COOLFluiD  Release kernel
COOLFluiD is a Collaborative Simulation Environment (CSE) focused on complex MultiPhysics simulations.
utest-parallel-collective-scatter.hpp
Go to the documentation of this file.
1 // Copyright (C) 2010-2013 von Karman Institute for Fluid Dynamics, Belgium
2 //
3 // This software is distributed under the terms of the
4 // GNU Lesser General Public License version 3 (LGPLv3).
5 // See doc/lgpl.txt and doc/gpl.txt for the license text.
6 
7 // this file is en-block included into utest-parallel-collective.cpp
8 // do not include anything here, rather in utest-parallel-collective.cpp
9 
11 
13 {
16  {
17  int i;
18 
19  // rank and proc
20  nproc=PE::Comm::instance().size();
21  irank=PE::Comm::instance().rank();
22 
23  // ptr helpers
24  sndcnt=0;
25  rcvcnt=0;
26  ptr_sndcnt=new int[nproc];
27  ptr_rcvcnt=new int[nproc];
28  ptr_snddat=new double[nproc*nproc];
29  ptr_rcvdat=new double[nproc*nproc];
30  ptr_sndmap=new int[nproc*nproc];
31  ptr_rcvmap=new int*[nproc];
32  for (i=0; i<nproc; i++) ptr_rcvmap[i]=new int[nproc];
33  ptr_tmprcv=new double[nproc*nproc];
34  ptr_tmpcnt=new int[nproc];
35 
36  // std::Vector helpers
37  vec_sndcnt.resize(nproc);
38  vec_rcvcnt.resize(nproc);
39  vec_snddat.resize(nproc*nproc);
40  vec_rcvdat.resize(nproc*nproc);
41  vec_sndmap.resize(nproc*nproc);
42  vec_rcvmap.resize(nproc);
43  for (i=0; i<nproc; i++) vec_rcvmap[i].resize(nproc);
44  vec_tmprcv.resize(0);
45  vec_tmpcnt.resize(nproc);
46  vec_tmprcvchr.resize(nproc*nproc*sizeof(double));
47  vec_snddatchr.resize(nproc*nproc*sizeof(double));
48  }
49 
52  {
53  delete[] ptr_sndcnt;
54  delete[] ptr_rcvcnt;
55  delete[] ptr_snddat;
56  delete[] ptr_rcvdat;
57  delete[] ptr_sndmap;
58  for (int i=0; i<nproc; i++) delete[] ptr_rcvmap[i];
59  delete[] ptr_rcvmap;
60  delete[] ptr_tmprcv;
61  delete[] ptr_tmpcnt;
62  }
63 
65  int nproc;
67  int irank;
68 
70  int sndcnt;
71  int rcvcnt;
72  int* ptr_sndcnt;
73  int* ptr_rcvcnt;
74  double* ptr_snddat;
75  double* ptr_rcvdat;
76  int* ptr_sndmap;
77  int** ptr_rcvmap;
78  double* ptr_tmprcv;
79  int* ptr_tmpcnt;
80 
82  std::vector<int> vec_sndcnt;
83  std::vector<int> vec_rcvcnt;
84  std::vector<double> vec_snddat;
85  std::vector<double> vec_rcvdat;
86  std::vector<int> vec_sndmap;
87  std::vector<std::vector<int> > vec_rcvmap;
88  std::vector<double> vec_tmprcv;
89  std::vector<int> vec_tmpcnt;
90  std::vector<char> vec_tmprcvchr;
91  std::vector<char> vec_snddatchr;
92 
95  {
96  int i,j;
97  for (i=0; i<nproc; i++)
98  for (j=0; j<nproc; j++){
99  ptr_snddat[i*nproc+j]=(irank+1)*1000000+(i+1)*10000+(j+1);
100  ptr_rcvdat[i*nproc+j]=(i+1)*1000000+(irank+1)*10000+(j+1);
101  }
102  sndcnt=nproc*nproc;
103  rcvcnt=nproc*nproc;
104  vec_snddat.assign(ptr_snddat,ptr_snddat+nproc*nproc);
105  vec_rcvdat.assign(ptr_rcvdat,ptr_rcvdat+nproc*nproc);
106  vec_snddatchr.assign((char*)(ptr_snddat),(char*)(ptr_snddat+nproc*nproc));
107  }
108 
111  {
112  int i,j,k,l;
113  for (i=0; i<nproc; i++){
114  ptr_sndcnt[i]=(i+irank*irank)%nproc;
115  ptr_rcvcnt[i]=(i*i+irank)%nproc;
116  }
117  for(i=0; i<nproc*nproc; i++) { // making debugger shut up for uninitialized values
118  ptr_snddat[i]=0.;
119  ptr_rcvdat[i]=0.;
120  ptr_sndmap[i]=0;
121  }
122  for(i=0; i<nproc; i++) for(j=0; j<nproc; j++) ptr_rcvmap[i][j]=0; // making debugger shut up for uninitialized values
123  for(i=0, k=0; i<nproc; i++)
124  for(j=0; j<ptr_sndcnt[i]; j++, k++)
125  ptr_snddat[k]=(irank+1)*1000000+(i+1)*10000+(j+1);
126  for(i=0, k=0; i<nproc; i++)
127  for(j=0; j<ptr_rcvcnt[i]; j++, k++)
128  ptr_rcvdat[k]=(i+1)*1000000+(irank+1)*10000+(j+1);
129  for (i=0, k=0,l=0; i<nproc; k+=ptr_sndcnt[i], i++)
130  for (j=0; j<ptr_sndcnt[i]; j++,l++)
131  ptr_sndmap[l]=k+ptr_sndcnt[i]-1-j; // flipping all sets for each process
132  for (i=0, k=0, l=0; i<nproc; k+=ptr_rcvcnt[i], i++)
133  for (j=0; j<ptr_rcvcnt[i]; j++, l++)
134  ptr_rcvmap[i][j]=ptr_rcvcnt[i]-1-j;// redirecting to align start with nproc numbers
135  for(i=0, sndcnt=0, rcvcnt=0; i<nproc; i++){
136  sndcnt+=ptr_sndcnt[i];
137  rcvcnt+=ptr_rcvcnt[i];
138  }
139  vec_sndcnt.assign(ptr_sndcnt,ptr_sndcnt+nproc);
140  vec_rcvcnt.assign(ptr_rcvcnt,ptr_rcvcnt+nproc);
141  vec_snddat.assign(ptr_snddat,ptr_snddat+nproc*nproc);
142  vec_rcvdat.assign(ptr_rcvdat,ptr_rcvdat+nproc*nproc);
143  vec_sndmap.assign(ptr_sndmap,ptr_sndmap+nproc*nproc);
144  for (i=0; i<nproc; i++) vec_rcvmap[i].assign(ptr_rcvmap[i],ptr_rcvmap[i]+nproc);
145  vec_snddatchr.assign((char*)(ptr_snddat),(char*)(ptr_snddat+nproc*nproc));
146  }
147 
148 };
149 
151 
152 BOOST_FIXTURE_TEST_SUITE( PEScatterSuite, PEScatterFixture )
153 
154 
157 {
158  PEProcessSortedExecute(-1,CFinfo << "Testing scatter " << irank << "/" << nproc << CFendl; );
159 }
160 
162 
163 BOOST_AUTO_TEST_CASE( scatter_ptr_constant )
164 {
165  int i,r;
166 
167  setup_data_constant();
168 
169  for (r=0; r<nproc; r++) {
170 
171  delete[] ptr_tmprcv;
172  ptr_tmprcv=0;
173 
174  ptr_tmprcv=PE::Comm::instance().scatter(ptr_snddat, nproc, (double*)0, r);
175  for (i=0; i<nproc; i++) BOOST_CHECK_EQUAL( ptr_tmprcv[i] , ptr_rcvdat[r*nproc+i] );
176 
177  for (i=0; i<nproc*nproc; i++) ptr_tmprcv[i]=0.;
178  PE::Comm::instance().scatter(ptr_snddat, nproc, ptr_tmprcv, r);
179  for (i=0; i<nproc; i++) BOOST_CHECK_EQUAL( ptr_tmprcv[i] , ptr_rcvdat[r*nproc+i] );
180 
181  for (i=0; i<nproc*nproc; i++) ptr_tmprcv[i]=ptr_snddat[i];
182  PE::Comm::instance().scatter(ptr_tmprcv, nproc, ptr_tmprcv, r);
183  for (i=0; i<nproc; i++) BOOST_CHECK_EQUAL( ptr_tmprcv[i] , ptr_rcvdat[r*nproc+i] );
184 
185  delete[] ptr_tmprcv;
186  ptr_tmprcv=0;
187 
188  ptr_tmprcv=(double*)PE::Comm::instance().scatter((char*)ptr_snddat, nproc, (char*)0, r, sizeof(double));
189  for (i=0; i<nproc; i++) BOOST_CHECK_EQUAL( ptr_tmprcv[i] , ptr_rcvdat[r*nproc+i] );
190 
191  for (i=0; i<nproc*nproc; i++) ptr_tmprcv[i]=0.;
192  PE::Comm::instance().scatter((char*)ptr_snddat, nproc, (char*)ptr_tmprcv, r, sizeof(double));
193  for (i=0; i<nproc; i++) BOOST_CHECK_EQUAL( ptr_tmprcv[i] , ptr_rcvdat[r*nproc+i] );
194 
195  for (i=0; i<nproc*nproc; i++) ptr_tmprcv[i]=ptr_snddat[i];
196  PE::Comm::instance().scatter((char*)ptr_tmprcv, nproc, (char*)ptr_tmprcv, r, sizeof(double));
197  for (i=0; i<nproc; i++) BOOST_CHECK_EQUAL( ptr_tmprcv[i] , ptr_rcvdat[r*nproc+i] );
198  }
199 }
200 
202 
203 BOOST_AUTO_TEST_CASE( scatter_vector_constant )
204 {
205  int i,r;
206 
207  setup_data_constant();
208 
209  for (r=0; r<nproc; r++) {
210 
211  vec_tmprcv.resize(0);
212  vec_tmprcv.reserve(0);
213  PE::Comm::instance().scatter(vec_snddat, vec_tmprcv, r);
214  for (i=0; i<nproc; i++) BOOST_CHECK_EQUAL( vec_tmprcv[i] , vec_rcvdat[r*nproc+i] );
215  BOOST_CHECK_EQUAL( (int)vec_tmprcv.size() , rcvcnt/nproc );
216 
217  vec_tmprcv.assign(nproc*nproc,0.);
218  PE::Comm::instance().scatter(vec_snddat, vec_tmprcv, r);
219  for (i=0; i<nproc; i++) BOOST_CHECK_EQUAL( vec_tmprcv[i] , vec_rcvdat[r*nproc+i] );
220 
221  vec_tmprcv=vec_snddat;
222  PE::Comm::instance().scatter(vec_tmprcv, vec_tmprcv, r);
223  for (i=0; i<nproc; i++) BOOST_CHECK_EQUAL( vec_tmprcv[i] , vec_rcvdat[r*nproc+i] );
224 
225  vec_tmprcvchr.resize(0);
226  vec_tmprcvchr.reserve(0);
227  PE::Comm::instance().scatter(vec_snddatchr, vec_tmprcvchr, r );
228  BOOST_CHECK_EQUAL( vec_tmprcvchr.size() , sizeof(double)*rcvcnt/nproc );
229  for (i=0; i<nproc; i++) BOOST_CHECK_EQUAL( ((double*)(&vec_tmprcvchr[0]))[i], vec_rcvdat[r*nproc+i] );
230 
231  for (i=0; i<nproc*nproc; i++) ((double*)(&vec_tmprcvchr[0]))[i]=0.;
232  PE::Comm::instance().scatter(vec_snddatchr, vec_tmprcvchr, r );
233  for (i=0; i<nproc; i++) BOOST_CHECK_EQUAL( ((double*)(&vec_tmprcvchr[0]))[i], vec_rcvdat[r*nproc+i] );
234 
235  vec_tmprcvchr.assign((char*)(ptr_snddat),(char*)(ptr_snddat+nproc*nproc));
236  PE::Comm::instance().scatter(vec_tmprcvchr, vec_tmprcvchr, r );
237  for (i=0; i<nproc; i++) BOOST_CHECK_EQUAL( ((double*)(&vec_tmprcvchr[0]))[i], vec_rcvdat[r*nproc+i] );
238  }
239 }
240 
242 
243 BOOST_AUTO_TEST_CASE( scatter_ptr_variable )
244 {
245  int i,j,k,r;
246 
247  setup_data_variable();
248 
249  for (r=0; r<nproc; r++) {
250 
251  delete[] ptr_tmprcv;
252  ptr_tmprcv=0;
253  ptr_tmprcv=PE::Comm::instance().scatter(ptr_snddat, ptr_sndcnt, (double*)0, ptr_rcvcnt[r], r);
254  for (i=0, k=0; i<nproc; i++) for (j=0; j<ptr_rcvcnt[i]; j++, k++) if (i==r) BOOST_CHECK_EQUAL( ptr_tmprcv[j] , ptr_rcvdat[k] );
255 
256  for (i=0, k=0; i<nproc; i++) for (j=0; j<ptr_rcvcnt[i]; j++, k++) if (i==r) ptr_tmprcv[j]=0.;
257  PE::Comm::instance().scatter(ptr_snddat, ptr_sndcnt, ptr_tmprcv, ptr_rcvcnt[r], r);
258  for (i=0, k=0; i<nproc; i++) for (j=0; j<ptr_rcvcnt[i]; j++, k++) if (i==r) BOOST_CHECK_EQUAL( ptr_tmprcv[j] , ptr_rcvdat[k] );
259 
260  delete[] ptr_tmprcv;
261  ptr_tmprcv=new double[nproc*nproc];
262  for (i=0; i<nproc*nproc; i++) ptr_tmprcv[i]=ptr_snddat[i];
263  PE::Comm::instance().scatter(ptr_tmprcv, ptr_sndcnt, ptr_tmprcv, ptr_rcvcnt[r], r);
264  for (i=0, k=0; i<nproc; i++) for (j=0; j<ptr_rcvcnt[i]; j++, k++) if (i==r) BOOST_CHECK_EQUAL( ptr_tmprcv[j] , ptr_rcvdat[k] );
265 
266  delete[] ptr_tmprcv;
267  ptr_tmprcv=0;
268  for(i=0; i<nproc; i++) ptr_tmpcnt[i]=-1;
269  ptr_tmprcv=PE::Comm::instance().scatter(ptr_snddat, ptr_sndcnt, (double*)0, ptr_tmpcnt[r], r);
270  BOOST_CHECK_EQUAL( ptr_tmpcnt[r] , ptr_rcvcnt[r] );
271  for (i=0, k=0; i<nproc; i++) for (j=0; j<ptr_rcvcnt[i]; j++, k++) if (i==r) BOOST_CHECK_EQUAL( ptr_tmprcv[j] , ptr_rcvdat[k] );
272 
273  for (i=0, k=0; i<nproc; i++) for (j=0; j<ptr_rcvcnt[i]; j++, k++) if (i==r) ptr_tmprcv[j]=0.;
274  for(i=0; i<nproc; i++) ptr_tmpcnt[i]=-1;
275  PE::Comm::instance().scatter(ptr_snddat, ptr_sndcnt, ptr_tmprcv, ptr_tmpcnt[r], r);
276  BOOST_CHECK_EQUAL( ptr_tmpcnt[r] , ptr_rcvcnt[r] );
277  for (i=0, k=0; i<nproc; i++) for (j=0; j<ptr_rcvcnt[i]; j++, k++) if (i==r) BOOST_CHECK_EQUAL( ptr_tmprcv[j] , ptr_rcvdat[k] );
278 
279  delete[] ptr_tmprcv;
280  ptr_tmprcv=new double[nproc*nproc];
281  for (i=0; i<nproc*nproc; i++) ptr_tmprcv[i]=ptr_snddat[i];
282  for(i=0; i<nproc; i++) ptr_tmpcnt[i]=-1;
283  PE::Comm::instance().scatter(ptr_tmprcv, ptr_sndcnt, ptr_tmprcv, ptr_tmpcnt[r], r);
284  BOOST_CHECK_EQUAL( ptr_tmpcnt[r] , ptr_rcvcnt[r] );
285  for (i=0, k=0; i<nproc; i++) for (j=0; j<ptr_rcvcnt[i]; j++, k++) if (i==r) BOOST_CHECK_EQUAL( ptr_tmprcv[j] , ptr_rcvdat[k] );
286 
287  delete[] ptr_tmprcv;
288  ptr_tmprcv=0;
289  ptr_tmprcv=PE::Comm::instance().scatter(ptr_snddat, ptr_sndcnt, ptr_sndmap, (double*)0, ptr_rcvcnt[r], ptr_rcvmap[r], r);
290  for (i=0, k=0; i<nproc; i++) for (j=0; j<ptr_rcvcnt[i]; j++, k++) if (i==r) BOOST_CHECK_EQUAL( ptr_tmprcv[j] , ptr_rcvdat[k] );
291 
292  for (i=0, k=0; i<nproc; i++) for (j=0; j<ptr_rcvcnt[i]; j++, k++) if (i==r) ptr_tmprcv[j]=0.;
293  PE::Comm::instance().scatter(ptr_snddat, ptr_sndcnt, ptr_sndmap, ptr_tmprcv, ptr_rcvcnt[r], ptr_rcvmap[r], r);
294  for (i=0, k=0; i<nproc; i++) for (j=0; j<ptr_rcvcnt[i]; j++, k++) if (i==r) BOOST_CHECK_EQUAL( ptr_tmprcv[j] , ptr_rcvdat[k] );
295 
296  delete[] ptr_tmprcv;
297  ptr_tmprcv=new double[nproc*nproc];
298  for (i=0; i<nproc*nproc; i++) ptr_tmprcv[i]=ptr_snddat[i];
299  PE::Comm::instance().scatter(ptr_tmprcv, ptr_sndcnt, ptr_sndmap, ptr_tmprcv, ptr_rcvcnt[r], ptr_rcvmap[r], r);
300  for (i=0, k=0; i<nproc; i++) for (j=0; j<ptr_rcvcnt[i]; j++, k++) if (i==r) BOOST_CHECK_EQUAL( ptr_tmprcv[j] , ptr_rcvdat[k] );
301 
302  delete[] ptr_tmprcv;
303  ptr_tmprcv=0;
304  ptr_tmprcv=(double*)PE::Comm::instance().scatter((char*)ptr_snddat, ptr_sndcnt, (char*)0, ptr_rcvcnt[r], r, sizeof(double));
305  for (i=0, k=0; i<nproc; i++) for (j=0; j<ptr_rcvcnt[i]; j++, k++) if (i==r) BOOST_CHECK_EQUAL( ptr_tmprcv[j] , ptr_rcvdat[k] );
306 
307  for (i=0, k=0; i<nproc; i++) for (j=0; j<ptr_rcvcnt[i]; j++, k++) if (i==r) ptr_tmprcv[j]=0.;
308  PE::Comm::instance().scatter((char*)ptr_snddat, ptr_sndcnt, (char*)ptr_tmprcv, ptr_rcvcnt[r], r, sizeof(double));
309  for (i=0, k=0; i<nproc; i++) for (j=0; j<ptr_rcvcnt[i]; j++, k++) if (i==r) BOOST_CHECK_EQUAL( ptr_tmprcv[j] , ptr_rcvdat[k] );
310 
311  delete[] ptr_tmprcv;
312  ptr_tmprcv=new double[nproc*nproc];
313  for (i=0; i<nproc*nproc; i++) ptr_tmprcv[i]=ptr_snddat[i];
314  PE::Comm::instance().scatter((char*)ptr_tmprcv, ptr_sndcnt, (char*)ptr_tmprcv, ptr_rcvcnt[r], r, sizeof(double));
315  for (i=0, k=0; i<nproc; i++) for (j=0; j<ptr_rcvcnt[i]; j++, k++) if (i==r) BOOST_CHECK_EQUAL( ptr_tmprcv[j] , ptr_rcvdat[k] );
316 
317  delete[] ptr_tmprcv;
318  ptr_tmprcv=0;
319  for(i=0; i<nproc; i++) ptr_tmpcnt[i]=-1;
320  ptr_tmprcv=(double*)PE::Comm::instance().scatter((char*)ptr_snddat, ptr_sndcnt, (char*)0, ptr_tmpcnt[r], r, sizeof(double));
321  BOOST_CHECK_EQUAL( ptr_tmpcnt[r] , ptr_rcvcnt[r] );
322  for (i=0, k=0; i<nproc; i++) for (j=0; j<ptr_rcvcnt[i]; j++, k++) if (i==r) BOOST_CHECK_EQUAL( ptr_tmprcv[j] , ptr_rcvdat[k] );
323 
324  for (i=0, k=0; i<nproc; i++) for (j=0; j<ptr_rcvcnt[i]; j++, k++) if (i==r) ptr_tmprcv[j]=0.;
325  for(i=0; i<nproc; i++) ptr_tmpcnt[i]=-1;
326  PE::Comm::instance().scatter((char*)ptr_snddat, ptr_sndcnt, (char*)ptr_tmprcv, ptr_tmpcnt[r], r, sizeof(double));
327  BOOST_CHECK_EQUAL( ptr_tmpcnt[r] , ptr_rcvcnt[r] );
328  for (i=0, k=0; i<nproc; i++) for (j=0; j<ptr_rcvcnt[i]; j++, k++) if (i==r) BOOST_CHECK_EQUAL( ptr_tmprcv[j] , ptr_rcvdat[k] );
329 
330  delete[] ptr_tmprcv;
331  ptr_tmprcv=new double[nproc*nproc];
332  for (i=0; i<nproc*nproc; i++) ptr_tmprcv[i]=ptr_snddat[i];
333  for(i=0; i<nproc; i++) ptr_tmpcnt[i]=-1;
334  PE::Comm::instance().scatter((char*)ptr_tmprcv, ptr_sndcnt, (char*)ptr_tmprcv, ptr_tmpcnt[r], r, sizeof(double));
335  BOOST_CHECK_EQUAL( ptr_tmpcnt[r] , ptr_rcvcnt[r] );
336  for (i=0, k=0; i<nproc; i++) for (j=0; j<ptr_rcvcnt[i]; j++, k++ ) if (i==r) BOOST_CHECK_EQUAL( ptr_tmprcv[j] , ptr_rcvdat[k] );
337 
338  delete[] ptr_tmprcv;
339  ptr_tmprcv=0;
340  ptr_tmprcv=(double*)PE::Comm::instance().scatter((char*)ptr_snddat, ptr_sndcnt, ptr_sndmap, (char*)0, ptr_rcvcnt[r], ptr_rcvmap[r], r, sizeof(double));
341  for (i=0, k=0; i<nproc; i++) for (j=0; j<ptr_rcvcnt[i]; j++, k++) if (i==r) BOOST_CHECK_EQUAL( ptr_tmprcv[j] , ptr_rcvdat[k] );
342 
343  for (i=0, k=0; i<nproc; i++) for (j=0; j<ptr_rcvcnt[i]; j++, k++) if (i==r) ptr_tmprcv[j]=0.;
344  PE::Comm::instance().scatter((char*)ptr_snddat, ptr_sndcnt, ptr_sndmap, (char*)ptr_tmprcv, ptr_rcvcnt[r], ptr_rcvmap[r], r, sizeof(double));
345  for (i=0, k=0; i<nproc; i++) for (j=0; j<ptr_rcvcnt[i]; j++, k++) if (i==r) BOOST_CHECK_EQUAL( ptr_tmprcv[j] , ptr_rcvdat[k] );
346 
347  delete[] ptr_tmprcv;
348  ptr_tmprcv=new double[nproc*nproc];
349  for (i=0; i<nproc*nproc; i++) ptr_tmprcv[i]=ptr_snddat[i];
350  PE::Comm::instance().scatter((char*)ptr_tmprcv, ptr_sndcnt, ptr_sndmap, (char*)ptr_tmprcv, ptr_rcvcnt[r], ptr_rcvmap[r], r, sizeof(double));
351  for (i=0, k=0; i<nproc; i++) for (j=0; j<ptr_rcvcnt[i]; j++, k++) if (i==r) BOOST_CHECK_EQUAL( ptr_tmprcv[j] , ptr_rcvdat[k] );
352  }
353 }
354 
356 
357 BOOST_AUTO_TEST_CASE( scatter_vector_variable )
358 {
359  int i,j,k,r;
360 
361  setup_data_variable();
362 
363  for (r=0; r<nproc; r++) {
364 
365  vec_tmprcv.resize(0);
366  vec_tmprcv.reserve(0);
367  PE::Comm::instance().scatter(vec_snddat, vec_sndcnt, vec_tmprcv, vec_rcvcnt[r], r);
368  for (i=0, k=0; i<nproc; i++) for (j=0; j<vec_rcvcnt[i]; j++, k++) if (i==r) BOOST_CHECK_EQUAL( vec_tmprcv[j] , vec_rcvdat[k] );
369 
370  for (i=0, k=0; i<nproc; i++) for (j=0; j<vec_rcvcnt[i]; j++, k++) if (i==r) vec_tmprcv[j]=0.;
371  PE::Comm::instance().scatter(vec_snddat, vec_sndcnt, vec_tmprcv, vec_rcvcnt[r], r);
372  for (i=0, k=0; i<nproc; i++) for (j=0; j<vec_rcvcnt[i]; j++, k++) if (i==r) BOOST_CHECK_EQUAL( vec_tmprcv[j] , vec_rcvdat[k] );
373 
374  vec_tmprcv.resize(nproc*nproc);
375  vec_tmprcv.reserve(nproc*nproc);
376  for (i=0; i<nproc*nproc; i++) vec_tmprcv[i]=vec_snddat[i];
377  PE::Comm::instance().scatter(vec_tmprcv, vec_sndcnt, vec_tmprcv, vec_rcvcnt[r], r);
378  for (i=0, k=0; i<nproc; i++) for (j=0; j<vec_rcvcnt[i]; j++, k++) if (i==r) BOOST_CHECK_EQUAL( vec_tmprcv[j] , vec_rcvdat[k] );
379 
380  vec_tmprcv.resize(0);
381  vec_tmprcv.reserve(0);
382  for(i=0; i<nproc; i++) vec_tmpcnt[i]=-1;
383  PE::Comm::instance().scatter(vec_snddat, vec_sndcnt, vec_tmprcv, vec_tmpcnt[r], r);
384  BOOST_CHECK_EQUAL( vec_tmpcnt[r] , vec_rcvcnt[r] );
385  for (i=0, k=0; i<nproc; i++) for (j=0; j<vec_rcvcnt[i]; j++, k++) if (i==r) BOOST_CHECK_EQUAL( vec_tmprcv[j] , vec_rcvdat[k] );
386 
387  for (i=0, k=0; i<nproc; i++) for (j=0; j<vec_rcvcnt[i]; j++, k++) if (i==r) vec_tmprcv[j]=0.;
388  for(i=0; i<nproc; i++) vec_tmpcnt[i]=-1;
389  PE::Comm::instance().scatter(vec_snddat, vec_sndcnt, vec_tmprcv, vec_tmpcnt[r], r);
390  BOOST_CHECK_EQUAL( vec_tmpcnt[r] , vec_rcvcnt[r] );
391  for (i=0, k=0; i<nproc; i++) for (j=0; j<vec_rcvcnt[i]; j++, k++) if (i==r) BOOST_CHECK_EQUAL( vec_tmprcv[j] , vec_rcvdat[k] );
392 
393  vec_tmprcv.resize(nproc*nproc);
394  vec_tmprcv.reserve(nproc*nproc);
395  for (i=0; i<nproc*nproc; i++) vec_tmprcv[i]=vec_snddat[i];
396  for(i=0; i<nproc; i++) vec_tmpcnt[i]=-1;
397  PE::Comm::instance().scatter(vec_tmprcv, vec_sndcnt, vec_tmprcv, vec_tmpcnt[r], r);
398  BOOST_CHECK_EQUAL( vec_tmpcnt[r] , vec_rcvcnt[r] );
399  for (i=0, k=0; i<nproc; i++) for (j=0; j<vec_rcvcnt[i]; j++, k++) if (i==r) BOOST_CHECK_EQUAL( vec_tmprcv[j] , vec_rcvdat[k] );
400 
401  vec_tmprcv.resize(0);
402  vec_tmprcv.reserve(0);
403  PE::Comm::instance().scatter(vec_snddat, vec_sndcnt, vec_sndmap, vec_tmprcv, vec_rcvcnt[r], vec_rcvmap[r], r);
404  for (i=0, k=0; i<nproc; i++) for (j=0; j<vec_rcvcnt[i]; j++, k++) if (i==r) BOOST_CHECK_EQUAL( vec_tmprcv[j] , vec_rcvdat[k] );
405 
406  for (i=0, k=0; i<nproc; i++) for (j=0; j<vec_rcvcnt[i]; j++, k++) if (i==r) vec_tmprcv[j]=0.;
407  PE::Comm::instance().scatter(vec_snddat, vec_sndcnt, vec_sndmap, vec_tmprcv, vec_rcvcnt[r], vec_rcvmap[r], r);
408  for (i=0, k=0; i<nproc; i++) for (j=0; j<vec_rcvcnt[i]; j++, k++) if (i==r) BOOST_CHECK_EQUAL( vec_tmprcv[j] , vec_rcvdat[k] );
409 
410  vec_tmprcv.resize(nproc*nproc);
411  vec_tmprcv.reserve(nproc*nproc);
412  for (i=0; i<nproc*nproc; i++) vec_tmprcv[i]=vec_snddat[i];
413  PE::Comm::instance().scatter(vec_tmprcv, vec_sndcnt, vec_sndmap, vec_tmprcv, vec_rcvcnt[r], vec_rcvmap[r], r);
414  for (i=0, k=0; i<nproc; i++) for (j=0; j<vec_rcvcnt[i]; j++, k++) if (i==r) BOOST_CHECK_EQUAL( vec_tmprcv[j] , vec_rcvdat[k] );
415 
416  vec_tmprcvchr.resize(0);
417  vec_tmprcvchr.reserve(0);
418  PE::Comm::instance().scatter(vec_snddatchr, vec_sndcnt, vec_tmprcvchr, vec_rcvcnt[r], r, sizeof(double));
419  for (i=0, k=0; i<nproc; i++) for (j=0; j<vec_rcvcnt[i]; j++, k++) if (i==r) BOOST_CHECK_EQUAL( ((double*)(&vec_tmprcvchr[0]))[j] , vec_rcvdat[k] );
420 
421  for (i=0, k=0; i<nproc; i++) for (j=0; j<vec_rcvcnt[i]; j++, k++) if (i==r) ((double*)(&vec_tmprcvchr[0]))[j]=0.;
422  PE::Comm::instance().scatter(vec_snddatchr, vec_sndcnt, vec_tmprcvchr, vec_rcvcnt[r], r, sizeof(double));
423  for (i=0, k=0; i<nproc; i++) for (j=0; j<vec_rcvcnt[i]; j++, k++) if (i==r) BOOST_CHECK_EQUAL( ((double*)(&vec_tmprcvchr[0]))[j] , vec_rcvdat[k] );
424 
425  vec_tmprcvchr.resize(nproc*nproc*sizeof(double));
426  vec_tmprcvchr.reserve(nproc*nproc*sizeof(double));
427  for (i=0; i<nproc*nproc; i++) ((double*)(&vec_tmprcvchr[0]))[i]=vec_snddat[i];
428  PE::Comm::instance().scatter(vec_tmprcvchr, vec_sndcnt, vec_tmprcvchr, vec_rcvcnt[r], r, sizeof(double));
429  for (i=0, k=0; i<nproc; i++) for (j=0; j<vec_rcvcnt[i]; j++, k++) if (i==r) BOOST_CHECK_EQUAL( ((double*)(&vec_tmprcvchr[0]))[j] , vec_rcvdat[k] );
430 
431  vec_tmprcvchr.resize(0);
432  vec_tmprcvchr.reserve(0);
433  for(i=0; i<nproc; i++) vec_tmpcnt[i]=-1;
434  PE::Comm::instance().scatter(vec_snddatchr, vec_sndcnt, vec_tmprcvchr, vec_tmpcnt[r], r, sizeof(double));
435  BOOST_CHECK_EQUAL( vec_tmpcnt[r] , vec_rcvcnt[r] );
436  for (i=0, k=0; i<nproc; i++) for (j=0; j<vec_rcvcnt[i]; j++, k++) if (i==r) BOOST_CHECK_EQUAL( ((double*)(&vec_tmprcvchr[0]))[j] , vec_rcvdat[k] );
437 
438  for (i=0, k=0; i<nproc; i++) for (j=0; j<vec_rcvcnt[i]; j++, k++) if (i==r) ((double*)(&vec_tmprcvchr[0]))[j]=0.;
439  for(i=0; i<nproc; i++) vec_tmpcnt[i]=-1;
440  PE::Comm::instance().scatter(vec_snddatchr, vec_sndcnt, vec_tmprcvchr, vec_tmpcnt[r], r, sizeof(double));
441  BOOST_CHECK_EQUAL( vec_tmpcnt[r] , vec_rcvcnt[r] );
442  for (i=0, k=0; i<nproc; i++) for (j=0; j<vec_rcvcnt[i]; j++, k++) if (i==r) BOOST_CHECK_EQUAL( ((double*)(&vec_tmprcvchr[0]))[j] , vec_rcvdat[k] );
443 
444  vec_tmprcvchr.resize(nproc*nproc*sizeof(double));
445  vec_tmprcvchr.reserve(nproc*nproc*sizeof(double));
446  for (i=0; i<nproc*nproc; i++) ((double*)(&vec_tmprcvchr[0]))[i]=vec_snddat[i];
447  for(i=0; i<nproc; i++) vec_tmpcnt[i]=-1;
448  PE::Comm::instance().scatter(vec_tmprcvchr, vec_sndcnt, vec_tmprcvchr, vec_tmpcnt[r], r, sizeof(double));
449  BOOST_CHECK_EQUAL( vec_tmpcnt[r] , vec_rcvcnt[r] );
450  for (i=0, k=0; i<nproc; i++) for (j=0; j<vec_rcvcnt[i]; j++, k++) if (i==r) BOOST_CHECK_EQUAL( ((double*)(&vec_tmprcvchr[0]))[j] , vec_rcvdat[k] );
451 
452  vec_tmprcvchr.resize(0);
453  vec_tmprcvchr.reserve(0);
454  PE::Comm::instance().scatter(vec_snddatchr, vec_sndcnt, vec_sndmap, vec_tmprcvchr, vec_rcvcnt[r], vec_rcvmap[r], r, sizeof(double));
455  for (i=0, k=0; i<nproc; i++) for (j=0; j<vec_rcvcnt[i]; j++, k++) if (i==r) BOOST_CHECK_EQUAL( ((double*)(&vec_tmprcvchr[0]))[j] , vec_rcvdat[k] );
456 
457  for (i=0, k=0; i<nproc; i++) for (j=0; j<vec_rcvcnt[i]; j++, k++) if (i==r) ((double*)&vec_tmprcvchr[0])[j]=0.;
458  PE::Comm::instance().scatter(vec_snddatchr, vec_sndcnt, vec_sndmap, vec_tmprcvchr, vec_rcvcnt[r], vec_rcvmap[r], r, sizeof(double));
459  for (i=0, k=0; i<nproc; i++) for (j=0; j<vec_rcvcnt[i]; j++, k++) if (i==r) BOOST_CHECK_EQUAL( ((double*)(&vec_tmprcvchr[0]))[j] , vec_rcvdat[k] );
460 
461  vec_tmprcvchr.resize(nproc*nproc*sizeof(double));
462  vec_tmprcvchr.reserve(nproc*nproc*sizeof(double));
463  for (i=0; i<nproc*nproc; i++) ((double*)(&vec_tmprcvchr[0]))[i]=vec_snddat[i];
464  PE::Comm::instance().scatter(vec_tmprcvchr, vec_sndcnt, vec_sndmap, vec_tmprcvchr, vec_rcvcnt[r], vec_rcvmap[r], r, sizeof(double));
465  for (i=0, k=0; i<nproc; i++) for (j=0; j<vec_rcvcnt[i]; j++, k++) if (i==r) BOOST_CHECK_EQUAL( ((double*)(&vec_tmprcvchr[0]))[j] , vec_rcvdat[k] );
466  }
467 }
468 
470 
471 BOOST_AUTO_TEST_SUITE_END()
472 
473 
#define CFinfo
these are always defined
Definition: Log.hpp:104
void setup_data_constant()
helper function for constant size data - setting up input and verification data
int sndcnt
data for raw pointers
BOOST_AUTO_TEST_CASE(scatter)
#define CFendl
Definition: Log.hpp:109
T * scatter(const Communicator &comm, const T *in_values, const int in_n, T *out_values, const int root, const int stride=1)
Definition: scatter.hpp:187
std::vector< std::vector< int > > vec_rcvmap
~PEScatterFixture()
common tear-down for each test case
std::vector< int > vec_sndcnt
data for std::vectors
PEScatterFixture()
common setup for each test case
void setup_data_variable()
helper function for variable size data - setting up input and verification data
#define PEProcessSortedExecute(irank, expression)
Definition: debug.hpp:43
Send comments to:
COOLFluiD Web Admin