COOLFluiD  Release kernel
COOLFluiD is a Collaborative Simulation Environment (CSE) focused on complex MultiPhysics simulations.
utest-parallel-collective-all_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( PEAllGatherSuite, PEAllGatherFixture )
146 
147 
150 {
151  PEProcessSortedExecute(-1,CFinfo << "Testing all_gather " << irank << "/" << nproc << CFendl; );
152 }
153 
155 
156 BOOST_AUTO_TEST_CASE( all_gather_ptr_constant )
157 {
158  int i;
159 
160  setup_data_constant();
161 
162  delete[] ptr_tmprcv;
163  ptr_tmprcv=0;
164 
165  ptr_tmprcv=PE::Comm::instance().all_gather(ptr_snddat, nproc, (double*)0);
166  for (i=0; i<nproc*nproc; i++) BOOST_CHECK_EQUAL( ptr_tmprcv[i] , ptr_rcvdat[i] );
167 
168  for (i=0; i<nproc; i++) ptr_tmprcv[i]=0.;
169  PE::Comm::instance().all_gather(ptr_snddat, nproc, ptr_tmprcv);
170  for (i=0; i<nproc*nproc; i++) BOOST_CHECK_EQUAL( ptr_tmprcv[i] , ptr_rcvdat[i] );
171 
172  for (i=0; i<nproc; i++) ptr_tmprcv[i]=ptr_snddat[i];
173  PE::Comm::instance().all_gather(ptr_tmprcv, nproc, ptr_tmprcv);
174  for (i=0; i<nproc*nproc; i++) BOOST_CHECK_EQUAL( ptr_tmprcv[i] , ptr_rcvdat[i] );
175 
176  delete[] ptr_tmprcv;
177  ptr_tmprcv=0;
178  ptr_tmprcv=(double*)PE::Comm::instance().all_gather((char*)ptr_snddat, nproc, (char*)0, sizeof(double));
179  for (i=0; i<nproc*nproc; i++) BOOST_CHECK_EQUAL( ptr_tmprcv[i] , ptr_rcvdat[i] );
180 
181  for (i=0; i<nproc; i++) ptr_tmprcv[i]=0.;
182  PE::Comm::instance().all_gather((char*)ptr_snddat, nproc, (char*)ptr_tmprcv, sizeof(double));
183  for (i=0; i<nproc*nproc; i++) BOOST_CHECK_EQUAL( ptr_tmprcv[i] , ptr_rcvdat[i] );
184 
185  for (i=0; i<nproc; i++) ptr_tmprcv[i]=ptr_snddat[i];
186  PE::Comm::instance().all_gather((char*)ptr_tmprcv, nproc, (char*)ptr_tmprcv, sizeof(double));
187  for (i=0; i<nproc*nproc; i++) BOOST_CHECK_EQUAL( ptr_tmprcv[i] , ptr_rcvdat[i] );
188 }
189 
191 
192 BOOST_AUTO_TEST_CASE( all_gather_vector_constant )
193 {
194  int i;
195 
196  setup_data_constant();
197 
198  vec_tmprcv.resize(0);
199  vec_tmprcv.reserve(0);
200  PE::Comm::instance().all_gather(vec_snddat, vec_tmprcv);
201  for (i=0; i<nproc*nproc; i++) BOOST_CHECK_EQUAL( vec_tmprcv[i] , vec_rcvdat[i] );
202  BOOST_CHECK_EQUAL( (int)vec_tmprcv.size() , rcvcnt );
203 
204  vec_tmprcv.assign(nproc*nproc,0.);
205  PE::Comm::instance().all_gather(vec_snddat, vec_tmprcv);
206  for (i=0; i<nproc*nproc; i++) BOOST_CHECK_EQUAL( vec_tmprcv[i] , vec_rcvdat[i] );
207 
208  vec_tmprcv=vec_snddat;
209  PE::Comm::instance().all_gather(vec_tmprcv, vec_tmprcv);
210  for (i=0; i<nproc*nproc; i++) BOOST_CHECK_EQUAL( vec_tmprcv[i] , vec_rcvdat[i] );
211 
212  vec_tmprcvchr.resize(0);
213  vec_tmprcvchr.reserve(0);
214  PE::Comm::instance().all_gather(vec_snddatchr, vec_tmprcvchr );
215  BOOST_CHECK_EQUAL( vec_tmprcvchr.size() , sizeof(double)*rcvcnt );
216  for (i=0; i<nproc*nproc; i++) BOOST_CHECK_EQUAL( ((double*)(&vec_tmprcvchr[0]))[i], vec_rcvdat[i] );
217 
218  for (i=0; i<nproc; i++) ((double*)(&vec_tmprcvchr[0]))[i]=0.;
219  PE::Comm::instance().all_gather(vec_snddatchr, vec_tmprcvchr );
220  for (i=0; i<nproc*nproc; i++) BOOST_CHECK_EQUAL( ((double*)(&vec_tmprcvchr[0]))[i], vec_rcvdat[i] );
221 
222  vec_tmprcvchr.assign((char*)(ptr_snddat),(char*)(ptr_snddat+nproc));
223  PE::Comm::instance().all_gather(vec_tmprcvchr, vec_tmprcvchr );
224  for (i=0; i<nproc*nproc; i++) BOOST_CHECK_EQUAL( ((double*)(&vec_tmprcvchr[0]))[i], vec_rcvdat[i] );
225 }
226 
228 
229 BOOST_AUTO_TEST_CASE( all_gather_ptr_variable )
230 {
231 
232  int i,j,k;
233 
234  setup_data_variable();
235 
236  delete[] ptr_tmprcv;
237  ptr_tmprcv=0;
238  ptr_tmprcv=PE::Comm::instance().all_gather(ptr_snddat, sndcnt, (double*)0, ptr_rcvcnt);
239  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] );
240 
241  for (i=0, k=0; i<nproc; i++) for (j=0; j<ptr_rcvcnt[i]; j++, k++) ptr_tmprcv[k]=0.;
242  PE::Comm::instance().all_gather(ptr_snddat, sndcnt, ptr_tmprcv, ptr_rcvcnt);
243  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] );
244 
245  delete[] ptr_tmprcv;
246  ptr_tmprcv=new double[nproc*nproc];
247  for (i=0, k=0; i<nproc; i++) for (j=0; j<ptr_rcvcnt[i]; j++, k++) ptr_tmprcv[k]=0.;
248  for (i=0; i<nproc; i++) ptr_tmprcv[i]=ptr_snddat[i];
249  PE::Comm::instance().all_gather(ptr_tmprcv, sndcnt, ptr_tmprcv, ptr_rcvcnt);
250  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] );
251 
252  delete[] ptr_tmprcv;
253  ptr_tmprcv=0;
254  for(i=0; i<nproc; i++) ptr_tmpcnt[i]=-1;
255  ptr_tmprcv=PE::Comm::instance().all_gather(ptr_snddat, sndcnt, (double*)0, ptr_tmpcnt);
256  for (i=0; i<nproc; i++) BOOST_CHECK_EQUAL( ptr_tmpcnt[i] , ptr_rcvcnt[i] );
257  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] );
258 
259  for (i=0, k=0; i<nproc; i++) for (j=0; j<ptr_rcvcnt[i]; j++, k++) ptr_tmprcv[k]=0.;
260  for(i=0; i<nproc; i++) ptr_tmpcnt[i]=-1;
261  PE::Comm::instance().all_gather(ptr_snddat, sndcnt, ptr_tmprcv, ptr_tmpcnt);
262  for (i=0; i<nproc; i++) BOOST_CHECK_EQUAL( ptr_tmpcnt[i] , ptr_rcvcnt[i] );
263  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] );
264 
265  delete[] ptr_tmprcv;
266  ptr_tmprcv=new double[nproc*nproc];
267  for (i=0, k=0; i<nproc; i++) for (j=0; j<ptr_rcvcnt[i]; j++, k++) ptr_tmprcv[k]=0.;
268  for (i=0; i<nproc; i++) ptr_tmprcv[i]=ptr_snddat[i];
269  for(i=0; i<nproc; i++) ptr_tmpcnt[i]=-1;
270  PE::Comm::instance().all_gather(ptr_tmprcv, sndcnt, ptr_tmprcv, ptr_tmpcnt);
271  for (i=0; i<nproc; i++) BOOST_CHECK_EQUAL( ptr_tmpcnt[i] , ptr_rcvcnt[i] );
272  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] );
273 
274  delete[] ptr_tmprcv;
275  ptr_tmprcv=0;
276  ptr_tmprcv=PE::Comm::instance().all_gather(ptr_snddat, sndcnt, ptr_sndmap, (double*)0, ptr_rcvcnt, ptr_rcvmap);
277  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
278 
279  for (i=0, k=0; i<nproc; i++) for (j=0; j<ptr_rcvcnt[i]; j++, k++) ptr_tmprcv[i*nproc+j]=0.;
280  PE::Comm::instance().all_gather(ptr_snddat, sndcnt, ptr_sndmap, ptr_tmprcv, ptr_rcvcnt, ptr_rcvmap);
281  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
282 
283  delete[] ptr_tmprcv;
284  ptr_tmprcv=new double[nproc*nproc];
285  for (i=0, k=0; i<nproc; i++) for (j=0; j<ptr_rcvcnt[i]; j++, k++) ptr_tmprcv[i*nproc+j]=0.;
286  for (i=0; i<nproc; i++) ptr_tmprcv[i]=ptr_snddat[i];
287  PE::Comm::instance().all_gather(ptr_tmprcv, sndcnt, ptr_sndmap, ptr_tmprcv, ptr_rcvcnt, ptr_rcvmap);
288  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
289 
290  delete[] ptr_tmprcv;
291  ptr_tmprcv=0;
292  ptr_tmprcv=(double*)PE::Comm::instance().all_gather((char*)ptr_snddat, sndcnt, (char*)0, ptr_rcvcnt, sizeof(double));
293  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] );
294 
295  for (i=0, k=0; i<nproc; i++) for (j=0; j<ptr_rcvcnt[i]; j++, k++) ptr_tmprcv[k]=0.;
296  PE::Comm::instance().all_gather((char*)ptr_snddat, sndcnt, (char*)ptr_tmprcv, ptr_rcvcnt, sizeof(double));
297  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] );
298 
299  delete[] ptr_tmprcv;
300  ptr_tmprcv=new double[nproc*nproc];
301  for (i=0, k=0; i<nproc; i++) for (j=0; j<ptr_rcvcnt[i]; j++, k++) ptr_tmprcv[k]=0.;
302  for (i=0; i<nproc; i++) ptr_tmprcv[i]=ptr_snddat[i];
303  PE::Comm::instance().all_gather((char*)ptr_tmprcv, sndcnt, (char*)ptr_tmprcv, ptr_rcvcnt, sizeof(double));
304  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] );
305 
306  delete[] ptr_tmprcv;
307  ptr_tmprcv=0;
308  for(i=0; i<nproc; i++) ptr_tmpcnt[i]=-1;
309  ptr_tmprcv=(double*)PE::Comm::instance().all_gather((char*)ptr_snddat, sndcnt, (char*)0, ptr_tmpcnt, sizeof(double));
310  for (i=0; i<nproc; i++) BOOST_CHECK_EQUAL( ptr_tmpcnt[i] , ptr_rcvcnt[i] );
311  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] );
312 
313  for (i=0, k=0; i<nproc; i++) for (j=0; j<ptr_rcvcnt[i]; j++, k++) ptr_tmprcv[k]=0.;
314  for(i=0; i<nproc; i++) ptr_tmpcnt[i]=-1;
315  PE::Comm::instance().all_gather((char*)ptr_snddat, sndcnt, (char*)ptr_tmprcv, ptr_tmpcnt, sizeof(double));
316  for (i=0; i<nproc; i++) BOOST_CHECK_EQUAL( ptr_tmpcnt[i] , ptr_rcvcnt[i] );
317  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] );
318 
319  delete[] ptr_tmprcv;
320  ptr_tmprcv=new double[nproc*nproc];
321  for (i=0, k=0; i<nproc; i++) for (j=0; j<ptr_rcvcnt[i]; j++, k++) ptr_tmprcv[k]=0.;
322  for (i=0; i<nproc; i++) ptr_tmprcv[i]=ptr_snddat[i];
323  for(i=0; i<nproc; i++) ptr_tmpcnt[i]=-1;
324  PE::Comm::instance().all_gather((char*)ptr_tmprcv, sndcnt, (char*)ptr_tmprcv, ptr_tmpcnt, sizeof(double));
325  for (i=0; i<nproc; i++) BOOST_CHECK_EQUAL( ptr_tmpcnt[i] , ptr_rcvcnt[i] );
326  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] );
327 
328  delete[] ptr_tmprcv;
329  ptr_tmprcv=0;
330  ptr_tmprcv=(double*)PE::Comm::instance().all_gather((char*)ptr_snddat, sndcnt, ptr_sndmap, (char*)0, ptr_rcvcnt, ptr_rcvmap, sizeof(double));
331  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
332 
333  for (i=0, k=0; i<nproc; i++) for (j=0; j<ptr_rcvcnt[i]; j++, k++) ptr_tmprcv[i*nproc+j]=0.;
334  PE::Comm::instance().all_gather((char*)ptr_snddat, sndcnt, ptr_sndmap, (char*)ptr_tmprcv, ptr_rcvcnt, ptr_rcvmap, sizeof(double));
335  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
336 
337  delete[] ptr_tmprcv;
338  ptr_tmprcv=new double[nproc*nproc];
339  for (i=0, k=0; i<nproc; i++) for (j=0; j<ptr_rcvcnt[i]; j++, k++) ptr_tmprcv[i*nproc+j]=0.;
340  for (i=0; i<nproc; i++) ptr_tmprcv[i]=ptr_snddat[i];
341  PE::Comm::instance().all_gather((char*)ptr_tmprcv, sndcnt, ptr_sndmap, (char*)ptr_tmprcv, ptr_rcvcnt, ptr_rcvmap, sizeof(double));
342  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
343 }
344 
346 
347 BOOST_AUTO_TEST_CASE( all_gather_vector_variable )
348 {
349  int i,j,k;
350 
351  setup_data_variable();
352 
353  vec_tmprcv.resize(0);
354  vec_tmprcv.reserve(0);
355  PE::Comm::instance().all_gather(vec_snddat, sndcnt, vec_tmprcv, vec_rcvcnt);
356  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] );
357 
358  for (i=0, k=0; i<nproc; i++) for (j=0; j<vec_rcvcnt[i]; j++, k++) vec_tmprcv[k]=0.;
359  PE::Comm::instance().all_gather(vec_snddat, sndcnt, vec_tmprcv, vec_rcvcnt);
360  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] );
361 
362  vec_tmprcv.resize(nproc*nproc);
363  vec_tmprcv.reserve(nproc*nproc);
364  for (i=0, k=0; i<nproc; i++) for (j=0; j<vec_rcvcnt[i]; j++, k++) vec_tmprcv[k]=0.;
365  for (i=0; i<nproc; i++) vec_tmprcv[i]=vec_snddat[i];
366  PE::Comm::instance().all_gather(vec_tmprcv, sndcnt, vec_tmprcv, vec_rcvcnt);
367  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] );
368 
369  vec_tmprcv.resize(0);
370  vec_tmprcv.reserve(0);
371  for(i=0; i<nproc; i++) vec_tmpcnt[i]=-1;
372  PE::Comm::instance().all_gather(vec_snddat, sndcnt, vec_tmprcv, vec_tmpcnt);
373  for (i=0; i<nproc; i++) BOOST_CHECK_EQUAL( vec_tmpcnt[i] , vec_rcvcnt[i] );
374  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] );
375 
376  for (i=0, k=0; i<nproc; i++) for (j=0; j<vec_rcvcnt[i]; j++, k++) vec_tmprcv[k]=0.;
377  for(i=0; i<nproc; i++) vec_tmpcnt[i]=-1;
378  PE::Comm::instance().all_gather(vec_snddat, sndcnt, vec_tmprcv, vec_tmpcnt);
379  for (i=0; i<nproc; i++) BOOST_CHECK_EQUAL( vec_tmpcnt[i] , vec_rcvcnt[i] );
380  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] );
381 
382  vec_tmprcv.resize(nproc*nproc);
383  vec_tmprcv.reserve(nproc*nproc);
384  for (i=0, k=0; i<nproc; i++) for (j=0; j<vec_rcvcnt[i]; j++, k++) vec_tmprcv[k]=0.;
385  for (i=0; i<nproc; i++) vec_tmprcv[i]=vec_snddat[i];
386  for(i=0; i<nproc; i++) vec_tmpcnt[i]=-1;
387  PE::Comm::instance().all_gather(vec_tmprcv, sndcnt, vec_tmprcv, vec_tmpcnt);
388  for (i=0; i<nproc; i++) BOOST_CHECK_EQUAL( vec_tmpcnt[i] , vec_rcvcnt[i] );
389  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] );
390 
391  vec_tmprcv.resize(0);
392  vec_tmprcv.reserve(0);
393  PE::Comm::instance().all_gather(vec_snddat, sndcnt, vec_sndmap, vec_tmprcv, vec_rcvcnt, vec_rcvmap);
394  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
395 
396  for (i=0, k=0; i<nproc; i++) for (j=0; j<vec_rcvcnt[i]; j++, k++) vec_tmprcv[i*nproc+j]=0.;
397  PE::Comm::instance().all_gather(vec_snddat, sndcnt, vec_sndmap, vec_tmprcv, vec_rcvcnt, vec_rcvmap);
398  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
399 
400  vec_tmprcv.resize(nproc*nproc);
401  vec_tmprcv.reserve(nproc*nproc);
402  for (i=0, k=0; i<nproc; i++) for (j=0; j<vec_rcvcnt[i]; j++, k++) vec_tmprcv[i*nproc+j]=0.;
403  for (i=0; i<nproc; i++) vec_tmprcv[i]=vec_snddat[i];
404  PE::Comm::instance().all_gather(vec_tmprcv, sndcnt, vec_sndmap, vec_tmprcv, vec_rcvcnt, vec_rcvmap);
405  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
406 
407  vec_tmprcvchr.resize(0);
408  vec_tmprcvchr.reserve(0);
409  PE::Comm::instance().all_gather(vec_snddatchr, sndcnt, vec_tmprcvchr, vec_rcvcnt, sizeof(double));
410  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] );
411 
412  for (i=0, k=0; i<nproc; i++) for (j=0; j<vec_rcvcnt[i]; j++, k++) ((double*)(&vec_tmprcvchr[0]))[k]=0.;
413  PE::Comm::instance().all_gather(vec_snddatchr, sndcnt, vec_tmprcvchr, vec_rcvcnt, sizeof(double));
414  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] );
415 
416  vec_tmprcvchr.resize(nproc*nproc*sizeof(double));
417  vec_tmprcvchr.reserve(nproc*nproc*sizeof(double));
418  for (i=0, k=0; i<nproc; i++) for (j=0; j<vec_rcvcnt[i]; j++, k++) ((double*)(&vec_tmprcvchr[0]))[k]=0.;
419  for (i=0; i<nproc; i++) ((double*)(&vec_tmprcvchr[0]))[i]=vec_snddat[i];
420  PE::Comm::instance().all_gather(vec_tmprcvchr, sndcnt, vec_tmprcvchr, vec_rcvcnt, sizeof(double));
421  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] );
422 
423  vec_tmprcvchr.resize(0);
424  vec_tmprcvchr.reserve(0);
425  for(i=0; i<nproc; i++) vec_tmpcnt[i]=-1;
426  PE::Comm::instance().all_gather(vec_snddatchr, sndcnt, vec_tmprcvchr, vec_tmpcnt, sizeof(double));
427  for (i=0; i<nproc; i++) BOOST_CHECK_EQUAL( vec_tmpcnt[i] , vec_rcvcnt[i] );
428  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] );
429 
430  for (i=0, k=0; i<nproc; i++) for (j=0; j<vec_rcvcnt[i]; j++, k++) ((double*)(&vec_tmprcvchr[0]))[k]=0.;
431  for(i=0; i<nproc; i++) vec_tmpcnt[i]=-1;
432  PE::Comm::instance().all_gather(vec_snddatchr, sndcnt, vec_tmprcvchr, vec_tmpcnt, sizeof(double));
433  for (i=0; i<nproc; i++) BOOST_CHECK_EQUAL( vec_tmpcnt[i] , vec_rcvcnt[i] );
434  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] );
435 
436  vec_tmprcvchr.resize(nproc*nproc*sizeof(double));
437  vec_tmprcvchr.reserve(nproc*nproc*sizeof(double));
438  for (i=0, k=0; i<nproc; i++) for (j=0; j<vec_rcvcnt[i]; j++, k++) ((double*)(&vec_tmprcvchr[0]))[k]=0.;
439  for (i=0; i<nproc; i++) ((double*)(&vec_tmprcvchr[0]))[i]=vec_snddat[i];
440  for(i=0; i<nproc; i++) vec_tmpcnt[i]=-1;
441  PE::Comm::instance().all_gather(vec_tmprcvchr, sndcnt, vec_tmprcvchr, vec_tmpcnt, sizeof(double));
442  for (i=0; i<nproc; i++) BOOST_CHECK_EQUAL( vec_tmpcnt[i] , vec_rcvcnt[i] );
443  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 
445  vec_tmprcvchr.resize(0);
446  vec_tmprcvchr.reserve(0);
447  PE::Comm::instance().all_gather(vec_snddatchr, sndcnt, vec_sndmap, vec_tmprcvchr, vec_rcvcnt, vec_rcvmap, sizeof(double));
448  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
449 
450  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.;
451  PE::Comm::instance().all_gather(vec_snddatchr, sndcnt, vec_sndmap, vec_tmprcvchr, vec_rcvcnt, vec_rcvmap, sizeof(double));
452  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
453 
454  vec_tmprcvchr.resize(nproc*nproc*sizeof(double));
455  vec_tmprcvchr.reserve(nproc*nproc*sizeof(double));
456  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.;
457  for (i=0; i<nproc; i++) ((double*)(&vec_tmprcvchr[0]))[i]=vec_snddat[i];
458  PE::Comm::instance().all_gather(vec_tmprcvchr, sndcnt, vec_sndmap, vec_tmprcvchr, vec_rcvcnt, vec_rcvmap, sizeof(double));
459  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
460 }
461 
463 
464 BOOST_AUTO_TEST_SUITE_END()
465 
466 
#define CFinfo
these are always defined
Definition: Log.hpp:104
void setup_data_variable()
helper function for variable size data - setting up input and verification data
#define CFendl
Definition: Log.hpp:109
void setup_data_constant()
helper function for constant size data - setting up input and verification data
~PEAllGatherFixture()
common tear-down for each test case
T * all_gather(const Communicator &comm, const T *in_values, const int in_n, T *out_values, const int stride=1)
Definition: all_gather.hpp:185
BOOST_AUTO_TEST_CASE(all_gather)
PEAllGatherFixture()
common setup for each test case
std::vector< int > vec_rcvcnt
data for std::vectors
#define PEProcessSortedExecute(irank, expression)
Definition: debug.hpp:43
Send comments to:
COOLFluiD Web Admin