2 |
|
* @file Communicator.hpp |
3 |
|
* @author Charles Vardeman <cvardema.at.nd.edu> |
4 |
|
* @date 08/18/2010 |
5 |
– |
* @time 11:56am |
5 |
|
* @version 1.0 |
6 |
|
* |
7 |
|
* @section LICENSE |
41 |
|
* |
42 |
|
* [1] Meineke, et al., J. Comp. Chem. 26, 252-271 (2005). |
43 |
|
* [2] Fennell & Gezelter, J. Chem. Phys. 124, 234104 (2006). |
44 |
< |
* [3] Sun, Lin & Gezelter, J. Chem. Phys. 128, 24107 (2008). |
44 |
> |
* [3] Sun, Lin & Gezelter, J. Chem. Phys. 128, 234107 (2008). |
45 |
|
* [4] Kuang & Gezelter, J. Chem. Phys. 133, 164101 (2010). |
46 |
|
* [5] Vardeman, Stocker & Gezelter, J. Chem. Theory Comput. 7, 834 (2011). |
47 |
|
*/ |
67 |
|
template<class T> |
68 |
|
class MPITraits { |
69 |
|
public: |
70 |
< |
static MPI::Datatype Type(); |
70 |
> |
static MPI_Datatype Type(); |
71 |
|
static int Length() { return 1; }; |
72 |
|
}; |
73 |
|
|
74 |
< |
template<> inline MPI::Datatype MPITraits<int>::Type() { return MPI::INT; } |
75 |
< |
template<> inline MPI::Datatype MPITraits<RealType>::Type() { return MPI::REALTYPE; } |
74 |
> |
template<> inline MPI_Datatype MPITraits<int>::Type() { return MPI_INT; } |
75 |
> |
template<> inline MPI_Datatype MPITraits<RealType>::Type() { return MPI_REALTYPE; } |
76 |
|
|
77 |
|
template<class T, unsigned int Dim> |
78 |
|
class MPITraits< Vector<T, Dim> > { |
79 |
|
public: |
80 |
< |
static MPI::Datatype Type() { return MPITraits<T>::Type(); } |
80 |
> |
static MPI_Datatype Type() { return MPITraits<T>::Type(); } |
81 |
|
static int Length() {return Dim;} |
82 |
|
}; |
83 |
|
|
84 |
|
template<class T> |
85 |
|
class MPITraits< Vector3<T> > { |
86 |
|
public: |
87 |
< |
static MPI::Datatype Type() { return MPITraits<T>::Type(); } |
87 |
> |
static MPI_Datatype Type() { return MPITraits<T>::Type(); } |
88 |
|
static int Length() {return 3;} |
89 |
|
}; |
90 |
|
|
91 |
< |
template<class T, unsigned int Row, unsigned int Col> |
92 |
< |
class MPITraits< RectMatrix<T, Row, Col> > { |
91 |
> |
template<class T, unsigned int R, unsigned int C> |
92 |
> |
class MPITraits< RectMatrix<T, R, C> > { |
93 |
|
public: |
94 |
< |
static MPI::Datatype Type() { return MPITraits<T>::Type(); } |
95 |
< |
static int Length() {return Row * Col;} |
94 |
> |
static MPI_Datatype Type() { return MPITraits<T>::Type(); } |
95 |
> |
static int Length() {return R * C;} |
96 |
|
}; |
97 |
|
|
98 |
|
template<class T> |
99 |
|
class MPITraits< SquareMatrix3<T> > { |
100 |
|
public: |
101 |
< |
static MPI::Datatype Type() { return MPITraits<T>::Type(); } |
101 |
> |
static MPI_Datatype Type() { return MPITraits<T>::Type(); } |
102 |
|
static int Length() {return 9;} |
103 |
|
}; |
104 |
|
|
109 |
|
|
110 |
|
Communicator<D>() { |
111 |
|
|
112 |
< |
int nProc = MPI::COMM_WORLD.Get_size(); |
113 |
< |
int myRank = MPI::COMM_WORLD.Get_rank(); |
112 |
> |
int nProc; |
113 |
> |
int myRank; |
114 |
> |
|
115 |
> |
MPI_Comm_size( MPI_COMM_WORLD, &nProc); |
116 |
> |
MPI_Comm_rank( MPI_COMM_WORLD, &myRank); |
117 |
|
|
118 |
|
int nColumnsMax = (int) sqrt(RealType(nProc)); |
119 |
|
|
122 |
|
if (nProc % i == 0) nColumns = i; |
123 |
|
} |
124 |
|
|
125 |
+ |
// int nRows = nProc / nColumns; |
126 |
|
rowIndex_ = myRank / nColumns; |
127 |
|
columnIndex_ = myRank % nColumns; |
128 |
|
|
129 |
|
switch(D) { |
130 |
|
case Row : |
131 |
< |
myComm = MPI::COMM_WORLD.Split(rowIndex_, 0); |
131 |
> |
MPI_Comm_split(MPI_COMM_WORLD, rowIndex_, 0, &myComm); |
132 |
|
break; |
133 |
|
case Column: |
134 |
< |
myComm = MPI::COMM_WORLD.Split(columnIndex_, 0); |
134 |
> |
MPI_Comm_split(MPI_COMM_WORLD, columnIndex_, 0, &myComm); |
135 |
|
break; |
136 |
|
case Global: |
137 |
< |
myComm = MPI::COMM_WORLD.Split(myRank, 0); |
137 |
> |
MPI_Comm_split(MPI_COMM_WORLD, myRank, 0, &myComm); |
138 |
|
} |
139 |
|
|
140 |
|
} |
141 |
|
|
142 |
< |
MPI::Intracomm getComm() { return myComm; } |
142 |
> |
MPI_Comm getComm() { return myComm; } |
143 |
|
|
144 |
|
private: |
145 |
|
int rowIndex_; |
146 |
|
int columnIndex_; |
147 |
< |
MPI::Intracomm myComm; |
147 |
> |
MPI_Comm myComm; |
148 |
|
}; |
149 |
|
|
150 |
|
|
152 |
|
class Plan { |
153 |
|
public: |
154 |
|
|
155 |
< |
Plan<T>(MPI::Intracomm comm, int nObjects) { |
156 |
< |
myComm = comm; |
157 |
< |
int nCommProcs = myComm.Get_size(); |
155 |
> |
Plan<T>(MPI_Comm comm, int nObjects) : myComm(comm) { |
156 |
> |
|
157 |
> |
int nCommProcs; |
158 |
> |
MPI_Comm_size( myComm, &nCommProcs ); |
159 |
|
|
160 |
|
counts.resize(nCommProcs, 0); |
161 |
|
displacements.resize(nCommProcs, 0); |
162 |
|
|
163 |
|
planSize_ = MPITraits<T>::Length() * nObjects; |
164 |
|
|
165 |
< |
myComm.Allgather(&planSize_, 1, MPI::INT, &counts[0], 1, MPI::INT); |
165 |
> |
MPI_Allgather(&planSize_, 1, MPI_INT, &counts[0], 1, MPI_INT, myComm); |
166 |
|
|
167 |
|
displacements[0] = 0; |
168 |
|
for (int i = 1; i < nCommProcs; i++) { |
181 |
|
// an assert would be helpful here to make sure the vectors are the |
182 |
|
// correct geometry |
183 |
|
|
184 |
< |
myComm.Allgatherv(&v1[0], |
185 |
< |
planSize_, |
186 |
< |
MPITraits<T>::Type(), |
187 |
< |
&v2[0], |
188 |
< |
&counts[0], |
189 |
< |
&displacements[0], |
190 |
< |
MPITraits<T>::Type()); |
184 |
> |
MPI_Allgatherv(&v1[0], |
185 |
> |
planSize_, |
186 |
> |
MPITraits<T>::Type(), |
187 |
> |
&v2[0], |
188 |
> |
&counts[0], |
189 |
> |
&displacements[0], |
190 |
> |
MPITraits<T>::Type(), |
191 |
> |
myComm); |
192 |
|
} |
193 |
|
|
194 |
|
void scatter(vector<T>& v1, vector<T>& v2) { |
195 |
|
// an assert would be helpful here to make sure the vectors are the |
196 |
|
// correct geometry |
197 |
|
|
198 |
< |
myComm.Reduce_scatter(&v1[0], &v2[0], &counts[0], |
199 |
< |
MPITraits<T>::Type(), MPI::SUM); |
198 |
> |
MPI_Reduce_scatter(&v1[0], &v2[0], &counts[0], |
199 |
> |
MPITraits<T>::Type(), MPI_SUM, myComm); |
200 |
|
} |
201 |
|
|
202 |
|
int getSize() { |
208 |
|
int size_; |
209 |
|
vector<int> counts; |
210 |
|
vector<int> displacements; |
211 |
< |
MPI::Intracomm myComm; |
211 |
> |
MPI_Comm myComm; |
212 |
|
}; |
213 |
|
|
214 |
|
#endif |