20 nproc=PE::Comm::instance().size();
21 irank=PE::Comm::instance().rank();
79 for (i=0; i<
nproc; i++){
80 ptr_snddat[i]=(irank+1)*1000+(i+1);
81 for (j=0; j<
nproc; j++) ptr_rcvdat[i*nproc+j]=(i+1)*1000+(j+1);
85 vec_snddat.assign(ptr_snddat,ptr_snddat+nproc);
86 vec_rcvdat.assign(ptr_rcvdat,ptr_rcvdat+nproc*nproc);
87 vec_snddatchr.assign((
char*)(ptr_snddat),(
char*)(ptr_snddat+nproc));
96 for(i=0; i<
nproc; i++) {
101 for(i=0; i<
nproc; i++)
for(j=0; j<
nproc; j++) ptr_rcvdat[i*nproc+j]=0;
102 for (i=0; i<
nproc; i++){
103 ptr_snddat[i]=(irank+1)*1000+(i+1);
104 for (j=0; j<
nproc; j++) ptr_rcvdat[i*nproc+j]=(i+1)*1000+(2*(rcvcnt-j)-1);
109 ptr_rcvmap[i]=rcvcnt-1-i;
110 vec_snddat.assign(ptr_snddat,ptr_snddat+nproc);
111 vec_rcvdat.assign(ptr_rcvdat,ptr_rcvdat+nproc*nproc);
112 vec_snddatchr.assign((
char*)(ptr_snddat),(
char*)(ptr_snddat+nproc));
113 vec_sndmap.assign(ptr_sndmap,ptr_sndmap+sndcnt);
114 vec_rcvmap.assign(ptr_rcvmap,ptr_rcvmap+rcvcnt);
136 setup_data_constant();
138 for (r=0; r<nproc; r++) {
143 ptr_tmprcv=PE::Comm::instance().broadcast(ptr_snddat, nproc, (
double*)0, r);
144 for (i=0; i<nproc; i++) BOOST_CHECK_EQUAL( ptr_tmprcv[i] , ptr_rcvdat[r*nproc+i] );
146 for (i=0; i<nproc; i++) ptr_tmprcv[i]=0.;
147 PE::Comm::instance().broadcast(ptr_snddat, nproc, ptr_tmprcv, r);
148 for (i=0; i<nproc; i++) BOOST_CHECK_EQUAL( ptr_tmprcv[i] , ptr_rcvdat[r*nproc+i] );
150 for (i=0; i<nproc; i++) ptr_tmprcv[i]=ptr_snddat[i];
151 PE::Comm::instance().broadcast(ptr_tmprcv, nproc, ptr_tmprcv, r);
152 for (i=0; i<nproc; i++) BOOST_CHECK_EQUAL( ptr_tmprcv[i] , ptr_rcvdat[r*nproc+i] );
157 ptr_tmprcv=(
double*)PE::Comm::instance().broadcast((
char*)ptr_snddat, nproc, (
char*)0, r,
sizeof(
double));
158 for (i=0; i<nproc; i++) BOOST_CHECK_EQUAL( ptr_tmprcv[i] , ptr_rcvdat[r*nproc+i] );
160 for (i=0; i<nproc; i++) ptr_tmprcv[i]=0.;
161 PE::Comm::instance().broadcast((
char*)ptr_snddat, nproc, (
char*)ptr_tmprcv, r,
sizeof(
double));
162 for (i=0; i<nproc; i++) BOOST_CHECK_EQUAL( ptr_tmprcv[i] , ptr_rcvdat[r*nproc+i] );
164 for (i=0; i<nproc; i++) ptr_tmprcv[i]=ptr_snddat[i];
165 PE::Comm::instance().broadcast((
char*)ptr_tmprcv, nproc, (
char*)ptr_tmprcv, r,
sizeof(
double));
166 for (i=0; i<nproc; i++) BOOST_CHECK_EQUAL( ptr_tmprcv[i] , ptr_rcvdat[r*nproc+i] );
176 setup_data_constant();
178 for (r=0; r<nproc; r++) {
180 vec_tmprcv.resize(0);
181 vec_tmprcv.reserve(0);
182 PE::Comm::instance().broadcast(vec_snddat, vec_tmprcv, r);
183 for (i=0; i<nproc; i++) BOOST_CHECK_EQUAL( vec_tmprcv[i] , vec_rcvdat[r*nproc+i] );
184 BOOST_CHECK_EQUAL( (
int)vec_tmprcv.size() , rcvcnt );
186 vec_tmprcv.assign(nproc,0.);
187 PE::Comm::instance().broadcast(vec_snddat, vec_tmprcv, r);
188 for (i=0; i<nproc; i++) BOOST_CHECK_EQUAL( vec_tmprcv[i] , vec_rcvdat[r*nproc+i] );
190 vec_tmprcv=vec_snddat;
191 PE::Comm::instance().broadcast(vec_tmprcv, vec_tmprcv, r);
192 for (i=0; i<nproc; i++) BOOST_CHECK_EQUAL( vec_tmprcv[i] , vec_rcvdat[r*nproc+i] );
194 vec_tmprcvchr.resize(0);
195 vec_tmprcvchr.reserve(0);
196 PE::Comm::instance().broadcast(vec_snddatchr, vec_tmprcvchr, r );
197 BOOST_CHECK_EQUAL( vec_tmprcvchr.size() ,
sizeof(double)*rcvcnt );
198 for (i=0; i<nproc; i++) BOOST_CHECK_EQUAL( ((
double*)(&vec_tmprcvchr[0]))[i], vec_rcvdat[r*nproc+i] );
200 for (i=0; i<nproc; i++) ((
double*)(&vec_tmprcvchr[0]))[i]=0.;
201 PE::Comm::instance().broadcast(vec_snddatchr, vec_tmprcvchr, r );
202 for (i=0; i<nproc; i++) BOOST_CHECK_EQUAL( ((
double*)(&vec_tmprcvchr[0]))[i], vec_rcvdat[r*nproc+i] );
204 vec_tmprcvchr.assign((
char*)(ptr_snddat),(
char*)(ptr_snddat+nproc));
205 PE::Comm::instance().broadcast(vec_tmprcvchr, vec_tmprcvchr, r );
206 for (i=0; i<nproc; i++) BOOST_CHECK_EQUAL( ((
double*)(&vec_tmprcvchr[0]))[i], vec_rcvdat[r*nproc+i] );
217 setup_data_variable();
219 for (r=0; r<nproc; r++) {
224 ptr_tmprcv=PE::Comm::instance().broadcast(ptr_snddat, sndcnt, ptr_sndmap, (
double*)0, ptr_rcvmap, r);
225 for (i=0; i<sndcnt; i++) BOOST_CHECK_EQUAL( ptr_tmprcv[i] , ptr_rcvdat[nproc*r+i] );
227 for (i=0; i<sndcnt; i++) ptr_tmprcv[i]=0.;
228 PE::Comm::instance().broadcast(ptr_snddat, sndcnt, ptr_sndmap, ptr_tmprcv, ptr_rcvmap, r);
229 for (i=0; i<sndcnt; i++) BOOST_CHECK_EQUAL( ptr_tmprcv[i] , ptr_rcvdat[nproc*r+i] );
232 ptr_tmprcv=
new double[nproc];
233 for (i=0; i<nproc; i++) ptr_tmprcv[i]=ptr_snddat[i];
234 PE::Comm::instance().broadcast(ptr_tmprcv, sndcnt, ptr_sndmap, ptr_tmprcv, ptr_rcvmap, r);
235 for (i=0; i<sndcnt; i++) BOOST_CHECK_EQUAL( ptr_tmprcv[i] , ptr_rcvdat[nproc*r+i] );
239 ptr_tmprcv=(
double*)PE::Comm::instance().broadcast((
char*)ptr_snddat, sndcnt, ptr_sndmap, (
char*)0, ptr_rcvmap, r,
sizeof(
double));
240 for (i=0; i<sndcnt; i++) BOOST_CHECK_EQUAL( ptr_tmprcv[i] , ptr_rcvdat[nproc*r+i] );
242 for (i=0; i<sndcnt; i++) ptr_tmprcv[i]=0.;
243 PE::Comm::instance().broadcast((
char*)ptr_snddat, sndcnt, ptr_sndmap, (
char*)ptr_tmprcv, ptr_rcvmap, r,
sizeof(
double));
244 for (i=0; i<sndcnt; i++) BOOST_CHECK_EQUAL( ptr_tmprcv[i] , ptr_rcvdat[nproc*r+i] );
247 ptr_tmprcv=
new double[nproc];
248 for (i=0; i<nproc; i++) ptr_tmprcv[i]=ptr_snddat[i];
249 PE::Comm::instance().broadcast((
char*)ptr_tmprcv, sndcnt, ptr_sndmap, (
char*)ptr_tmprcv, ptr_rcvmap, r,
sizeof(
double));
250 for (i=0; i<sndcnt; i++) BOOST_CHECK_EQUAL( ptr_tmprcv[i] , ptr_rcvdat[nproc*r+i] );
260 setup_data_variable();
262 for (r=0; r<nproc; r++) {
264 vec_tmprcv.resize(0);
265 vec_tmprcv.reserve(0);
266 PE::Comm::instance().broadcast(vec_snddat, vec_sndmap, vec_tmprcv, vec_rcvmap, r);
267 for (i=0; i<sndcnt; i++) BOOST_CHECK_EQUAL( vec_tmprcv[i] , vec_rcvdat[nproc*r+i] );
269 for (i=0; i<sndcnt; i++) vec_tmprcv[i]=0.;
270 PE::Comm::instance().broadcast(vec_snddat, vec_sndmap, vec_tmprcv, vec_rcvmap, r);
271 for (i=0; i<sndcnt; i++) BOOST_CHECK_EQUAL( vec_tmprcv[i] , vec_rcvdat[nproc*r+i] );
273 vec_tmprcv.resize(nproc);
274 vec_tmprcv.reserve(nproc);
275 for (i=0; i<nproc; i++) vec_tmprcv[i]=vec_snddat[i];
276 PE::Comm::instance().broadcast(vec_tmprcv, vec_sndmap, vec_tmprcv, vec_rcvmap, r);
277 for (i=0; i<sndcnt; i++) BOOST_CHECK_EQUAL( vec_tmprcv[i] , vec_rcvdat[nproc*r+i] );
279 vec_tmprcvchr.resize(0);
280 vec_tmprcvchr.reserve(0);
281 PE::Comm::instance().broadcast(vec_snddatchr, vec_sndmap, vec_tmprcvchr, vec_rcvmap, r,
sizeof(
double));
282 for (i=0; i<sndcnt; i++) BOOST_CHECK_EQUAL( ((
double*)&vec_tmprcvchr[0])[i] , vec_rcvdat[nproc*r+i] );
284 for (i=0; i<nproc; i++) ((
double*)&vec_tmprcvchr[0])[i]=0.;
285 PE::Comm::instance().broadcast(vec_snddatchr, vec_sndmap, vec_tmprcvchr, vec_rcvmap, r,
sizeof(
double));
286 for (i=0; i<sndcnt; i++) BOOST_CHECK_EQUAL( ((
double*)&vec_tmprcvchr[0])[i] , vec_rcvdat[nproc*r+i] );
288 vec_tmprcvchr.resize(nproc*
sizeof(
double));
289 vec_tmprcvchr.reserve(nproc*
sizeof(
double));
290 for (i=0; i<nproc; i++) ((
double*)(&vec_tmprcvchr[0]))[i]=vec_snddat[i];
291 PE::Comm::instance().broadcast(vec_tmprcvchr, vec_sndmap, vec_tmprcvchr, vec_rcvmap, r,
sizeof(
double));
292 for (i=0; i<sndcnt; i++) BOOST_CHECK_EQUAL( ((
double*)&vec_tmprcvchr[0])[i] , vec_rcvdat[nproc*r+i] );
298 BOOST_AUTO_TEST_SUITE_END()
#define CFinfo
these are always defined
std::vector< char > vec_tmprcvchr
int sndcnt
data for raw pointers
std::vector< int > vec_sndmap
void setup_data_variable()
helper function for variable size data - setting up input and verification data
PEBroadcastFixture()
common setup for each test case
BOOST_AUTO_TEST_CASE(Broadcast)
std::vector< double > vec_snddat
data for std::vectors
std::vector< double > vec_tmprcv
std::vector< int > vec_rcvmap
std::vector< double > vec_rcvdat
std::vector< char > vec_snddatchr
void setup_data_constant()
helper function for constant size data - setting up input and verification data
int nproc
number of processes
~PEBroadcastFixture()
common tear-down for each test case
#define PEProcessSortedExecute(irank, expression)