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 for(r=0; r<nproc; r++) PE::Comm::instance().reduce(PE::plus(), &ival, 1, &iresult, r);
183 BOOST_CHECK_EQUAL( iresult, itest );
184 for(r=0; r<nproc; r++) PE::Comm::instance().reduce(PE::plus(), &dval, 1, &dresult, r);
185 BOOST_CHECK_EQUAL( dresult, dtest );
190 for(i=0; i<nproc; i++) { itest*=i+1; dtest*=(double)i+1.; }
193 for(r=0; r<nproc; r++) PE::Comm::instance().reduce(PE::multiplies(), &ival, 1, &iresult, r);
194 BOOST_CHECK_EQUAL( iresult, itest );
195 for(r=0; r<nproc; r++) PE::Comm::instance().reduce(PE::multiplies(), &dval, 1, &dresult, r);
196 BOOST_CHECK_EQUAL( dresult, dtest );
203 for(r=0; r<nproc; r++) PE::Comm::instance().reduce(
PE::max(), &ival, 1, &iresult, r);
204 BOOST_CHECK_EQUAL( iresult, itest );
205 for(r=0; r<nproc; r++) PE::Comm::instance().reduce(
PE::max(), &dval, 1, &dresult, r);
206 BOOST_CHECK_EQUAL( dresult, dtest );
213 for(r=0; r<nproc; r++) PE::Comm::instance().reduce(
PE::min(), &ival, 1, &iresult, r);
214 BOOST_CHECK_EQUAL( iresult, itest );
215 for(r=0; r<nproc; r++) PE::Comm::instance().reduce(
PE::min(), &dval, 1, &dresult, r);
216 BOOST_CHECK_EQUAL( dresult, dtest );
228 for(r=0; r<nproc; r++) PE::Comm::instance().reduce(PE::plus(), in, 3, out, r);
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();
244 for(r=0; r<nproc; r++) {
246 ptr_tmprcv=PE::Comm::instance().reduce(PE::plus(), ptr_snddat, sndcnt, (
double*)0, r);
248 double* dummy=PE::Comm::instance().reduce(PE::plus(), ptr_snddat, sndcnt, (
double*)0, r);
249 BOOST_CHECK_EQUAL( dummy , (
double*)0 );
252 for (i=0; i<2*nproc; i++) BOOST_CHECK_EQUAL( ptr_tmprcv[i] , ptr_rcvdat[i] );
254 for (i=0; i<2*nproc; i++) ptr_tmprcv[i]=0.;
255 for(r=0; r<nproc; r++) PE::Comm::instance().reduce(PE::plus(), ptr_snddat, sndcnt, ptr_tmprcv, r);
256 for (i=0; i<2*nproc; i++) BOOST_CHECK_EQUAL( ptr_tmprcv[i] , ptr_rcvdat[i] );
258 for(r=0; r<nproc; r++) {
259 for (i=0; i<2*nproc; i++) ptr_tmprcv[i]=ptr_snddat[i];
260 PE::Comm::instance().reduce(PE::plus(), ptr_tmprcv, sndcnt, ptr_tmprcv, r);
262 for (i=0; i<2*nproc; i++) BOOST_CHECK_EQUAL( ptr_tmprcv[i] , ptr_rcvdat[i] );
264 for (i=0; i<2*nproc; i++) BOOST_CHECK_EQUAL( ptr_tmprcv[i] , ptr_snddat[i] );
268 delete[] ptr_tmprcv2;
270 for(r=0; r<nproc; r++) {
272 ptr_tmprcv2=PE::Comm::instance().reduce(PE::plus(), ptr_snddat2, sndcnt, (
double*)0, r, 2);
274 double* dummy=PE::Comm::instance().reduce(PE::plus(), ptr_snddat2, sndcnt, (
double*)0, r, 2);
275 BOOST_CHECK_EQUAL( dummy , (
double*)0 );
278 for (i=0; i<4*nproc; i++) BOOST_CHECK_EQUAL( ptr_tmprcv2[i] , ptr_rcvdat2[i] );
280 for (i=0; i<4*nproc; i++) ptr_tmprcv2[i]=0.;
281 for(r=0; r<nproc; r++) PE::Comm::instance().reduce(PE::plus(), ptr_snddat2, sndcnt, ptr_tmprcv2, r, 2);
282 for (i=0; i<4*nproc; i++) BOOST_CHECK_EQUAL( ptr_tmprcv2[i] , ptr_rcvdat2[i] );
284 for(r=0; r<nproc; r++) {
285 for (i=0; i<4*nproc; i++) ptr_tmprcv2[i]=ptr_snddat2[i];
286 PE::Comm::instance().reduce(PE::plus(), ptr_tmprcv2, sndcnt, ptr_tmprcv2, r, 2);
288 for (i=0; i<4*nproc; i++) BOOST_CHECK_EQUAL( ptr_tmprcv2[i] , ptr_rcvdat2[i] );
290 for (i=0; i<4*nproc; i++) BOOST_CHECK_EQUAL( ptr_tmprcv2[i] , ptr_snddat2[i] );
301 setup_data_constant();
303 vec_tmprcv.resize(0);
304 vec_tmprcv.reserve(0);
305 for(r=0; r<nproc; r++) PE::Comm::instance().reduce(PE::plus(), vec_snddat, vec_tmprcv, r);
306 for (i=0; i<2*nproc; i++) BOOST_CHECK_EQUAL( vec_tmprcv[i] , vec_rcvdat[i] );
307 BOOST_CHECK_EQUAL( (
int)vec_tmprcv.size() , sndcnt );
309 vec_tmprcv.assign(2*nproc,0.);
310 for(r=0; r<nproc; r++) PE::Comm::instance().reduce(PE::plus(), vec_snddat, vec_tmprcv, r);
311 for (i=0; i<2*nproc; i++) BOOST_CHECK_EQUAL( vec_tmprcv[i] , vec_rcvdat[i] );
313 for(r=0; r<nproc; r++) {
314 vec_tmprcv=vec_snddat;
315 PE::Comm::instance().reduce(PE::plus(), vec_tmprcv, vec_tmprcv, r);
317 for (i=0; i<2*nproc; i++) BOOST_CHECK_EQUAL( vec_tmprcv[i] , vec_rcvdat[i] );
319 for (i=0; i<2*nproc; i++) BOOST_CHECK_EQUAL( vec_tmprcv[i] , vec_snddat[i] );
323 vec_tmprcv2.resize(0);
324 vec_tmprcv2.reserve(0);
325 for(r=0; r<nproc; r++) PE::Comm::instance().reduce(PE::plus(), vec_snddat2, vec_tmprcv2, r, 2);
326 for (i=0; i<4*nproc; i++) BOOST_CHECK_EQUAL( vec_tmprcv2[i] , vec_rcvdat2[i] );
327 BOOST_CHECK_EQUAL( (
int)vec_tmprcv2.size() , 2*sndcnt );
329 vec_tmprcv2.assign(4*nproc,0.);
330 for(r=0; r<nproc; r++) PE::Comm::instance().reduce(PE::plus(), vec_snddat2, vec_tmprcv2, r, 2);
331 for (i=0; i<4*nproc; i++) BOOST_CHECK_EQUAL( vec_tmprcv2[i] , vec_rcvdat2[i] );
333 for(r=0; r<nproc; r++) {
334 vec_tmprcv2=vec_snddat2;
335 PE::Comm::instance().reduce(PE::plus(), vec_tmprcv2, vec_tmprcv2, r, 2);
337 for (i=0; i<4*nproc; i++) BOOST_CHECK_EQUAL( vec_tmprcv2[i] , vec_rcvdat2[i] );
339 for (i=0; i<4*nproc; i++) BOOST_CHECK_EQUAL( vec_tmprcv2[i] , vec_snddat2[i] );
350 setup_data_variable();
354 for(r=0; r<nproc; r++) {
356 ptr_tmprcv=PE::Comm::instance().reduce(PE::plus(), ptr_snddat, sndcnt, ptr_sndmap, (
double*)0, ptr_rcvmap, r);
358 double* dummy=PE::Comm::instance().reduce(PE::plus(), ptr_snddat, sndcnt, ptr_sndmap, (
double*)0, ptr_rcvmap, r);
359 BOOST_CHECK_EQUAL( dummy , (
double*)0 );
362 for (i=0; i<nproc; i++) BOOST_CHECK_EQUAL( ptr_tmprcv[2*i] , ptr_rcvdat[2*i] );
365 ptr_tmprcv=
new double[2*nproc];
366 for (i=0; i<2*nproc; i++) ptr_tmprcv[i]=0.;
367 for(r=0; r<nproc; r++) PE::Comm::instance().reduce(PE::plus(), ptr_snddat, sndcnt, ptr_sndmap, ptr_tmprcv, ptr_rcvmap, r);
368 for (i=0; i<nproc; i++) BOOST_CHECK_EQUAL( ptr_tmprcv[2*i] , ptr_rcvdat[2*i] );
370 for(r=0; r<nproc; r++) {
371 for (i=0; i<2*nproc; i++) ptr_tmprcv[i]=ptr_snddat[i];
372 PE::Comm::instance().reduce(PE::plus(), ptr_tmprcv, sndcnt, ptr_sndmap, ptr_tmprcv, ptr_rcvmap, r);
374 for (i=0; i<nproc; i++) BOOST_CHECK_EQUAL( ptr_tmprcv[2*i] , ptr_rcvdat[2*i] );
376 for (i=0; i<nproc; i++) BOOST_CHECK_EQUAL( ptr_tmprcv[2*i] , ptr_snddat[2*i] );
380 delete[] ptr_tmprcv2;
382 for(r=0; r<nproc; r++) {
384 ptr_tmprcv2=PE::Comm::instance().reduce(PE::plus(), ptr_snddat2, sndcnt, ptr_sndmap, (
double*)0, ptr_rcvmap, r, 2);
386 double* dummy=PE::Comm::instance().reduce(PE::plus(), ptr_snddat2, sndcnt, ptr_sndmap, (
double*)0, ptr_rcvmap, r, 2);
387 BOOST_CHECK_EQUAL( dummy , (
double*)0 );
390 for (i=0; i<nproc; i++) BOOST_CHECK_EQUAL( ptr_tmprcv2[4*i+0] , ptr_rcvdat2[4*i+0] );
391 for (i=0; i<nproc; i++) BOOST_CHECK_EQUAL( ptr_tmprcv2[4*i+1] , ptr_rcvdat2[4*i+1] );
393 delete[] ptr_tmprcv2;
394 ptr_tmprcv2=
new double[4*nproc];
395 for (i=0; i<4*nproc; i++) ptr_tmprcv2[i]=0.;
396 for(r=0; r<nproc; r++) PE::Comm::instance().reduce(PE::plus(), ptr_snddat2, sndcnt, ptr_sndmap, ptr_tmprcv2, ptr_rcvmap, r, 2);
397 for (i=0; i<nproc; i++) BOOST_CHECK_EQUAL( ptr_tmprcv2[4*i+0] , ptr_rcvdat2[4*i+0] );
398 for (i=0; i<nproc; i++) BOOST_CHECK_EQUAL( ptr_tmprcv2[4*i+1] , ptr_rcvdat2[4*i+1] );
400 for(r=0; r<nproc; r++) {
401 for (i=0; i<4*nproc; i++) ptr_tmprcv2[i]=ptr_snddat2[i];
402 PE::Comm::instance().reduce(PE::plus(), ptr_tmprcv2, sndcnt, ptr_sndmap, ptr_tmprcv2, ptr_rcvmap, r, 2);
404 for (i=0; i<nproc; i++) BOOST_CHECK_EQUAL( ptr_tmprcv2[4*i+0] , ptr_rcvdat2[4*i+0] );
405 for (i=0; i<nproc; i++) BOOST_CHECK_EQUAL( ptr_tmprcv2[4*i+1] , ptr_rcvdat2[4*i+1] );
407 for (i=0; i<nproc; i++) BOOST_CHECK_EQUAL( ptr_tmprcv2[4*i+0] , ptr_snddat2[4*i+0] );
408 for (i=0; i<nproc; i++) BOOST_CHECK_EQUAL( ptr_tmprcv2[4*i+1] , ptr_snddat2[4*i+1] );
419 setup_data_variable();
421 vec_tmprcv.resize(0);
422 vec_tmprcv.reserve(0);
423 for(r=0; r<nproc; r++) PE::Comm::instance().reduce(PE::plus(), vec_snddat, vec_sndmap, vec_tmprcv, vec_rcvmap, r);
424 for (i=0; i<nproc; i++) BOOST_CHECK_EQUAL( vec_tmprcv[2*i] , vec_rcvdat[2*i] );
426 vec_tmprcv.resize(2*nproc);
427 vec_tmprcv.reserve(2*nproc);
428 for (i=0; i<2*nproc; i++) vec_tmprcv[i]=0.;
429 for(r=0; r<nproc; r++) PE::Comm::instance().reduce(PE::plus(), vec_snddat, vec_sndmap, vec_tmprcv, vec_rcvmap, r);
430 for (i=0; i<nproc; i++) BOOST_CHECK_EQUAL( vec_tmprcv[2*i] , vec_rcvdat[2*i] );
432 for(r=0; r<nproc; r++) {
433 vec_tmprcv=vec_snddat;
434 PE::Comm::instance().reduce(PE::plus(), vec_tmprcv, vec_sndmap, vec_tmprcv, vec_rcvmap, r);
436 for (i=0; i<nproc; i++) BOOST_CHECK_EQUAL( vec_tmprcv[2*i] , vec_rcvdat[2*i] );
438 for (i=0; i<nproc; i++) BOOST_CHECK_EQUAL( vec_tmprcv[2*i] , vec_snddat[2*i] );
442 vec_tmprcv2.resize(0);
443 vec_tmprcv2.reserve(0);
444 for(r=0; r<nproc; r++) PE::Comm::instance().reduce(PE::plus(), vec_snddat2, vec_sndmap, vec_tmprcv2, vec_rcvmap, r, 2);
445 for (i=0; i<nproc; i++) BOOST_CHECK_EQUAL( vec_tmprcv2[4*i+0] , vec_rcvdat2[4*i+0] );
446 for (i=0; i<nproc; i++) BOOST_CHECK_EQUAL( vec_tmprcv2[4*i+1] , vec_rcvdat2[4*i+1] );
448 vec_tmprcv2.resize(4*nproc);
449 vec_tmprcv2.reserve(4*nproc);
450 vec_tmprcv2.assign(4*nproc,0.);
451 for(r=0; r<nproc; r++) PE::Comm::instance().reduce(PE::plus(), vec_snddat2, vec_sndmap, vec_tmprcv2, vec_rcvmap, r, 2);
452 for (i=0; i<nproc; i++) BOOST_CHECK_EQUAL( vec_tmprcv2[4*i+0] , vec_rcvdat2[4*i+0] );
453 for (i=0; i<nproc; i++) BOOST_CHECK_EQUAL( vec_tmprcv2[4*i+1] , vec_rcvdat2[4*i+1] );
455 for(r=0; r<nproc; r++) {
456 vec_tmprcv2=vec_snddat2;
457 PE::Comm::instance().reduce(PE::plus(), vec_tmprcv2, vec_sndmap, vec_tmprcv2, vec_rcvmap, r, 2);
459 for (i=0; i<nproc; i++) BOOST_CHECK_EQUAL( vec_tmprcv2[4*i+0] , vec_rcvdat2[4*i+0] );
460 for (i=0; i<nproc; i++) BOOST_CHECK_EQUAL( vec_tmprcv2[4*i+1] , vec_rcvdat2[4*i+1] );
462 for (i=0; i<nproc; i++) BOOST_CHECK_EQUAL( vec_tmprcv2[4*i+0] , vec_snddat2[4*i+0] );
463 for (i=0; i<nproc; i++) BOOST_CHECK_EQUAL( vec_tmprcv2[4*i+1] , vec_snddat2[4*i+1] );
470 BOOST_AUTO_TEST_SUITE_END()
472 #define CFinfo
these are always defined
std::vector< double > vec_rcvdat2
std::vector< double > vec_snddat2
~PEReduceFixture()
common tear-down for each test case
std::vector< double > vec_rcvdat
int nproc
number of processes
Real max(const Real a, const Real b)
Maximum between two scalars.
optest operator+(const optest &b) const
operator +
void setup_data_constant()
helper function for constant size data - setting up input and verification data
T * reduce(const Communicator &comm, const Op &op, const T *in_values, const int in_n, T *out_values, const int root, const int stride=1)
Real min(const Real a, const Real b)
Minimum between two scalars.
void init()
giving values for i and d
int sndcnt
data for raw pointers
void setup_data_variable()
helper function for variable size data - setting up input and verification data
std::vector< int > vec_sndmap
std::vector< double > vec_tmprcv2
std::vector< int > vec_rcvmap
test class with operator + to test if operations and reduce can work with it
BOOST_AUTO_TEST_CASE(reduce)
std::vector< double > vec_snddat
data for std::vectors
bool test()
function to test result
std::vector< double > vec_tmprcv
PEReduceFixture()
common setup for each test case
#define PEProcessSortedExecute(irank, expression)