18 nproc=PE::Comm::instance().size();
19 irank=PE::Comm::instance().rank();
86 for (i=0; i<2*
nproc; i++)
88 ptr_snddat[i]=(irank+1)*10000+(i+1);
90 for (k=0; k<
nproc; k++) ptr_rcvdat[i]+=(k+1)*10000+(i+1);
92 for (i=0; i<2*
nproc; i++) { ptr_snddat2[2*i+0]=ptr_snddat[i]; ptr_snddat2[2*i+1]=ptr_snddat[i]+1; }
93 for (i=0; i<2*
nproc; i++) { ptr_rcvdat2[2*i+0]=ptr_rcvdat[i]; ptr_rcvdat2[2*i+1]=ptr_rcvdat[i]+
nproc; }
95 vec_snddat.assign(ptr_snddat,ptr_snddat+2*nproc);
96 vec_rcvdat.assign(ptr_rcvdat,ptr_rcvdat+2*nproc);
97 vec_snddat2.assign(ptr_snddat2,ptr_snddat2+4*nproc);
98 vec_rcvdat2.assign(ptr_rcvdat2,ptr_rcvdat2+4*nproc);
105 for (i=0; i<2*
nproc; i++) {
109 for (i=0; i<
nproc; i++)
111 ptr_snddat[2*i]=(irank+1)*10000+(i+1);
113 ptr_rcvmap[i]=2*(nproc-1-i);
114 for (k=0; k<
nproc; k++) ptr_rcvdat[2*(nproc-1-i)]+=(k+1)*10000+(i+1);
116 for (i=0; i<2*
nproc; i++) { ptr_snddat2[2*i+0]=ptr_snddat[i]; ptr_snddat2[2*i+1]=ptr_snddat[i]+1; }
117 for (i=0; i<2*
nproc; i++) { ptr_rcvdat2[2*i+0]=ptr_rcvdat[i]; ptr_rcvdat2[2*i+1]=ptr_rcvdat[i]+(double)nproc; }
119 vec_snddat.assign(ptr_snddat,ptr_snddat+2*nproc);
120 vec_rcvdat.assign(ptr_rcvdat,ptr_rcvdat+2*nproc);
121 vec_sndmap.assign(ptr_sndmap,ptr_sndmap+nproc);
122 vec_rcvmap.assign(ptr_rcvmap,ptr_rcvmap+nproc);
123 vec_snddat2.assign(ptr_snddat2,ptr_snddat2+4*nproc);
124 vec_rcvdat2.assign(ptr_rcvdat2,ptr_rcvdat2+4*nproc);
135 ival=PE::Comm::instance().rank()+1;
136 dval=(double)PE::Comm::instance().rank()+10.;
144 int nproc=PE::Comm::instance().size();
146 for(i=0; i<
nproc; i++) itest+=i+1;
148 for(i=0; i<
nproc; i++) dtest+=(
double)i+10.;
149 return ((ival==itest)&&(dval==dtest));
171 int ival,itest,iresult;
172 double dval,dtest,dresult;
174 dval=(double)irank+1.;
179 for(i=0; i<nproc; i++) { itest+=i+1; dtest+=(double)i+1.; }
182 PE::Comm::instance().all_reduce(PE::plus(), &ival, 1, &iresult);
183 BOOST_CHECK_EQUAL( iresult, itest );
184 PE::Comm::instance().all_reduce(PE::plus(), &dval, 1, &dresult);
185 BOOST_CHECK_EQUAL( dresult, dtest );
190 for(i=0; i<nproc; i++) { itest*=i+1; dtest*=(double)i+1.; }
193 PE::Comm::instance().all_reduce(PE::multiplies(), &ival, 1, &iresult);
194 BOOST_CHECK_EQUAL( iresult, itest );
195 PE::Comm::instance().all_reduce(PE::multiplies(), &dval, 1, &dresult);
196 BOOST_CHECK_EQUAL( dresult, dtest );
203 PE::Comm::instance().all_reduce(
PE::max(), &ival, 1, &iresult);
204 BOOST_CHECK_EQUAL( iresult, itest );
205 PE::Comm::instance().all_reduce(
PE::max(), &dval, 1, &dresult);
206 BOOST_CHECK_EQUAL( dresult, dtest );
213 PE::Comm::instance().all_reduce(
PE::min(), &ival, 1, &iresult);
214 BOOST_CHECK_EQUAL( iresult, itest );
215 PE::Comm::instance().all_reduce(
PE::min(), &dval, 1, &dresult);
216 BOOST_CHECK_EQUAL( dresult, dtest );
228 PE::Comm::instance().all_reduce(PE::plus(), in, 3, out);
229 BOOST_CHECK_EQUAL( out[0].
test() ,
true );
230 BOOST_CHECK_EQUAL( out[1].
test() ,
true );
231 BOOST_CHECK_EQUAL( out[2].
test() ,
true );
240 setup_data_constant();
245 ptr_tmprcv=PE::Comm::instance().all_reduce(PE::plus(), ptr_snddat, sndcnt, (
double*)0);
246 for (i=0; i<2*nproc; i++) BOOST_CHECK_EQUAL( ptr_tmprcv[i] , ptr_rcvdat[i] );
248 for (i=0; i<2*nproc; i++) ptr_tmprcv[i]=0.;
249 PE::Comm::instance().all_reduce(PE::plus(), ptr_snddat, sndcnt, ptr_tmprcv);
250 for (i=0; i<2*nproc; i++) BOOST_CHECK_EQUAL( ptr_tmprcv[i] , ptr_rcvdat[i] );
252 for (i=0; i<2*nproc; i++) ptr_tmprcv[i]=ptr_snddat[i];
253 PE::Comm::instance().all_reduce(PE::plus(), ptr_tmprcv, sndcnt, ptr_tmprcv);
254 for (i=0; i<2*nproc; i++) BOOST_CHECK_EQUAL( ptr_tmprcv[i] , ptr_rcvdat[i] );
256 delete[] ptr_tmprcv2;
259 ptr_tmprcv2=PE::Comm::instance().all_reduce(PE::plus(), ptr_snddat2, sndcnt, (
double*)0, 2);
260 for (i=0; i<4*nproc; i++) BOOST_CHECK_EQUAL( ptr_tmprcv2[i] , ptr_rcvdat2[i] );
262 for (i=0; i<4*nproc; i++) ptr_tmprcv2[i]=0.;
263 PE::Comm::instance().all_reduce(PE::plus(), ptr_snddat2, sndcnt, ptr_tmprcv2, 2);
264 for (i=0; i<4*nproc; i++) BOOST_CHECK_EQUAL( ptr_tmprcv2[i] , ptr_rcvdat2[i] );
266 for (i=0; i<4*nproc; i++) ptr_tmprcv2[i]=ptr_snddat2[i];
267 PE::Comm::instance().all_reduce(PE::plus(), ptr_tmprcv2, sndcnt, ptr_tmprcv2, 2);
268 for (i=0; i<4*nproc; i++) BOOST_CHECK_EQUAL( ptr_tmprcv2[i] , ptr_rcvdat2[i] );
278 setup_data_constant();
280 vec_tmprcv.resize(0);
281 vec_tmprcv.reserve(0);
282 PE::Comm::instance().all_reduce(PE::plus(), vec_snddat, vec_tmprcv);
283 for (i=0; i<2*nproc; i++) BOOST_CHECK_EQUAL( vec_tmprcv[i] , vec_rcvdat[i] );
284 BOOST_CHECK_EQUAL( (
int)vec_tmprcv.size() , sndcnt );
286 vec_tmprcv.assign(2*nproc,0.);
287 PE::Comm::instance().all_reduce(PE::plus(), vec_snddat, vec_tmprcv);
288 for (i=0; i<2*nproc; i++) BOOST_CHECK_EQUAL( vec_tmprcv[i] , vec_rcvdat[i] );
290 vec_tmprcv=vec_snddat;
291 PE::Comm::instance().all_reduce(PE::plus(), vec_tmprcv, vec_tmprcv);
292 for (i=0; i<2*nproc; i++) BOOST_CHECK_EQUAL( vec_tmprcv[i] , vec_rcvdat[i] );
294 vec_tmprcv2.resize(0);
295 vec_tmprcv2.reserve(0);
296 PE::Comm::instance().all_reduce(PE::plus(), vec_snddat2, vec_tmprcv2, 2);
297 for (i=0; i<4*nproc; i++) BOOST_CHECK_EQUAL( vec_tmprcv2[i] , vec_rcvdat2[i] );
298 BOOST_CHECK_EQUAL( (
int)vec_tmprcv2.size() , 2*sndcnt );
300 vec_tmprcv2.assign(4*nproc,0.);
301 PE::Comm::instance().all_reduce(PE::plus(), vec_snddat2, vec_tmprcv2, 2);
302 for (i=0; i<4*nproc; i++) BOOST_CHECK_EQUAL( vec_tmprcv2[i] , vec_rcvdat2[i] );
304 vec_tmprcv2=vec_snddat2;
305 PE::Comm::instance().all_reduce(PE::plus(), vec_tmprcv2, vec_tmprcv2, 2);
306 for (i=0; i<4*nproc; i++) BOOST_CHECK_EQUAL( vec_tmprcv2[i] , vec_rcvdat2[i] );
315 setup_data_variable();
319 ptr_tmprcv=PE::Comm::instance().all_reduce(PE::plus(), ptr_snddat, sndcnt, ptr_sndmap, (
double*)0, ptr_rcvmap);
320 for (i=0; i<nproc; i++) BOOST_CHECK_EQUAL( ptr_tmprcv[2*i] , ptr_rcvdat[2*i] );
323 ptr_tmprcv=
new double[2*nproc];
324 for (i=0; i<2*nproc; i++) ptr_tmprcv[i]=0.;
325 PE::Comm::instance().all_reduce(PE::plus(), ptr_snddat, sndcnt, ptr_sndmap, ptr_tmprcv, ptr_rcvmap);
326 for (i=0; i<nproc; i++) BOOST_CHECK_EQUAL( ptr_tmprcv[2*i] , ptr_rcvdat[2*i] );
328 for (i=0; i<2*nproc; i++) ptr_tmprcv[i]=ptr_snddat[i];
329 PE::Comm::instance().all_reduce(PE::plus(), ptr_tmprcv, sndcnt, ptr_sndmap, ptr_tmprcv, ptr_rcvmap);
330 for (i=0; i<nproc; i++) BOOST_CHECK_EQUAL( ptr_tmprcv[2*i] , ptr_rcvdat[2*i] );
332 delete[] ptr_tmprcv2;
334 ptr_tmprcv2=PE::Comm::instance().all_reduce(PE::plus(), ptr_snddat2, sndcnt, ptr_sndmap, (
double*)0, ptr_rcvmap, 2);
335 for (i=0; i<nproc; i++) BOOST_CHECK_EQUAL( ptr_tmprcv2[4*i+0] , ptr_rcvdat2[4*i+0] );
336 for (i=0; i<nproc; i++) BOOST_CHECK_EQUAL( ptr_tmprcv2[4*i+1] , ptr_rcvdat2[4*i+1] );
338 delete[] ptr_tmprcv2;
339 ptr_tmprcv2=
new double[4*nproc];
340 for (i=0; i<4*nproc; i++) ptr_tmprcv2[i]=0.;
341 PE::Comm::instance().all_reduce(PE::plus(), ptr_snddat2, sndcnt, ptr_sndmap, ptr_tmprcv2, ptr_rcvmap, 2);
342 for (i=0; i<nproc; i++) BOOST_CHECK_EQUAL( ptr_tmprcv2[4*i+0] , ptr_rcvdat2[4*i+0] );
343 for (i=0; i<nproc; i++) BOOST_CHECK_EQUAL( ptr_tmprcv2[4*i+1] , ptr_rcvdat2[4*i+1] );
345 for (i=0; i<4*nproc; i++) ptr_tmprcv2[i]=ptr_snddat2[i];
346 PE::Comm::instance().all_reduce(PE::plus(), ptr_tmprcv2, sndcnt, ptr_sndmap, ptr_tmprcv2, ptr_rcvmap, 2);
347 for (i=0; i<nproc; i++) BOOST_CHECK_EQUAL( ptr_tmprcv2[4*i+0] , ptr_rcvdat2[4*i+0] );
348 for (i=0; i<nproc; i++) BOOST_CHECK_EQUAL( ptr_tmprcv2[4*i+1] , ptr_rcvdat2[4*i+1] );
357 setup_data_variable();
359 vec_tmprcv.resize(0);
360 vec_tmprcv.reserve(0);
361 PE::Comm::instance().all_reduce(PE::plus(), vec_snddat, vec_sndmap, vec_tmprcv, vec_rcvmap);
362 for (i=0; i<nproc; i++) BOOST_CHECK_EQUAL( vec_tmprcv[2*i] , vec_rcvdat[2*i] );
364 vec_tmprcv.resize(2*nproc);
365 vec_tmprcv.reserve(2*nproc);
366 for (i=0; i<2*nproc; i++) vec_tmprcv[i]=0.;
367 PE::Comm::instance().all_reduce(PE::plus(), vec_snddat, vec_sndmap, vec_tmprcv, vec_rcvmap);
368 for (i=0; i<nproc; i++) BOOST_CHECK_EQUAL( vec_tmprcv[2*i] , vec_rcvdat[2*i] );
370 vec_tmprcv=vec_snddat;
371 PE::Comm::instance().all_reduce(PE::plus(), vec_tmprcv, vec_sndmap, vec_tmprcv, vec_rcvmap);
372 for (i=0; i<nproc; i++) BOOST_CHECK_EQUAL( vec_tmprcv[2*i] , vec_rcvdat[2*i] );
374 vec_tmprcv2.resize(0);
375 vec_tmprcv2.reserve(0);
376 PE::Comm::instance().all_reduce(PE::plus(), vec_snddat2, vec_sndmap, vec_tmprcv2, vec_rcvmap, 2);
377 for (i=0; i<nproc; i++) BOOST_CHECK_EQUAL( vec_tmprcv2[4*i+0] , vec_rcvdat2[4*i+0] );
378 for (i=0; i<nproc; i++) BOOST_CHECK_EQUAL( vec_tmprcv2[4*i+1] , vec_rcvdat2[4*i+1] );
380 vec_tmprcv2.resize(4*nproc);
381 vec_tmprcv2.reserve(4*nproc);
382 vec_tmprcv2.assign(4*nproc,0.);
383 PE::Comm::instance().all_reduce(PE::plus(), vec_snddat2, vec_sndmap, vec_tmprcv2, vec_rcvmap, 2);
384 for (i=0; i<nproc; i++) BOOST_CHECK_EQUAL( vec_tmprcv2[4*i+0] , vec_rcvdat2[4*i+0] );
385 for (i=0; i<nproc; i++) BOOST_CHECK_EQUAL( vec_tmprcv2[4*i+1] , vec_rcvdat2[4*i+1] );
387 vec_tmprcv2=vec_snddat2;
388 PE::Comm::instance().all_reduce(PE::plus(), vec_tmprcv2, vec_sndmap, vec_tmprcv2, vec_rcvmap, 2);
389 for (i=0; i<nproc; i++) BOOST_CHECK_EQUAL( vec_tmprcv2[4*i+0] , vec_rcvdat2[4*i+0] );
390 for (i=0; i<nproc; i++) BOOST_CHECK_EQUAL( vec_tmprcv2[4*i+1] , vec_rcvdat2[4*i+1] );
395 BOOST_AUTO_TEST_SUITE_END()
397 #define CFinfo
these are always defined
void setup_data_constant()
helper function for constant size data - setting up input and verification data
~PEAllReduceFixture()
common tear-down for each test case
Real max(const Real a, const Real b)
Maximum between two scalars.
void setup_data_variable()
helper function for variable size data - setting up input and verification data
std::vector< double > vec_snddat
data for std::vectors
std::vector< int > vec_rcvmap
int sndcnt
data for raw pointers
Real min(const Real a, const Real b)
Minimum between two scalars.
std::vector< double > vec_tmprcv2
std::vector< double > vec_rcvdat2
std::vector< int > vec_sndmap
std::vector< double > vec_snddat2
PEAllReduceFixture()
common setup for each test case
std::vector< double > vec_tmprcv
T * all_reduce(const Communicator &comm, const Op &op, const T *in_values, const int in_n, T *out_values, const int stride=1)
test class with operator + to test if operations and all_reduce can work with it
bool test()
function to test result
optest operator+(const optest &b) const
operator +
BOOST_AUTO_TEST_CASE(all_reduce)
int nproc
number of processes
std::vector< double > vec_rcvdat
#define PEProcessSortedExecute(irank, expression)
void init()
giving values for i and d