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 R, unsigned int C> |
92 |
|
class MPITraits< RectMatrix<T, R, C> > { |
93 |
|
public: |
94 |
< |
static MPI::Datatype Type() { return MPITraits<T>::Type(); } |
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 |
|
|
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 |
> |
// myComm = MPI::COMM_WORLD.Split(rowIndex_, 0); |
133 |
|
break; |
134 |
|
case Column: |
135 |
< |
myComm = MPI::COMM_WORLD.Split(columnIndex_, 0); |
135 |
> |
MPI_Comm_split(MPI_COMM_WORLD, columnIndex_, 0, &myComm); |
136 |
> |
//myComm = MPI::COMM_WORLD.Split(columnIndex_, 0); |
137 |
|
break; |
138 |
|
case Global: |
139 |
< |
myComm = MPI::COMM_WORLD.Split(myRank, 0); |
139 |
> |
MPI_Comm_split(MPI_COMM_WORLD, myRank, 0, &myComm); |
140 |
> |
//myComm = MPI::COMM_WORLD.Split(myRank, 0); |
141 |
|
} |
142 |
|
|
143 |
|
} |
144 |
|
|
145 |
< |
MPI::Intracomm getComm() { return myComm; } |
145 |
> |
MPI_Comm getComm() { return myComm; } |
146 |
|
|
147 |
|
private: |
148 |
|
int rowIndex_; |
149 |
|
int columnIndex_; |
150 |
< |
MPI::Intracomm myComm; |
150 |
> |
MPI_Comm myComm; |
151 |
|
}; |
152 |
|
|
153 |
|
|
155 |
|
class Plan { |
156 |
|
public: |
157 |
|
|
158 |
< |
Plan<T>(MPI::Intracomm comm, int nObjects) : myComm(comm) { |
159 |
< |
int nCommProcs = myComm.Get_size(); |
158 |
> |
Plan<T>(MPI_Comm comm, int nObjects) : myComm(comm) { |
159 |
> |
|
160 |
> |
int nCommProcs; |
161 |
> |
MPI_Comm_size( myComm, &nCommProcs ); |
162 |
> |
|
163 |
> |
//int nCommProcs = myComm.Get_size(); |
164 |
|
|
165 |
|
counts.resize(nCommProcs, 0); |
166 |
|
displacements.resize(nCommProcs, 0); |
167 |
|
|
168 |
|
planSize_ = MPITraits<T>::Length() * nObjects; |
169 |
|
|
170 |
< |
myComm.Allgather(&planSize_, 1, MPI::INT, &counts[0], 1, MPI::INT); |
170 |
> |
MPI_Allgather(&planSize_, 1, MPI_INT, &counts[0], 1, MPI_INT, myComm); |
171 |
> |
//myComm.Allgather(&planSize_, 1, MPI_INT, &counts[0], 1, MPI_INT); |
172 |
|
|
173 |
|
displacements[0] = 0; |
174 |
|
for (int i = 1; i < nCommProcs; i++) { |
187 |
|
// an assert would be helpful here to make sure the vectors are the |
188 |
|
// correct geometry |
189 |
|
|
190 |
< |
myComm.Allgatherv(&v1[0], |
191 |
< |
planSize_, |
192 |
< |
MPITraits<T>::Type(), |
193 |
< |
&v2[0], |
194 |
< |
&counts[0], |
195 |
< |
&displacements[0], |
196 |
< |
MPITraits<T>::Type()); |
190 |
> |
MPI_Allgatherv(&v1[0], |
191 |
> |
planSize_, |
192 |
> |
MPITraits<T>::Type(), |
193 |
> |
&v2[0], |
194 |
> |
&counts[0], |
195 |
> |
&displacements[0], |
196 |
> |
MPITraits<T>::Type(), |
197 |
> |
myComm); |
198 |
> |
// myComm.Allgatherv(&v1[0], |
199 |
> |
// planSize_, |
200 |
> |
// MPITraits<T>::Type(), |
201 |
> |
// &v2[0], |
202 |
> |
// &counts[0], |
203 |
> |
// &displacements[0], |
204 |
> |
// MPITraits<T>::Type()); |
205 |
|
} |
206 |
|
|
207 |
|
void scatter(vector<T>& v1, vector<T>& v2) { |
208 |
|
// an assert would be helpful here to make sure the vectors are the |
209 |
|
// correct geometry |
210 |
|
|
211 |
< |
myComm.Reduce_scatter(&v1[0], &v2[0], &counts[0], |
212 |
< |
MPITraits<T>::Type(), MPI::SUM); |
211 |
> |
MPI_Reduce_scatter(&v1[0], &v2[0], &counts[0], |
212 |
> |
MPITraits<T>::Type(), MPI_SUM, myComm); |
213 |
> |
|
214 |
> |
// myComm.Reduce_scatter(&v1[0], &v2[0], &counts[0], |
215 |
> |
// MPITraits<T>::Type(), MPI::SUM); |
216 |
|
} |
217 |
|
|
218 |
|
int getSize() { |
224 |
|
int size_; |
225 |
|
vector<int> counts; |
226 |
|
vector<int> displacements; |
227 |
< |
MPI::Intracomm myComm; |
227 |
> |
MPI_Comm myComm; |
228 |
|
}; |
229 |
|
|
230 |
|
#endif |