ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/OpenMD/trunk/src/parallel/Communicator.hpp
(Generate patch)

Comparing:
branches/development/src/parallel/Communicator.hpp (file contents), Revision 1551 by gezelter, Thu Apr 28 18:38:21 2011 UTC vs.
trunk/src/parallel/Communicator.hpp (file contents), Revision 1796 by gezelter, Mon Sep 10 18:38:44 2012 UTC

# Line 43 | Line 43
43   * [1]  Meineke, et al., J. Comp. Chem. 26, 252-271 (2005).            
44   * [2]  Fennell & Gezelter, J. Chem. Phys. 124, 234104 (2006).          
45   * [3]  Sun, Lin & Gezelter, J. Chem. Phys. 128, 24107 (2008).          
46 < * [4]  Vardeman & Gezelter, in progress (2009).                        
46 > * [4]  Kuang & Gezelter,  J. Chem. Phys. 133, 164101 (2010).
47 > * [5]  Vardeman, Stocker & Gezelter, J. Chem. Theory Comput. 7, 834 (2011).
48   */
49  
50   #ifndef PARALLEL_COMMUNICATOR_HPP
# Line 71 | Line 72 | namespace OpenMD{
72      static int Length() { return 1; };
73    };
74    
75 <  template<> inline MPI::Datatype MPITraits<int>::Type() { return MPI_INT; }
76 <  template<> inline MPI::Datatype MPITraits<RealType>::Type() { return MPI_REALTYPE; }
75 >  template<> inline MPI::Datatype MPITraits<int>::Type() { return MPI::INT; }
76 >  template<> inline MPI::Datatype MPITraits<RealType>::Type() { return MPI::REALTYPE; }
77  
78    template<class T, unsigned int Dim>
79    class MPITraits< Vector<T, Dim> > {
# Line 103 | Line 104 | namespace OpenMD{
104    };
105    
106    
107 <  template<communicatorType D, typename T>
107 >  template<communicatorType D>
108    class Communicator {
109    public:
110      
111 <    Communicator<D, T>(int nObjects) {
111 >    Communicator<D>() {
112        
113        int nProc = MPI::COMM_WORLD.Get_size();
114        int myRank = MPI::COMM_WORLD.Get_rank();
115 <
115 >      
116        int nColumnsMax = (int) sqrt(RealType(nProc));
117  
118        int nColumns;
# Line 119 | Line 120 | namespace OpenMD{
120          if (nProc % i == 0) nColumns = i;        
121        }
122          
122      int nRows = nProc / nColumns;
123        rowIndex_ = myRank / nColumns;      
124        columnIndex_ = myRank % nColumns;
125  
# Line 133 | Line 133 | namespace OpenMD{
133        case Global:
134          myComm = MPI::COMM_WORLD.Split(myRank, 0);
135        }
136        
137      int nCommProcs = myComm.Get_size();
136  
137 <      counts.reserve(nCommProcs);
138 <      displacements.reserve(nCommProcs);
137 >    }
138 >    
139 >    MPI::Intracomm getComm() { return myComm; }
140 >    
141 >  private:
142 >    int rowIndex_;
143 >    int columnIndex_;
144 >    MPI::Intracomm myComm;
145 >  };
146 >  
147  
148 +  template<typename T>
149 +  class Plan {
150 +  public:
151 +    
152 +    Plan<T>(MPI::Intracomm comm, int nObjects) {
153 +      myComm = comm;
154 +      int nCommProcs = myComm.Get_size();
155 +      
156 +      counts.resize(nCommProcs, 0);
157 +      displacements.resize(nCommProcs, 0);
158 +      
159        planSize_ = MPITraits<T>::Length() * nObjects;
160 <
160 >      
161        myComm.Allgather(&planSize_, 1, MPI::INT, &counts[0], 1, MPI::INT);
162 <
162 >      
163        displacements[0] = 0;
164        for (int i = 1; i < nCommProcs; i++) {
165          displacements[i] = displacements[i-1] + counts[i-1];
149        size_ += counts[i-1];
166        }
167  
168        size_ = 0;
# Line 158 | Line 174 | namespace OpenMD{
174      
175      void gather(vector<T>& v1, vector<T>& v2) {
176        
177 +      // an assert would be helpful here to make sure the vectors are the
178 +      // correct geometry
179 +      
180        myComm.Allgatherv(&v1[0],
181                          planSize_,
182                          MPITraits<T>::Type(),
# Line 165 | Line 184 | namespace OpenMD{
184                          &counts[0],
185                          &displacements[0],
186                          MPITraits<T>::Type());      
187 <    }
187 >    }      
188      
170    
171    
189      void scatter(vector<T>& v1, vector<T>& v2) {
190 <      
190 >      // an assert would be helpful here to make sure the vectors are the
191 >      // correct geometry
192 >            
193        myComm.Reduce_scatter(&v1[0], &v2[0], &counts[0],
194                              MPITraits<T>::Type(), MPI::SUM);
195      }
# Line 181 | Line 200 | namespace OpenMD{
200      
201    private:
202      int planSize_;     ///< how many are on local proc
184    int rowIndex_;
185    int columnIndex_;
203      int size_;
204      vector<int> counts;
205      vector<int> displacements;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines