COOLFluiD  Release kernel
COOLFluiD is a Collaborative Simulation Environment (CSE) focused on complex MultiPhysics simulations.
utest-parallel-collective-all_to_all.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  // rank and proc
18  nproc=PE::Comm::instance().size();
19  irank=PE::Comm::instance().rank();
20 
21  // ptr helpers
22  sndcnt=0;
23  rcvcnt=0;
24  ptr_sndcnt=new int[nproc];
25  ptr_rcvcnt=new int[nproc];
26  ptr_snddat=new double[nproc*nproc];
27  ptr_rcvdat=new double[nproc*nproc];
28  ptr_sndmap=new int[nproc*nproc];
29  ptr_rcvmap=new int[nproc*nproc];
30  ptr_tmprcv=new double[nproc*nproc];
31  ptr_tmpcnt=new int[nproc];
32 
33  // std::Vector helpers
34  vec_sndcnt.resize(nproc);
35  vec_rcvcnt.resize(nproc);
36  vec_snddat.resize(nproc*nproc);
37  vec_rcvdat.resize(nproc*nproc);
38  vec_sndmap.resize(nproc*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*nproc*sizeof(double));
44  }
45 
48  {
49  delete[] ptr_sndcnt;
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_sndcnt;
68  int* ptr_rcvcnt;
69  double* ptr_snddat;
70  double* ptr_rcvdat;
71  int* ptr_sndmap;
72  int* ptr_rcvmap;
73  double* ptr_tmprcv;
74  int* ptr_tmpcnt;
75 
77  std::vector<int> vec_sndcnt;
78  std::vector<int> vec_rcvcnt;
79  std::vector<double> vec_snddat;
80  std::vector<double> vec_rcvdat;
81  std::vector<int> vec_sndmap;
82  std::vector<int> vec_rcvmap;
83  std::vector<double> vec_tmprcv;
84  std::vector<int> vec_tmpcnt;
85  std::vector<char> vec_tmprcvchr;
86  std::vector<char> vec_snddatchr;
87 
90  {
91  int i,j;
92  for (i=0; i<nproc; i++)
93  for (j=0; j<nproc; j++){
94  ptr_snddat[i*nproc+j]=(irank+1)*1000000+(i+1)*10000+(j+1);
95  ptr_rcvdat[i*nproc+j]=(i+1)*1000000+(irank+1)*10000+(j+1);
96  }
97  sndcnt=nproc*nproc;
98  rcvcnt=nproc*nproc;
99  vec_snddat.assign(ptr_snddat,ptr_snddat+nproc*nproc);
100  vec_rcvdat.assign(ptr_rcvdat,ptr_rcvdat+nproc*nproc);
101  vec_snddatchr.assign((char*)(ptr_snddat),(char*)(ptr_snddat+nproc*nproc));
102  }
103 
106  {
107  int i,j,k,l;
108  for (i=0; i<nproc; i++){
109  ptr_sndcnt[i]=(i+irank*irank)%nproc;
110  ptr_rcvcnt[i]=(i*i+irank)%nproc;
111  }
112  for(i=0; i<nproc*nproc; i++) { // making debugger shut up for uninitialized values
113  ptr_snddat[i]=0.;
114  ptr_rcvdat[i]=0.;
115  ptr_sndmap[i]=0;
116  ptr_rcvmap[i]=0;
117  }
118  for(i=0, k=0; i<nproc; i++)
119  for(j=0; j<ptr_sndcnt[i]; j++, k++)
120  ptr_snddat[k]=(irank+1)*1000000+(i+1)*10000+(j+1);
121  for(i=0, k=0; i<nproc; i++)
122  for(j=0; j<ptr_rcvcnt[i]; j++, k++)
123  ptr_rcvdat[k]=(i+1)*1000000+(irank+1)*10000+(j+1);
124  for (i=0, k=0,l=0; i<nproc; k+=ptr_sndcnt[i], i++)
125  for (j=0; j<ptr_sndcnt[i]; j++,l++)
126  ptr_sndmap[l]=k+ptr_sndcnt[i]-1-j; // flipping all sets for each process
127  for (i=0, k=0, l=0; i<nproc; k+=ptr_rcvcnt[i], i++)
128  for (j=0; j<ptr_rcvcnt[i]; j++, l++)
129  ptr_rcvmap[l]=i*nproc+ptr_rcvcnt[i]-1-j; // redirecting to align start with nproc numbers
130  for(i=0, sndcnt=0, rcvcnt=0; i<nproc; i++){
131  sndcnt+=ptr_sndcnt[i];
132  rcvcnt+=ptr_rcvcnt[i];
133  }
134  vec_sndcnt.assign(ptr_sndcnt,ptr_sndcnt+nproc);
135  vec_rcvcnt.assign(ptr_rcvcnt,ptr_rcvcnt+nproc);
136  vec_snddat.assign(ptr_snddat,ptr_snddat+nproc*nproc);
137  vec_rcvdat.assign(ptr_rcvdat,ptr_rcvdat+nproc*nproc);
138  vec_sndmap.assign(ptr_sndmap,ptr_sndmap+nproc*nproc);
139  vec_rcvmap.assign(ptr_rcvmap,ptr_rcvmap+nproc*nproc);
140  vec_snddatchr.assign((char*)(ptr_snddat),(char*)(ptr_snddat+nproc*nproc));
141  }
142 
143 };
144 
146 
147 BOOST_FIXTURE_TEST_SUITE( PEAllToAllSuite, PEAllToAllFixture )
148 
149 
152 {
153  PEProcessSortedExecute(-1,CFinfo << "Testing all_to_all " << irank << "/" << nproc << CFendl; );
154 }
155 
157 
158 BOOST_AUTO_TEST_CASE( all_to_all_ptr_constant )
159 {
160  int i;
161 
162  setup_data_constant();
163 
164  delete[] ptr_tmprcv;
165  ptr_tmprcv=0;
166 
167  ptr_tmprcv=PE::Comm::instance().all_to_all(ptr_snddat, nproc, (double*)0);
168  for (i=0; i<nproc*nproc; i++) BOOST_CHECK_EQUAL( ptr_tmprcv[i] , ptr_rcvdat[i] );
169 
170  for (i=0; i<nproc*nproc; i++) ptr_tmprcv[i]=0.;
171  PE::Comm::instance().all_to_all(ptr_snddat, nproc, ptr_tmprcv);
172  for (i=0; i<nproc*nproc; i++) BOOST_CHECK_EQUAL( ptr_tmprcv[i] , ptr_rcvdat[i] );
173 
174  for (i=0; i<nproc*nproc; i++) ptr_tmprcv[i]=ptr_snddat[i];
175  PE::Comm::instance().all_to_all(ptr_tmprcv, nproc, ptr_tmprcv);
176  for (i=0; i<nproc*nproc; i++) BOOST_CHECK_EQUAL( ptr_tmprcv[i] , ptr_rcvdat[i] );
177 
178  delete[] ptr_tmprcv;
179  ptr_tmprcv=0;
180  ptr_tmprcv=(double*)PE::Comm::instance().all_to_all((char*)ptr_snddat, nproc, (char*)0, sizeof(double));
181  for (i=0; i<nproc*nproc; i++) BOOST_CHECK_EQUAL( ptr_tmprcv[i] , ptr_rcvdat[i] );
182 
183  for (i=0; i<nproc*nproc; i++) ptr_tmprcv[i]=0.;
184  PE::Comm::instance().all_to_all((char*)ptr_snddat, nproc, (char*)ptr_tmprcv, sizeof(double));
185  for (i=0; i<nproc*nproc; i++) BOOST_CHECK_EQUAL( ptr_tmprcv[i] , ptr_rcvdat[i] );
186 
187  for (i=0; i<nproc*nproc; i++) ptr_tmprcv[i]=ptr_snddat[i];
188  PE::Comm::instance().all_to_all((char*)ptr_tmprcv, nproc, (char*)ptr_tmprcv, sizeof(double));
189  for (i=0; i<nproc*nproc; i++) BOOST_CHECK_EQUAL( ptr_tmprcv[i] , ptr_rcvdat[i] );
190 }
191 
193 
194 BOOST_AUTO_TEST_CASE( all_to_all_vector_constant )
195 {
196  int i;
197 
198  setup_data_constant();
199 
200  vec_tmprcv.resize(0);
201  vec_tmprcv.reserve(0);
202  PE::Comm::instance().all_to_all(vec_snddat, vec_tmprcv);
203  for (i=0; i<nproc*nproc; i++) BOOST_CHECK_EQUAL( vec_tmprcv[i] , vec_rcvdat[i] );
204  BOOST_CHECK_EQUAL( (int)vec_tmprcv.size() , rcvcnt );
205 
206  vec_tmprcv.assign(nproc*nproc,0.);
207  PE::Comm::instance().all_to_all(vec_snddat, vec_tmprcv);
208  for (i=0; i<nproc*nproc; i++) BOOST_CHECK_EQUAL( vec_tmprcv[i] , vec_rcvdat[i] );
209 
210  vec_tmprcv=vec_snddat;
211  PE::Comm::instance().all_to_all(vec_tmprcv, vec_tmprcv);
212  for (i=0; i<nproc*nproc; i++) BOOST_CHECK_EQUAL( vec_tmprcv[i] , vec_rcvdat[i] );
213 
214  vec_tmprcvchr.resize(0);
215  vec_tmprcvchr.reserve(0);
216  PE::Comm::instance().all_to_all(vec_snddatchr, vec_tmprcvchr );
217  BOOST_CHECK_EQUAL( vec_tmprcvchr.size() , sizeof(double)*rcvcnt );
218  for (i=0; i<nproc*nproc; i++) BOOST_CHECK_EQUAL( ((double*)(&vec_tmprcvchr[0]))[i], vec_rcvdat[i] );
219 
220  for (i=0; i<nproc*nproc; i++) ((double*)(&vec_tmprcvchr[0]))[i]=0.;
221  PE::Comm::instance().all_to_all(vec_snddatchr, vec_tmprcvchr );
222  for (i=0; i<nproc*nproc; i++) BOOST_CHECK_EQUAL( ((double*)(&vec_tmprcvchr[0]))[i], vec_rcvdat[i] );
223 
224  vec_tmprcvchr.assign((char*)(ptr_snddat),(char*)(ptr_snddat+nproc*nproc));
225  PE::Comm::instance().all_to_all(vec_tmprcvchr, vec_tmprcvchr );
226  for (i=0; i<nproc*nproc; i++) BOOST_CHECK_EQUAL( ((double*)(&vec_tmprcvchr[0]))[i], vec_rcvdat[i] );
227 }
228 
230 
231 BOOST_AUTO_TEST_CASE( all_to_all_ptr_variable )
232 {
233  int i,j,k;
234 
235  setup_data_variable();
236 
237  delete[] ptr_tmprcv;
238  ptr_tmprcv=0;
239  ptr_tmprcv=PE::Comm::instance().all_to_all(ptr_snddat, ptr_sndcnt, (double*)0, ptr_rcvcnt);
240  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] );
241 
242  for (i=0, k=0; i<nproc; i++) for (j=0; j<ptr_rcvcnt[i]; j++, k++) ptr_tmprcv[k]=0.;
243  PE::Comm::instance().all_to_all(ptr_snddat, ptr_sndcnt, ptr_tmprcv, ptr_rcvcnt);
244  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] );
245 
246  delete[] ptr_tmprcv;
247  ptr_tmprcv=new double[nproc*nproc];
248  for (i=0; i<nproc*nproc; i++) ptr_tmprcv[i]=ptr_snddat[i];
249  PE::Comm::instance().all_to_all(ptr_tmprcv, ptr_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_to_all(ptr_snddat, ptr_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_to_all(ptr_snddat, ptr_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; i<nproc*nproc; i++) ptr_tmprcv[i]=ptr_snddat[i];
268  for(i=0; i<nproc; i++) ptr_tmpcnt[i]=-1;
269  PE::Comm::instance().all_to_all(ptr_tmprcv, ptr_sndcnt, ptr_tmprcv, ptr_tmpcnt);
270  for (i=0; i<nproc; i++) BOOST_CHECK_EQUAL( ptr_tmpcnt[i] , ptr_rcvcnt[i] );
271  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  ptr_tmprcv=PE::Comm::instance().all_to_all(ptr_snddat, ptr_sndcnt, ptr_sndmap, (double*)0, ptr_rcvcnt, ptr_rcvmap);
276  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
277 
278  for (i=0, k=0; i<nproc; i++) for (j=0; j<ptr_rcvcnt[i]; j++, k++) ptr_tmprcv[i*nproc+j]=0.;
279  PE::Comm::instance().all_to_all(ptr_snddat, ptr_sndcnt, ptr_sndmap, ptr_tmprcv, ptr_rcvcnt, ptr_rcvmap);
280  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
281 
282  delete[] ptr_tmprcv;
283  ptr_tmprcv=new double[nproc*nproc];
284  for (i=0; i<nproc*nproc; i++) ptr_tmprcv[i]=ptr_snddat[i];
285  PE::Comm::instance().all_to_all(ptr_tmprcv, ptr_sndcnt, ptr_sndmap, ptr_tmprcv, ptr_rcvcnt, ptr_rcvmap);
286  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
287 
288  delete[] ptr_tmprcv;
289  ptr_tmprcv=0;
290  ptr_tmprcv=(double*)PE::Comm::instance().all_to_all((char*)ptr_snddat, ptr_sndcnt, (char*)0, ptr_rcvcnt, sizeof(double));
291  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] );
292 
293  for (i=0, k=0; i<nproc; i++) for (j=0; j<ptr_rcvcnt[i]; j++, k++) ptr_tmprcv[k]=0.;
294  PE::Comm::instance().all_to_all((char*)ptr_snddat, ptr_sndcnt, (char*)ptr_tmprcv, ptr_rcvcnt, sizeof(double));
295  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] );
296 
297  delete[] ptr_tmprcv;
298  ptr_tmprcv=new double[nproc*nproc];
299  for (i=0; i<nproc*nproc; i++) ptr_tmprcv[i]=ptr_snddat[i];
300  PE::Comm::instance().all_to_all((char*)ptr_tmprcv, ptr_sndcnt, (char*)ptr_tmprcv, ptr_rcvcnt, sizeof(double));
301  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] );
302 
303  delete[] ptr_tmprcv;
304  ptr_tmprcv=0;
305  for(i=0; i<nproc; i++) ptr_tmpcnt[i]=-1;
306  ptr_tmprcv=(double*)PE::Comm::instance().all_to_all((char*)ptr_snddat, ptr_sndcnt, (char*)0, ptr_tmpcnt, sizeof(double));
307  for (i=0; i<nproc; i++) BOOST_CHECK_EQUAL( ptr_tmpcnt[i] , ptr_rcvcnt[i] );
308  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] );
309 
310  for (i=0, k=0; i<nproc; i++) for (j=0; j<ptr_rcvcnt[i]; j++, k++) ptr_tmprcv[k]=0.;
311  for(i=0; i<nproc; i++) ptr_tmpcnt[i]=-1;
312  PE::Comm::instance().all_to_all((char*)ptr_snddat, ptr_sndcnt, (char*)ptr_tmprcv, ptr_tmpcnt, sizeof(double));
313  for (i=0; i<nproc; i++) BOOST_CHECK_EQUAL( ptr_tmpcnt[i] , ptr_rcvcnt[i] );
314  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] );
315 
316  delete[] ptr_tmprcv;
317  ptr_tmprcv=new double[nproc*nproc];
318  for (i=0; i<nproc*nproc; i++) ptr_tmprcv[i]=ptr_snddat[i];
319  for(i=0; i<nproc; i++) ptr_tmpcnt[i]=-1;
320  PE::Comm::instance().all_to_all((char*)ptr_tmprcv, ptr_sndcnt, (char*)ptr_tmprcv, ptr_tmpcnt, sizeof(double));
321  for (i=0; i<nproc; i++) BOOST_CHECK_EQUAL( ptr_tmpcnt[i] , ptr_rcvcnt[i] );
322  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] );
323 
324  delete[] ptr_tmprcv;
325  ptr_tmprcv=0;
326  ptr_tmprcv=(double*)PE::Comm::instance().all_to_all((char*)ptr_snddat, ptr_sndcnt, ptr_sndmap, (char*)0, ptr_rcvcnt, ptr_rcvmap, sizeof(double));
327  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
328 
329  for (i=0, k=0; i<nproc; i++) for (j=0; j<ptr_rcvcnt[i]; j++, k++) ptr_tmprcv[i*nproc+j]=0.;
330  PE::Comm::instance().all_to_all((char*)ptr_snddat, ptr_sndcnt, ptr_sndmap, (char*)ptr_tmprcv, 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  delete[] ptr_tmprcv;
334  ptr_tmprcv=new double[nproc*nproc];
335  for (i=0; i<nproc*nproc; i++) ptr_tmprcv[i]=ptr_snddat[i];
336  PE::Comm::instance().all_to_all((char*)ptr_tmprcv, ptr_sndcnt, ptr_sndmap, (char*)ptr_tmprcv, ptr_rcvcnt, ptr_rcvmap, sizeof(double));
337  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
338 }
339 
341 
342 BOOST_AUTO_TEST_CASE( all_to_all_vector_variable )
343 {
344  int i,j,k;
345 
346  setup_data_variable();
347 
348  vec_tmprcv.resize(0);
349  vec_tmprcv.reserve(0);
350  PE::Comm::instance().all_to_all(vec_snddat, vec_sndcnt, vec_tmprcv, vec_rcvcnt);
351  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] );
352 
353  for (i=0, k=0; i<nproc; i++) for (j=0; j<vec_rcvcnt[i]; j++, k++) vec_tmprcv[k]=0.;
354  PE::Comm::instance().all_to_all(vec_snddat, vec_sndcnt, vec_tmprcv, vec_rcvcnt);
355  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] );
356 
357  vec_tmprcv.resize(nproc*nproc);
358  vec_tmprcv.reserve(nproc*nproc);
359  for (i=0; i<nproc*nproc; i++) vec_tmprcv[i]=vec_snddat[i];
360  PE::Comm::instance().all_to_all(vec_tmprcv, vec_sndcnt, vec_tmprcv, vec_rcvcnt);
361  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] );
362 
363  vec_tmprcv.resize(0);
364  vec_tmprcv.reserve(0);
365  for(i=0; i<nproc; i++) vec_tmpcnt[i]=-1;
366  PE::Comm::instance().all_to_all(vec_snddat, vec_sndcnt, vec_tmprcv, vec_tmpcnt);
367  for (i=0; i<nproc; i++) BOOST_CHECK_EQUAL( vec_tmpcnt[i] , vec_rcvcnt[i] );
368  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] );
369 
370  for (i=0, k=0; i<nproc; i++) for (j=0; j<vec_rcvcnt[i]; j++, k++) vec_tmprcv[k]=0.;
371  for(i=0; i<nproc; i++) vec_tmpcnt[i]=-1;
372  PE::Comm::instance().all_to_all(vec_snddat, vec_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  vec_tmprcv.resize(nproc*nproc);
377  vec_tmprcv.reserve(nproc*nproc);
378  for (i=0; i<nproc*nproc; i++) vec_tmprcv[i]=vec_snddat[i];
379  for(i=0; i<nproc; i++) vec_tmpcnt[i]=-1;
380  PE::Comm::instance().all_to_all(vec_tmprcv, vec_sndcnt, vec_tmprcv, vec_tmpcnt);
381  for (i=0; i<nproc; i++) BOOST_CHECK_EQUAL( vec_tmpcnt[i] , vec_rcvcnt[i] );
382  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] );
383 
384  vec_tmprcv.resize(0);
385  vec_tmprcv.reserve(0);
386  PE::Comm::instance().all_to_all(vec_snddat, vec_sndcnt, vec_sndmap, vec_tmprcv, vec_rcvcnt, vec_rcvmap);
387  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
388 
389  for (i=0, k=0; i<nproc; i++) for (j=0; j<vec_rcvcnt[i]; j++, k++) vec_tmprcv[i*nproc+j]=0.;
390  PE::Comm::instance().all_to_all(vec_snddat, vec_sndcnt, vec_sndmap, vec_tmprcv, vec_rcvcnt, vec_rcvmap);
391  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
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  PE::Comm::instance().all_to_all(vec_tmprcv, vec_sndcnt, vec_sndmap, vec_tmprcv, vec_rcvcnt, vec_rcvmap);
397  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
398 
399  vec_tmprcvchr.resize(0);
400  vec_tmprcvchr.reserve(0);
401  PE::Comm::instance().all_to_all(vec_snddatchr, vec_sndcnt, vec_tmprcvchr, vec_rcvcnt, sizeof(double));
402  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] );
403 
404  for (i=0, k=0; i<nproc; i++) for (j=0; j<vec_rcvcnt[i]; j++, k++) ((double*)(&vec_tmprcvchr[0]))[k]=0.;
405  PE::Comm::instance().all_to_all(vec_snddatchr, vec_sndcnt, vec_tmprcvchr, vec_rcvcnt, sizeof(double));
406  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] );
407 
408  vec_tmprcvchr.resize(nproc*nproc*sizeof(double));
409  vec_tmprcvchr.reserve(nproc*nproc*sizeof(double));
410  for (i=0; i<nproc*nproc; i++) ((double*)(&vec_tmprcvchr[0]))[i]=vec_snddat[i];
411  PE::Comm::instance().all_to_all(vec_tmprcvchr, vec_sndcnt, vec_tmprcvchr, vec_rcvcnt, sizeof(double));
412  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] );
413 
414  vec_tmprcvchr.resize(0);
415  vec_tmprcvchr.reserve(0);
416  for(i=0; i<nproc; i++) vec_tmpcnt[i]=-1;
417  PE::Comm::instance().all_to_all(vec_snddatchr, vec_sndcnt, vec_tmprcvchr, vec_tmpcnt, sizeof(double));
418  for (i=0; i<nproc; i++) BOOST_CHECK_EQUAL( vec_tmpcnt[i] , vec_rcvcnt[i] );
419  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] );
420 
421  for (i=0, k=0; i<nproc; i++) for (j=0; j<vec_rcvcnt[i]; j++, k++) ((double*)(&vec_tmprcvchr[0]))[k]=0.;
422  for(i=0; i<nproc; i++) vec_tmpcnt[i]=-1;
423  PE::Comm::instance().all_to_all(vec_snddatchr, vec_sndcnt, vec_tmprcvchr, vec_tmpcnt, sizeof(double));
424  for (i=0; i<nproc; i++) BOOST_CHECK_EQUAL( vec_tmpcnt[i] , vec_rcvcnt[i] );
425  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] );
426 
427  vec_tmprcvchr.resize(nproc*nproc*sizeof(double));
428  vec_tmprcvchr.reserve(nproc*nproc*sizeof(double));
429  for (i=0; i<nproc*nproc; i++) ((double*)(&vec_tmprcvchr[0]))[i]=vec_snddat[i];
430  for(i=0; i<nproc; i++) vec_tmpcnt[i]=-1;
431  PE::Comm::instance().all_to_all(vec_tmprcvchr, vec_sndcnt, vec_tmprcvchr, vec_tmpcnt, sizeof(double));
432  for (i=0; i<nproc; i++) BOOST_CHECK_EQUAL( vec_tmpcnt[i] , vec_rcvcnt[i] );
433  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] );
434 
435  vec_tmprcvchr.resize(0);
436  vec_tmprcvchr.reserve(0);
437  PE::Comm::instance().all_to_all(vec_snddatchr, vec_sndcnt, vec_sndmap, vec_tmprcvchr, vec_rcvcnt, vec_rcvmap, sizeof(double));
438  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
439 
440  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.;
441  //for (i=0, k=0; i<nproc; i++) for (j=0; j<vec_rcvcnt[i]; j++, k++) vec_tmprcvchr[i*nproc+j]=0.;
442  PE::Comm::instance().all_to_all(vec_snddatchr, vec_sndcnt, vec_sndmap, vec_tmprcvchr, vec_rcvcnt, vec_rcvmap, sizeof(double));
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]))[i*nproc+j] , vec_rcvdat[k] ); // i*nproc+j is not a bug, check reason at init
444 
445  vec_tmprcvchr.resize(nproc*nproc*sizeof(double));
446  vec_tmprcvchr.reserve(nproc*nproc*sizeof(double));
447  for (i=0; i<nproc*nproc; i++) ((double*)(&vec_tmprcvchr[0]))[i]=vec_snddat[i];
448  PE::Comm::instance().all_to_all(vec_tmprcvchr, vec_sndcnt, vec_sndmap, vec_tmprcvchr, vec_rcvcnt, vec_rcvmap, sizeof(double));
449  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
450 
451 }
452 
454 
455 BOOST_AUTO_TEST_SUITE_END()
456 
457 
#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
T * all_to_all(const Communicator &comm, const T *in_values, const int in_n, T *out_values, const int stride=1)
Definition: all_to_all.hpp:192
void setup_data_constant()
helper function for constant size data - setting up input and verification data
std::vector< int > vec_sndcnt
data for std::vectors
PEAllToAllFixture()
common setup for each test case
BOOST_AUTO_TEST_CASE(all_to_all)
~PEAllToAllFixture()
common tear-down for each test case
#define PEProcessSortedExecute(irank, expression)
Definition: debug.hpp:43
Send comments to:
COOLFluiD Web Admin