COOLFluiD  Release kernel
COOLFluiD is a Collaborative Simulation Environment (CSE) focused on complex MultiPhysics simulations.
utest-parallel-collective-gather.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_rcvcnt=new int[nproc];
27  ptr_snddat=new double[nproc];
28  ptr_rcvdat=new double[nproc*nproc];
29  ptr_sndmap=new int[nproc];
30  ptr_rcvmap=new int[nproc*nproc];
31  ptr_tmprcv=new double[nproc*nproc];
32  ptr_tmpcnt=new int[nproc];
33 
34  // std::Vector helpers
35  vec_rcvcnt.resize(nproc);
36  vec_snddat.resize(nproc);
37  vec_rcvdat.resize(nproc*nproc);
38  vec_sndmap.resize(nproc);
39  vec_rcvmap.resize(nproc*nproc);
40  vec_tmprcv.resize(0);
41  vec_tmpcnt.resize(nproc);
42  vec_tmprcvchr.resize(nproc*nproc*sizeof(double));
43  vec_snddatchr.resize(nproc*sizeof(double));
44  }
45 
48  {
49  int i;
50  delete[] ptr_rcvcnt;
51  delete[] ptr_snddat;
52  delete[] ptr_rcvdat;
53  delete[] ptr_sndmap;
54  delete[] ptr_rcvmap;
55  delete[] ptr_tmprcv;
56  delete[] ptr_tmpcnt;
57  }
58 
60  int nproc;
62  int irank;
63 
65  int sndcnt;
66  int rcvcnt;
67  int* ptr_rcvcnt;
68  double* ptr_snddat;
69  double* ptr_rcvdat;
70  int* ptr_sndmap;
71  int* ptr_rcvmap;
72  double* ptr_tmprcv;
73  int* ptr_tmpcnt;
74 
76  std::vector<int> vec_rcvcnt;
77  std::vector<double> vec_snddat;
78  std::vector<double> vec_rcvdat;
79  std::vector<int> vec_sndmap;
80  std::vector<int> vec_rcvmap;
81  std::vector<double> vec_tmprcv;
82  std::vector<int> vec_tmpcnt;
83  std::vector<char> vec_tmprcvchr;
84  std::vector<char> vec_snddatchr;
85 
88  {
89  int i,j;
90  for (i=0; i<nproc; i++){
91  ptr_snddat[i]=(irank+1)*1000+(i+1);
92  for (j=0; j<nproc; j++){
93  ptr_rcvdat[i*nproc+j]=(i+1)*1000+(j+1);
94  }
95  }
96  sndcnt=nproc;
97  rcvcnt=nproc*nproc;
98  vec_snddat.assign(ptr_snddat,ptr_snddat+nproc);
99  vec_rcvdat.assign(ptr_rcvdat,ptr_rcvdat+nproc*nproc);
100  vec_snddatchr.assign((char*)(ptr_snddat),(char*)(ptr_snddat+nproc));
101  }
102 
105  {
106  int i,j,k,l;
107  for (i=0; i<nproc; i++){
108  ptr_rcvcnt[i]=i;
109  }
110  if (nproc==1) ptr_rcvcnt[0]=1;
111  sndcnt=ptr_rcvcnt[irank];
112  for(i=0; i<nproc*nproc; i++) { // making debugger shut up for uninitialized values
113  ptr_rcvdat[i]=0.;
114  ptr_rcvmap[i]=0;
115  }
116  for(i=0; i<nproc; i++) { // making debugger shut up for uninitialized values
117  ptr_snddat[i]=0.;
118  ptr_sndmap[i]=0;
119  }
120  for(i=0; i<nproc; i++)
121  ptr_snddat[i]=(irank+1)*1000+(i+1);
122  for (i=0, k=0; i<nproc; i++)
123  for (j=0; j<ptr_rcvcnt[i]; j++,k++)
124  ptr_rcvdat[k]=(i+1)*1000+(j+1);
125  for (i=0; i<sndcnt; i++)
126  ptr_sndmap[i]=sndcnt-1-i; // flipping all sets for each process
127  for (i=0, k=0; i<nproc; i++)
128  for (j=0; j<ptr_rcvcnt[i]; j++,k++)
129  ptr_rcvmap[k]=i*nproc+ptr_rcvcnt[i]-j-1; // flipping and redirecting to align start with nproc numbers
130  for(i=0, rcvcnt=0; i<nproc; i++){
131  rcvcnt+=ptr_rcvcnt[i];
132  }
133  vec_rcvcnt.assign(ptr_rcvcnt,ptr_rcvcnt+nproc);
134  vec_snddat.assign(ptr_snddat,ptr_snddat+nproc);
135  vec_rcvdat.assign(ptr_rcvdat,ptr_rcvdat+nproc*nproc);
136  vec_sndmap.assign(ptr_sndmap,ptr_sndmap+nproc);
137  vec_rcvmap.assign(ptr_rcvmap,ptr_rcvmap+nproc*nproc);
138  vec_snddatchr.assign((char*)(ptr_snddat),(char*)(ptr_snddat+nproc));
139  }
140 
141 };
142 
144 
145 BOOST_FIXTURE_TEST_SUITE( PEGatherSuite, PEGatherFixture )
146 
147 
150 {
151  PEProcessSortedExecute(-1,CFinfo << "Testing gather " << irank << "/" << nproc << CFendl; );
152 }
153 
155 
156 BOOST_AUTO_TEST_CASE( gather_ptr_constant )
157 {
158  int i ,r;
159 
160  setup_data_constant();
161 
162  for (r=0; r<nproc; r++){
163 
164  delete[] ptr_tmprcv;
165  ptr_tmprcv=0;
166 
167  ptr_tmprcv=PE::Comm::instance().gather(ptr_snddat, nproc, (double*)0, r);
168  if (r==irank) for (i=0; i<nproc*nproc; i++) BOOST_CHECK_EQUAL( ptr_tmprcv[i] , ptr_rcvdat[i] );
169  if (r!=irank) BOOST_CHECK_EQUAL( ptr_tmprcv , (double*)0 );
170 
171  if (r==irank) for (i=0; i<nproc*nproc; i++) ptr_tmprcv[i]=0.;
172  PE::Comm::instance().gather(ptr_snddat, nproc, ptr_tmprcv, r);
173  if (r==irank) for (i=0; i<nproc*nproc; i++) BOOST_CHECK_EQUAL( ptr_tmprcv[i] , ptr_rcvdat[i] );
174 
175  ptr_tmprcv=new double[nproc*nproc];
176  for (i=0; i<nproc*nproc; i++) ptr_tmprcv[i]=0.;
177  for (i=0; i<nproc; i++) ptr_tmprcv[i]=ptr_snddat[i];
178  PE::Comm::instance().gather(ptr_tmprcv, nproc, ptr_tmprcv, r);
179  if (r==irank) for (i=0; i<nproc*nproc; i++) BOOST_CHECK_EQUAL( ptr_tmprcv[i] , ptr_rcvdat[i] );
180 
181  delete[] ptr_tmprcv;
182  ptr_tmprcv=0;
183 
184  ptr_tmprcv=(double*)PE::Comm::instance().gather((char*)ptr_snddat, nproc, (char*)0, r, sizeof(double));
185  if (r==irank) for (i=0; i<nproc*nproc; i++) BOOST_CHECK_EQUAL( ptr_tmprcv[i] , ptr_rcvdat[i] );
186  if (r!=irank) BOOST_CHECK_EQUAL( ptr_tmprcv , (double*)0 );
187 
188  if (r==irank) for (i=0; i<nproc*nproc; i++) ptr_tmprcv[i]=0.;
189  PE::Comm::instance().gather((char*)ptr_snddat, nproc, (char*)ptr_tmprcv, r, sizeof(double));
190  if (r==irank) for (i=0; i<nproc*nproc; i++) BOOST_CHECK_EQUAL( ptr_tmprcv[i] , ptr_rcvdat[i] );
191 
192  ptr_tmprcv=new double[nproc*nproc];
193  for (i=0; i<nproc*nproc; i++) ptr_tmprcv[i]=0.;
194  for (i=0; i<nproc; i++) ptr_tmprcv[i]=ptr_snddat[i];
195  PE::Comm::instance().gather((char*)ptr_tmprcv, nproc, (char*)ptr_tmprcv, r, sizeof(double));
196  if (r==irank) for (i=0; i<nproc*nproc; i++) BOOST_CHECK_EQUAL( ptr_tmprcv[i] , ptr_rcvdat[i] );
197  }
198 }
199 
201 
202 BOOST_AUTO_TEST_CASE( gather_vector_constant )
203 {
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 
214  PE::Comm::instance().gather(vec_snddat, vec_tmprcv, r);
215  if (r==irank) for (i=0; i<nproc*nproc; i++) BOOST_CHECK_EQUAL( vec_tmprcv[i] , vec_rcvdat[i] );
216  if (r==irank) BOOST_CHECK_EQUAL( (int)vec_tmprcv.size() , rcvcnt );
217  if (r!=irank) BOOST_CHECK_EQUAL( (int)vec_tmprcv.size() , 0 );
218 
219  if (r==irank) vec_tmprcv.assign(nproc*nproc,0.);
220  PE::Comm::instance().gather(vec_snddat, vec_tmprcv, r);
221  if (r==irank) for (i=0; i<nproc*nproc; i++) BOOST_CHECK_EQUAL( vec_tmprcv[i] , vec_rcvdat[i] );
222 
223  vec_tmprcv=vec_snddat;
224  PE::Comm::instance().gather(vec_tmprcv, vec_tmprcv, r);
225  if (r==irank) for (i=0; i<nproc*nproc; i++) BOOST_CHECK_EQUAL( vec_tmprcv[i] , vec_rcvdat[i] );
226 
227  vec_tmprcvchr.resize(0);
228  vec_tmprcvchr.reserve(0);
229 
230  PE::Comm::instance().gather(vec_snddatchr, vec_tmprcvchr, r);
231  if (r==irank) BOOST_CHECK_EQUAL( vec_tmprcvchr.size() , sizeof(double)*rcvcnt );
232  if (r==irank) for (i=0; i<nproc*nproc; i++) BOOST_CHECK_EQUAL( ((double*)(&vec_tmprcvchr[0]))[i], vec_rcvdat[i] );
233  if (r!=irank) BOOST_CHECK_EQUAL( (int)vec_tmprcvchr.size() , 0 );
234 
235  if (r==irank) for (i=0; i<nproc; i++) ((double*)(&vec_tmprcvchr[0]))[i]=0.;
236  PE::Comm::instance().gather(vec_snddatchr, vec_tmprcvchr, r);
237  if (r==irank) for (i=0; i<nproc*nproc; i++) BOOST_CHECK_EQUAL( ((double*)(&vec_tmprcvchr[0]))[i], vec_rcvdat[i] );
238 
239  vec_tmprcvchr.assign((char*)(ptr_snddat),(char*)(ptr_snddat+nproc));
240  PE::Comm::instance().gather(vec_tmprcvchr, vec_tmprcvchr, r);
241  if (r==irank) for (i=0; i<nproc*nproc; i++) BOOST_CHECK_EQUAL( ((double*)(&vec_tmprcvchr[0]))[i], vec_rcvdat[i] );
242  }
243 }
244 
246 
247 BOOST_AUTO_TEST_CASE( gather_ptr_variable )
248 {
249 
250  int i,j,k,r;
251 
252  setup_data_variable();
253 
254  for (r=0; r<nproc; r++){
255 
256  delete[] ptr_tmprcv;
257  ptr_tmprcv=0;
258  ptr_tmprcv=PE::Comm::instance().gather(ptr_snddat, sndcnt, (double*)0, ptr_rcvcnt, r);
259  if (r==irank) for (i=0, k=0; i<nproc; i++) for (j=0; j<ptr_rcvcnt[i]; j++, k++) BOOST_CHECK_EQUAL( ptr_tmprcv[k] , ptr_rcvdat[k] );
260  if (r!=irank) BOOST_CHECK_EQUAL( ptr_tmprcv , (double*)0 );
261 
262  if (r==irank) for (i=0, k=0; i<nproc; i++) for (j=0; j<ptr_rcvcnt[i]; j++, k++) ptr_tmprcv[k]=0.;
263  PE::Comm::instance().gather(ptr_snddat, sndcnt, ptr_tmprcv, ptr_rcvcnt, r);
264  if (r==irank) for (i=0, k=0; i<nproc; i++) for (j=0; j<ptr_rcvcnt[i]; j++, k++) BOOST_CHECK_EQUAL( ptr_tmprcv[k] , ptr_rcvdat[k] );
265 
266  delete[] ptr_tmprcv;
267  ptr_tmprcv=new double[nproc*nproc];
268  for (i=0, k=0; i<nproc; i++) for (j=0; j<ptr_rcvcnt[i]; j++, k++) ptr_tmprcv[k]=0.;
269  for (i=0; i<nproc; i++) ptr_tmprcv[i]=ptr_snddat[i];
270  PE::Comm::instance().gather(ptr_tmprcv, sndcnt, ptr_tmprcv, ptr_rcvcnt, r);
271  if (r==irank) for (i=0, k=0; i<nproc; i++) for (j=0; j<ptr_rcvcnt[i]; j++, k++) BOOST_CHECK_EQUAL( ptr_tmprcv[k] , ptr_rcvdat[k] );
272 
273  delete[] ptr_tmprcv;
274  ptr_tmprcv=0;
275  for(i=0; i<nproc; i++) ptr_tmpcnt[i]=-1; // needs to be set for all processes
276  ptr_tmprcv=PE::Comm::instance().gather(ptr_snddat, sndcnt, (double*)0, ptr_tmpcnt, r);
277  if (r==irank) for (i=0; i<nproc; i++) BOOST_CHECK_EQUAL( ptr_tmpcnt[i] , ptr_rcvcnt[i] );
278  if (r==irank) for (i=0, k=0; i<nproc; i++) for (j=0; j<ptr_rcvcnt[i]; j++, k++) BOOST_CHECK_EQUAL( ptr_tmprcv[k] , ptr_rcvdat[k] );
279  if (r!=irank) BOOST_CHECK_EQUAL( ptr_tmprcv , (double*)0 );
280 
281  if (r==irank) for (i=0, k=0; i<nproc; i++) for (j=0; j<ptr_rcvcnt[i]; j++, k++) ptr_tmprcv[k]=0.;
282  for(i=0; i<nproc; i++) ptr_tmpcnt[i]=-1; // needs to be set for all processes
283  PE::Comm::instance().gather(ptr_snddat, sndcnt, ptr_tmprcv, ptr_tmpcnt, r);
284  if (r==irank) for (i=0; i<nproc; i++) BOOST_CHECK_EQUAL( ptr_tmpcnt[i] , ptr_rcvcnt[i] );
285  if (r==irank) for (i=0, k=0; i<nproc; i++) for (j=0; j<ptr_rcvcnt[i]; j++, k++) BOOST_CHECK_EQUAL( ptr_tmprcv[k] , ptr_rcvdat[k] );
286 
287  delete[] ptr_tmprcv;
288  ptr_tmprcv=new double[nproc*nproc];
289  for (i=0, k=0; i<nproc; i++) for (j=0; j<ptr_rcvcnt[i]; j++, k++) ptr_tmprcv[k]=0.;
290  for (i=0; i<nproc; i++) ptr_tmprcv[i]=ptr_snddat[i];
291  for (i=0; i<nproc; i++) ptr_tmpcnt[i]=-1; // needs to be set for all processes
292  PE::Comm::instance().gather(ptr_tmprcv, sndcnt, ptr_tmprcv, ptr_tmpcnt, r);
293  if (r==irank) for (i=0; i<nproc; i++) BOOST_CHECK_EQUAL( ptr_tmpcnt[i] , ptr_rcvcnt[i] );
294  if (r==irank) for (i=0, k=0; i<nproc; i++) for (j=0; j<ptr_rcvcnt[i]; j++, k++) BOOST_CHECK_EQUAL( ptr_tmprcv[k] , ptr_rcvdat[k] );
295 
296  delete[] ptr_tmprcv;
297  ptr_tmprcv=0;
298  ptr_tmprcv=PE::Comm::instance().gather(ptr_snddat, sndcnt, ptr_sndmap, (double*)0, ptr_rcvcnt, ptr_rcvmap, r);
299  if (r==irank) for (i=0, k=0; i<nproc; i++) for (j=0; j<ptr_rcvcnt[i]; j++, k++) BOOST_CHECK_EQUAL( ptr_tmprcv[i*nproc+j] , ptr_rcvdat[k] ); // i*nproc+j is not a bug, check reason at init
300  if (r!=irank) BOOST_CHECK_EQUAL( ptr_tmprcv , (double*)0 );
301 
302  if (r==irank) for (i=0, k=0; i<nproc; i++) for (j=0; j<ptr_rcvcnt[i]; j++, k++) ptr_tmprcv[i*nproc+j]=0.;
303  PE::Comm::instance().gather(ptr_snddat, sndcnt, ptr_sndmap, ptr_tmprcv, ptr_rcvcnt, ptr_rcvmap, r);
304  if (r==irank) for (i=0, k=0; i<nproc; i++) for (j=0; j<ptr_rcvcnt[i]; j++, k++) BOOST_CHECK_EQUAL( ptr_tmprcv[i*nproc+j] , ptr_rcvdat[k] ); // i*nproc+j is not a bug, check reason at init
305 
306  delete[] ptr_tmprcv;
307  ptr_tmprcv=new double[nproc*nproc];
308  for (i=0, k=0; i<nproc; i++) for (j=0; j<ptr_rcvcnt[i]; j++, k++) ptr_tmprcv[i*nproc+j]=0.;
309  for (i=0; i<nproc; i++) ptr_tmprcv[i]=ptr_snddat[i];
310  PE::Comm::instance().gather(ptr_tmprcv, sndcnt, ptr_sndmap, ptr_tmprcv, ptr_rcvcnt, ptr_rcvmap, r);
311  if (r==irank) for (i=0, k=0; i<nproc; i++) for (j=0; j<ptr_rcvcnt[i]; j++, k++) BOOST_CHECK_EQUAL( ptr_tmprcv[i*nproc+j] , ptr_rcvdat[k] ); // i*nproc+j is not a bug, check reason at init
312 
313  delete[] ptr_tmprcv;
314  ptr_tmprcv=0;
315  ptr_tmprcv=(double*)PE::Comm::instance().gather((char*)ptr_snddat, sndcnt, (char*)0, ptr_rcvcnt, r, sizeof(double));
316  if (r==irank) for (i=0, k=0; i<nproc; i++) for (j=0; j<ptr_rcvcnt[i]; j++, k++) BOOST_CHECK_EQUAL( ptr_tmprcv[k] , ptr_rcvdat[k] );
317  if (r!=irank) BOOST_CHECK_EQUAL( ptr_tmprcv , (double*)0 );
318 
319  if (r==irank) for (i=0, k=0; i<nproc; i++) for (j=0; j<ptr_rcvcnt[i]; j++, k++) ptr_tmprcv[k]=0.;
320  PE::Comm::instance().gather((char*)ptr_snddat, sndcnt, (char*)ptr_tmprcv, ptr_rcvcnt, r, sizeof(double));
321  if (r==irank) for (i=0, k=0; i<nproc; i++) for (j=0; j<ptr_rcvcnt[i]; j++, k++) BOOST_CHECK_EQUAL( ptr_tmprcv[k] , ptr_rcvdat[k] );
322 
323  delete[] ptr_tmprcv;
324  ptr_tmprcv=new double[nproc*nproc];
325  for (i=0, k=0; i<nproc; i++) for (j=0; j<ptr_rcvcnt[i]; j++, k++) ptr_tmprcv[k]=0.;
326  for (i=0; i<nproc; i++) ptr_tmprcv[i]=ptr_snddat[i];
327  PE::Comm::instance().gather((char*)ptr_tmprcv, sndcnt, (char*)ptr_tmprcv, ptr_rcvcnt, r, sizeof(double));
328  if (r==irank) for (i=0, k=0; i<nproc; i++) for (j=0; j<ptr_rcvcnt[i]; j++, k++) BOOST_CHECK_EQUAL( ptr_tmprcv[k] , ptr_rcvdat[k] );
329 
330  delete[] ptr_tmprcv;
331  ptr_tmprcv=0;
332  for(i=0; i<nproc; i++) ptr_tmpcnt[i]=-1; // needs to be set for all processes
333  ptr_tmprcv=(double*)PE::Comm::instance().gather((char*)ptr_snddat, sndcnt, (char*)0, ptr_tmpcnt, r, sizeof(double));
334  if (r==irank) for (i=0; i<nproc; i++) BOOST_CHECK_EQUAL( ptr_tmpcnt[i] , ptr_rcvcnt[i] );
335  if (r==irank) for (i=0, k=0; i<nproc; i++) for (j=0; j<ptr_rcvcnt[i]; j++, k++) BOOST_CHECK_EQUAL( ptr_tmprcv[k] , ptr_rcvdat[k] );
336  if (r!=irank) BOOST_CHECK_EQUAL( ptr_tmprcv , (double*)0 );
337 
338  if (r==irank) for (i=0, k=0; i<nproc; i++) for (j=0; j<ptr_rcvcnt[i]; j++, k++) ptr_tmprcv[k]=0.;
339  for(i=0; i<nproc; i++) ptr_tmpcnt[i]=-1; // needs to be set for all processes
340  PE::Comm::instance().gather((char*)ptr_snddat, sndcnt, (char*)ptr_tmprcv, ptr_tmpcnt, r, sizeof(double));
341  if (r==irank) for (i=0; i<nproc; i++) BOOST_CHECK_EQUAL( ptr_tmpcnt[i] , ptr_rcvcnt[i] );
342  if (r==irank) for (i=0, k=0; i<nproc; i++) for (j=0; j<ptr_rcvcnt[i]; j++, k++) BOOST_CHECK_EQUAL( ptr_tmprcv[k] , ptr_rcvdat[k] );
343 
344  delete[] ptr_tmprcv;
345  ptr_tmprcv=new double[nproc*nproc];
346  for (i=0, k=0; i<nproc; i++) for (j=0; j<ptr_rcvcnt[i]; j++, k++) ptr_tmprcv[k]=0.;
347  for (i=0; i<nproc; i++) ptr_tmprcv[i]=ptr_snddat[i];
348  for (i=0; i<nproc; i++) ptr_tmpcnt[i]=-1; // needs to be set for all processes
349  PE::Comm::instance().gather((char*)ptr_tmprcv, sndcnt, (char*)ptr_tmprcv, ptr_tmpcnt, r, sizeof(double));
350  if (r==irank) for (i=0; i<nproc; i++) BOOST_CHECK_EQUAL( ptr_tmpcnt[i] , ptr_rcvcnt[i] );
351  if (r==irank) for (i=0, k=0; i<nproc; i++) for (j=0; j<ptr_rcvcnt[i]; j++, k++) BOOST_CHECK_EQUAL( ptr_tmprcv[k] , ptr_rcvdat[k] );
352 
353  delete[] ptr_tmprcv;
354  ptr_tmprcv=0;
355  ptr_tmprcv=(double*)PE::Comm::instance().gather((char*)ptr_snddat, sndcnt, ptr_sndmap, (char*)0, ptr_rcvcnt, ptr_rcvmap, r, sizeof(double));
356  if (r==irank) for (i=0, k=0; i<nproc; i++) for (j=0; j<ptr_rcvcnt[i]; j++, k++) BOOST_CHECK_EQUAL( ptr_tmprcv[i*nproc+j] , ptr_rcvdat[k] ); // i*nproc+j is not a bug, check reason at init
357  if (r!=irank) BOOST_CHECK_EQUAL( ptr_tmprcv , (double*)0 );
358 
359  if (r==irank) for (i=0, k=0; i<nproc; i++) for (j=0; j<ptr_rcvcnt[i]; j++, k++) ptr_tmprcv[i*nproc+j]=0.;
360  PE::Comm::instance().gather((char*)ptr_snddat, sndcnt, ptr_sndmap, (char*)ptr_tmprcv, ptr_rcvcnt, ptr_rcvmap, r, sizeof(double));
361  if (r==irank) for (i=0, k=0; i<nproc; i++) for (j=0; j<ptr_rcvcnt[i]; j++, k++) BOOST_CHECK_EQUAL( ptr_tmprcv[i*nproc+j] , ptr_rcvdat[k] ); // i*nproc+j is not a bug, check reason at init
362 
363  delete[] ptr_tmprcv;
364  ptr_tmprcv=new double[nproc*nproc];
365  for (i=0, k=0; i<nproc; i++) for (j=0; j<ptr_rcvcnt[i]; j++, k++) ptr_tmprcv[i*nproc+j]=0.;
366  for (i=0; i<nproc; i++) ptr_tmprcv[i]=ptr_snddat[i];
367  PE::Comm::instance().gather((char*)ptr_tmprcv, sndcnt, ptr_sndmap, (char*)ptr_tmprcv, ptr_rcvcnt, ptr_rcvmap, r, sizeof(double));
368  if (r==irank) for (i=0, k=0; i<nproc; i++) for (j=0; j<ptr_rcvcnt[i]; j++, k++) BOOST_CHECK_EQUAL( ptr_tmprcv[i*nproc+j] , ptr_rcvdat[k] ); // i*nproc+j is not a bug, check reason at init
369  }
370 }
371 
373 
374 BOOST_AUTO_TEST_CASE( gather_vector_variable )
375 {
376  int i,j,k,r;
377 
378  setup_data_variable();
379 
380  for (r=0; r<nproc; r++){
381 
382  vec_tmprcv.resize(0);
383  vec_tmprcv.reserve(0);
384 
385  PE::Comm::instance().gather(vec_snddat, sndcnt, vec_tmprcv, vec_rcvcnt, r);
386  if (r==irank) for (i=0, k=0; i<nproc; i++) for (j=0; j<vec_rcvcnt[i]; j++, k++) BOOST_CHECK_EQUAL( vec_tmprcv[k] , vec_rcvdat[k] );
387  if (r!=irank) BOOST_CHECK_EQUAL( (int)vec_tmprcv.size() , 0 );
388 
389  if (r==irank) for (i=0, k=0; i<nproc; i++) for (j=0; j<vec_rcvcnt[i]; j++, k++) vec_tmprcv[k]=0.;
390  PE::Comm::instance().gather(vec_snddat, sndcnt, vec_tmprcv, vec_rcvcnt, r);
391  if (r==irank) for (i=0, k=0; i<nproc; i++) for (j=0; j<vec_rcvcnt[i]; j++, k++) BOOST_CHECK_EQUAL( vec_tmprcv[k] , vec_rcvdat[k] );
392 
393  vec_tmprcv.resize(nproc*nproc);
394  vec_tmprcv.reserve(nproc*nproc);
395  for (i=0, k=0; i<nproc; i++) for (j=0; j<vec_rcvcnt[i]; j++, k++) vec_tmprcv[k]=0.;
396  for (i=0; i<nproc; i++) vec_tmprcv[i]=vec_snddat[i];
397  PE::Comm::instance().gather(vec_tmprcv, sndcnt, vec_tmprcv, vec_rcvcnt, r);
398  if (r==irank) for (i=0, k=0; i<nproc; i++) for (j=0; j<vec_rcvcnt[i]; j++, k++) BOOST_CHECK_EQUAL( vec_tmprcv[k] , vec_rcvdat[k] );
399 
400  vec_tmprcv.resize(0);
401  vec_tmprcv.reserve(0);
402  for(i=0; i<nproc; i++) vec_tmpcnt[i]=-1; // needs to be set for all processes
403  PE::Comm::instance().gather(vec_snddat, sndcnt, vec_tmprcv, vec_tmpcnt, r);
404  if (r==irank) for (i=0; i<nproc; i++) BOOST_CHECK_EQUAL( vec_tmpcnt[i] , vec_rcvcnt[i] );
405  if (r==irank) for (i=0, k=0; i<nproc; i++) for (j=0; j<vec_rcvcnt[i]; j++, k++) BOOST_CHECK_EQUAL( vec_tmprcv[k] , vec_rcvdat[k] );
406  if (r!=irank) BOOST_CHECK_EQUAL( (int)vec_tmprcv.size() , 0 );
407 
408  if (r==irank) for (i=0, k=0; i<nproc; i++) for (j=0; j<vec_rcvcnt[i]; j++, k++) vec_tmprcv[k]=0.;
409  for(i=0; i<nproc; i++) vec_tmpcnt[i]=-1; // needs to be set for all processes
410  PE::Comm::instance().gather(vec_snddat, sndcnt, vec_tmprcv, vec_tmpcnt, r);
411  if (r==irank) for (i=0; i<nproc; i++) BOOST_CHECK_EQUAL( vec_tmpcnt[i] , vec_rcvcnt[i] );
412  if (r==irank) for (i=0, k=0; i<nproc; i++) for (j=0; j<vec_rcvcnt[i]; j++, k++) BOOST_CHECK_EQUAL( vec_tmprcv[k] , vec_rcvdat[k] );
413 
414  vec_tmprcv.resize(nproc*nproc);
415  vec_tmprcv.reserve(nproc*nproc);
416  for (i=0, k=0; i<nproc; i++) for (j=0; j<vec_rcvcnt[i]; j++, k++) vec_tmprcv[k]=0.;
417  for (i=0; i<nproc; i++) vec_tmprcv[i]=vec_snddat[i];
418  for(i=0; i<nproc; i++) vec_tmpcnt[i]=-1; // needs to be set for all processes
419  PE::Comm::instance().gather(vec_tmprcv, sndcnt, vec_tmprcv, vec_tmpcnt, r);
420  if (r==irank) for (i=0; i<nproc; i++) BOOST_CHECK_EQUAL( vec_tmpcnt[i] , vec_rcvcnt[i] );
421  if (r==irank) for (i=0, k=0; i<nproc; i++) for (j=0; j<vec_rcvcnt[i]; j++, k++) BOOST_CHECK_EQUAL( vec_tmprcv[k] , vec_rcvdat[k] );
422 
423  vec_tmprcv.resize(0);
424  vec_tmprcv.reserve(0);
425  PE::Comm::instance().gather(vec_snddat, sndcnt, vec_sndmap, vec_tmprcv, vec_rcvcnt, vec_rcvmap, r);
426  if (r==irank) for (i=0, k=0; i<nproc; i++) for (j=0; j<vec_rcvcnt[i]; j++, k++) BOOST_CHECK_EQUAL( vec_tmprcv[i*nproc+j] , vec_rcvdat[k] ); // i*nproc+j is not a bug, check reason at init
427  if (r!=irank) BOOST_CHECK_EQUAL( (int)vec_tmprcv.size() , 0 );
428 
429  if (r==irank) for (i=0, k=0; i<nproc; i++) for (j=0; j<vec_rcvcnt[i]; j++, k++) vec_tmprcv[i*nproc+j]=0.;
430  PE::Comm::instance().gather(vec_snddat, sndcnt, vec_sndmap, vec_tmprcv, vec_rcvcnt, vec_rcvmap, r);
431  if (r==irank) for (i=0, k=0; i<nproc; i++) for (j=0; j<vec_rcvcnt[i]; j++, k++) BOOST_CHECK_EQUAL( vec_tmprcv[i*nproc+j] , vec_rcvdat[k] ); // i*nproc+j is not a bug, check reason at init
432 
433  vec_tmprcv.resize(nproc*nproc);
434  vec_tmprcv.reserve(nproc*nproc);
435  for (i=0, k=0; i<nproc; i++) for (j=0; j<vec_rcvcnt[i]; j++, k++) vec_tmprcv[i*nproc+j]=0.;
436  for (i=0; i<nproc; i++) vec_tmprcv[i]=vec_snddat[i];
437  PE::Comm::instance().gather(vec_tmprcv, sndcnt, vec_sndmap, vec_tmprcv, vec_rcvcnt, vec_rcvmap, r);
438  if (r==irank) for (i=0, k=0; i<nproc; i++) for (j=0; j<vec_rcvcnt[i]; j++, k++) BOOST_CHECK_EQUAL( vec_tmprcv[i*nproc+j] , vec_rcvdat[k] ); // i*nproc+j is not a bug, check reason at init
439 
440  vec_tmprcvchr.resize(0);
441  vec_tmprcvchr.reserve(0);
442  PE::Comm::instance().gather(vec_snddatchr, sndcnt, vec_tmprcvchr, vec_rcvcnt, r, sizeof(double));
443  if (r==irank) for (i=0, k=0; i<nproc; i++) for (j=0; j<vec_rcvcnt[i]; j++, k++) BOOST_CHECK_EQUAL( ((double*)(&vec_tmprcvchr[0]))[k] , vec_rcvdat[k] );
444  if (r!=irank) BOOST_CHECK_EQUAL( (int)vec_tmprcvchr.size() , 0 );
445 
446  if (r==irank) for (i=0, k=0; i<nproc; i++) for (j=0; j<vec_rcvcnt[i]; j++, k++) ((double*)(&vec_tmprcvchr[0]))[k]=0.;
447  PE::Comm::instance().gather(vec_snddatchr, sndcnt, vec_tmprcvchr, vec_rcvcnt, r, sizeof(double));
448  if (r==irank) for (i=0, k=0; i<nproc; i++) for (j=0; j<vec_rcvcnt[i]; j++, k++) BOOST_CHECK_EQUAL( ((double*)(&vec_tmprcvchr[0]))[k] , vec_rcvdat[k] );
449 
450  vec_tmprcvchr.resize(nproc*nproc*sizeof(double));
451  vec_tmprcvchr.reserve(nproc*nproc*sizeof(double));
452  for (i=0, k=0; i<nproc; i++) for (j=0; j<vec_rcvcnt[i]; j++, k++) ((double*)(&vec_tmprcvchr[0]))[k]=0.;
453  for (i=0; i<nproc; i++) ((double*)(&vec_tmprcvchr[0]))[i]=vec_snddat[i];
454  PE::Comm::instance().gather(vec_tmprcvchr, sndcnt, vec_tmprcvchr, vec_rcvcnt, r, sizeof(double));
455  if (r==irank) for (i=0, k=0; i<nproc; i++) for (j=0; j<vec_rcvcnt[i]; j++, k++) BOOST_CHECK_EQUAL( ((double*)(&vec_tmprcvchr[0]))[k] , vec_rcvdat[k] );
456 
457  vec_tmprcvchr.resize(0);
458  vec_tmprcvchr.reserve(0);
459  for(i=0; i<nproc; i++) vec_tmpcnt[i]=-1; // needs to be set for all processes
460  PE::Comm::instance().gather(vec_snddatchr, sndcnt, vec_tmprcvchr, vec_tmpcnt, r, sizeof(double));
461  if (r==irank) for (i=0; i<nproc; i++) BOOST_CHECK_EQUAL( vec_tmpcnt[i] , vec_rcvcnt[i] );
462  if (r==irank) for (i=0, k=0; i<nproc; i++) for (j=0; j<vec_rcvcnt[i]; j++, k++) BOOST_CHECK_EQUAL( ((double*)(&vec_tmprcvchr[0]))[k] , vec_rcvdat[k] );
463  if (r!=irank) BOOST_CHECK_EQUAL( (int)vec_tmprcvchr.size() , 0 );
464 
465  if (r==irank) for (i=0, k=0; i<nproc; i++) for (j=0; j<vec_rcvcnt[i]; j++, k++) ((double*)(&vec_tmprcvchr[0]))[k]=0.;
466  for(i=0; i<nproc; i++) vec_tmpcnt[i]=-1; // needs to be set for all processes
467  PE::Comm::instance().gather(vec_snddatchr, sndcnt, vec_tmprcvchr, vec_tmpcnt, r, sizeof(double));
468  if (r==irank) for (i=0; i<nproc; i++) BOOST_CHECK_EQUAL( vec_tmpcnt[i] , vec_rcvcnt[i] );
469  if (r==irank) for (i=0, k=0; i<nproc; i++) for (j=0; j<vec_rcvcnt[i]; j++, k++) BOOST_CHECK_EQUAL( ((double*)(&vec_tmprcvchr[0]))[k] , vec_rcvdat[k] );
470 
471  vec_tmprcvchr.resize(nproc*nproc*sizeof(double));
472  vec_tmprcvchr.reserve(nproc*nproc*sizeof(double));
473  for (i=0, k=0; i<nproc; i++) for (j=0; j<vec_rcvcnt[i]; j++, k++) ((double*)(&vec_tmprcvchr[0]))[k]=0.;
474  for (i=0; i<nproc; i++) ((double*)(&vec_tmprcvchr[0]))[i]=vec_snddat[i];
475  for(i=0; i<nproc; i++) vec_tmpcnt[i]=-1; // needs to be set for all processes
476  PE::Comm::instance().gather(vec_tmprcvchr, sndcnt, vec_tmprcvchr, vec_tmpcnt, r, sizeof(double));
477  if (r==irank) for (i=0; i<nproc; i++) BOOST_CHECK_EQUAL( vec_tmpcnt[i] , vec_rcvcnt[i] );
478  if (r==irank) for (i=0, k=0; i<nproc; i++) for (j=0; j<vec_rcvcnt[i]; j++, k++) BOOST_CHECK_EQUAL( ((double*)(&vec_tmprcvchr[0]))[k] , vec_rcvdat[k] );
479 
480  vec_tmprcvchr.resize(0);
481  vec_tmprcvchr.reserve(0);
482  PE::Comm::instance().gather(vec_snddatchr, sndcnt, vec_sndmap, vec_tmprcvchr, vec_rcvcnt, vec_rcvmap, r, sizeof(double));
483  if (r==irank) for (i=0, k=0; i<nproc; i++) for (j=0; j<vec_rcvcnt[i]; j++, k++) BOOST_CHECK_EQUAL( ((double*)(&vec_tmprcvchr[0]))[i*nproc+j] , vec_rcvdat[k] ); // i*nproc+j is not a bug, check reason at init
484  if (r!=irank) BOOST_CHECK_EQUAL( (int)vec_tmprcvchr.size() , 0 );
485 
486  if (r==irank) for (i=0, k=0; i<nproc; i++) for (j=0; j<vec_rcvcnt[i]; j++, k++) ((double*)(&vec_tmprcvchr[0]))[i*nproc+j]=0.;
487  PE::Comm::instance().gather(vec_snddatchr, sndcnt, vec_sndmap, vec_tmprcvchr, vec_rcvcnt, vec_rcvmap, r, sizeof(double));
488  if (r==irank) for (i=0, k=0; i<nproc; i++) for (j=0; j<vec_rcvcnt[i]; j++, k++) BOOST_CHECK_EQUAL( ((double*)(&vec_tmprcvchr[0]))[i*nproc+j] , vec_rcvdat[k] ); // i*nproc+j is not a bug, check reason at init
489 
490  vec_tmprcvchr.resize(nproc*nproc*sizeof(double));
491  vec_tmprcvchr.reserve(nproc*nproc*sizeof(double));
492  for (i=0, k=0; i<nproc; i++) for (j=0; j<vec_rcvcnt[i]; j++, k++) ((double*)(&vec_tmprcvchr[0]))[i*nproc+j]=0.;
493  for (i=0; i<nproc; i++) ((double*)(&vec_tmprcvchr[0]))[i]=vec_snddat[i];
494  PE::Comm::instance().gather(vec_tmprcvchr, sndcnt, vec_sndmap, vec_tmprcvchr, vec_rcvcnt, vec_rcvmap, r, sizeof(double));
495  if (r==irank) for (i=0, k=0; i<nproc; i++) for (j=0; j<vec_rcvcnt[i]; j++, k++) BOOST_CHECK_EQUAL( ((double*)(&vec_tmprcvchr[0]))[i*nproc+j] , vec_rcvdat[k] ); // i*nproc+j is not a bug, check reason at init
496  }
497 }
498 
500 
501 BOOST_AUTO_TEST_SUITE_END()
502 
503 
#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
std::vector< int > vec_rcvcnt
data for std::vectors
T * gather(const Communicator &comm, const T *in_values, const int in_n, T *out_values, const int root, const int stride=1)
Definition: gather.hpp:186
BOOST_AUTO_TEST_CASE(gather)
std::vector< double > vec_rcvdat
void setup_data_variable()
helper function for variable size data - setting up input and verification data
#define CFendl
Definition: Log.hpp:109
std::vector< double > vec_snddat
~PEGatherFixture()
common tear-down for each test case
int nproc
number of processes
std::vector< double > vec_tmprcv
int sndcnt
data for raw pointers
PEGatherFixture()
common setup for each test case
#define PEProcessSortedExecute(irank, expression)
Definition: debug.hpp:43
Send comments to:
COOLFluiD Web Admin