103 |
|
}; |
104 |
|
|
105 |
|
|
106 |
< |
template<communicatorType D, typename T> |
106 |
> |
template<communicatorType D> |
107 |
|
class Communicator { |
108 |
|
public: |
109 |
|
|
110 |
< |
Communicator<D, T>(int nObjects) { |
110 |
> |
Communicator<D>() { |
111 |
|
|
112 |
|
int nProc = MPI::COMM_WORLD.Get_size(); |
113 |
|
int myRank = MPI::COMM_WORLD.Get_rank(); |
114 |
< |
|
114 |
> |
|
115 |
|
int nColumnsMax = (int) sqrt(RealType(nProc)); |
116 |
|
|
117 |
|
int nColumns; |
133 |
|
case Global: |
134 |
|
myComm = MPI::COMM_WORLD.Split(myRank, 0); |
135 |
|
} |
136 |
– |
|
137 |
– |
int nCommProcs = myComm.Get_size(); |
136 |
|
|
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 |
< |
|
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]; |
173 |
|
|
174 |
|
|
175 |
|
void gather(vector<T>& v1, vector<T>& v2) { |
176 |
< |
|
176 |
> |
|
177 |
|
// an assert would be helpful here to make sure the vectors are the |
178 |
|
// correct geometry |
179 |
|
|
184 |
|
&counts[0], |
185 |
|
&displacements[0], |
186 |
|
MPITraits<T>::Type()); |
187 |
< |
} |
187 |
> |
} |
188 |
|
|
172 |
– |
|
173 |
– |
|
189 |
|
void scatter(vector<T>& v1, vector<T>& v2) { |
190 |
|
// an assert would be helpful here to make sure the vectors are the |
191 |
|
// correct geometry |
192 |
< |
|
192 |
> |
|
193 |
|
myComm.Reduce_scatter(&v1[0], &v2[0], &counts[0], |
194 |
|
MPITraits<T>::Type(), MPI::SUM); |
195 |
|
} |
200 |
|
|
201 |
|
private: |
202 |
|
int planSize_; ///< how many are on local proc |
188 |
– |
int rowIndex_; |
189 |
– |
int columnIndex_; |
203 |
|
int size_; |
204 |
|
vector<int> counts; |
205 |
|
vector<int> displacements; |