11 #define BOOST_TEST_DYN_LINK
12 #define BOOST_TEST_MODULE "Test module for cf3::common 's parallel environment - part of testing the commwrapper."
16 #include <boost/test/unit_test.hpp>
17 #include <boost/shared_ptr.hpp>
43 m_argc = boost::unit_test::framework::master_test_suite().argc;
44 m_argv = boost::unit_test::framework::master_test_suite().argv;
61 BOOST_CHECK_EQUAL( w1->
size() , 16 );
62 BOOST_CHECK_EQUAL( w2->
size() , 8 );
64 BOOST_CHECK_EQUAL( w1->
stride() , 1 );
65 BOOST_CHECK_EQUAL( w2->
stride() , 3 );
67 BOOST_CHECK_EQUAL( w1->
size_of() , (int)
sizeof(
Uint) );
68 BOOST_CHECK_EQUAL( w2->
size_of() , (int)
sizeof(
double) );
76 double *dtest2=(
double*)w2->
pack();
78 for(i=0; i<16; i++) { BOOST_CHECK_EQUAL(itest1[i],16+i); itest1[i]+=16; }
79 for(i=0; i<24; i++) { BOOST_CHECK_EQUAL(dtest2[i],24.+(
double)i); dtest2[i]+=24.; }
84 for (i=0; i<16; i++) itest1[i]=0;
85 for (i=0; i<24; i++) dtest2[i]=0.;
90 for(i=0; i<16; i++) { BOOST_CHECK_EQUAL(itest1[i],32+i); itest1[i]+=16; }
91 for(i=0; i<24; i++) { BOOST_CHECK_EQUAL(dtest2[i],48.+(
double)i); dtest2[i]+=24.; }
93 std::vector<Uint> iv1; iv1.assign(itest1,itest1+16);
94 std::vector<double> dv2; dv2.assign(dtest2,dtest2+24);
105 BOOST_CHECK_EQUAL(iv1.size(),16);
106 BOOST_CHECK_EQUAL(dv2.size(),24);
107 for(i=0; i<16; i++) { BOOST_CHECK_EQUAL(iv1[i],48+i); iv1[i]+=16; }
108 for(i=0; i<24; i++) { BOOST_CHECK_EQUAL(dv2[i],72.+(
double)i); dv2[i]+=24.; }
110 std::vector<unsigned char> cv1; cv1.assign((
unsigned char*)&iv1[0],(
unsigned char*)&iv1[0]+16*
sizeof(
Uint));
111 std::vector<unsigned char> cv2; cv2.assign((
unsigned char*)&dv2[0],(
unsigned char*)&dv2[0]+24*
sizeof(
double));
116 cv1.assign(1000,0x00);
117 cv2.assign(1000,0x00);
122 BOOST_CHECK_EQUAL(cv1.size(),16*
sizeof(
Uint));
123 BOOST_CHECK_EQUAL(cv2.size(),24*
sizeof(double));
124 for(i=0; i<16; i++) { BOOST_CHECK_EQUAL( ((
Uint*)(&cv1[0]))[i] , 64+i ); ((
Uint*)(&cv1[0]))[i]+=16; }
125 for(i=0; i<24; i++) { BOOST_CHECK_EQUAL( ((
double*)(&cv2[0]))[i] , (
double)(96+i) ); ((
double*)(&cv2[0]))[i]+=24.; }
136 for(i=0; i<16; i++) iv1[i]-=64;
137 for(i=0; i<24; i++) dv2[i]-=96.;
138 for(i=0; i<16; i++) BOOST_CHECK_EQUAL(iv1[i],16+i);
139 for(i=0; i<24; i++) BOOST_CHECK_EQUAL(dv2[i],24.+(
double)i);
150 double *dtest2=(
double*)w2->
pack(map);
152 for(i=0; i<4; i++) { BOOST_CHECK_EQUAL( itest1[i] , 16+map[i] ); itest1[i]+=16; }
153 for(i=0; i<4; i++)
for (j=0; j<3; j++) { BOOST_CHECK_EQUAL( dtest2[i*3+j] , (
double)(24+3*map[i]+j) ); dtest2[i*3+j]+=24.; }
158 for (i=0; i<4; i++) itest1[i]=0;
159 for (i=0; i<12; i++) dtest2[i]=0.;
161 w1->
pack(map,itest1);
162 w2->
pack(map,dtest2);
164 for(i=0; i<4; i++) { BOOST_CHECK_EQUAL( itest1[i] , 32+map[i] ); itest1[i]+=16; }
165 for(i=0; i<4; i++)
for (j=0; j<3; j++) { BOOST_CHECK_EQUAL( dtest2[i*3+j] , (
double)(48+3*map[i]+j) ); dtest2[i*3+j]+=24.; }
167 std::vector<Uint> iv1; iv1.assign(itest1,itest1+4);
168 std::vector<double> dv2; dv2.assign(dtest2,dtest2+12);
179 BOOST_CHECK_EQUAL(iv1.size(),4);
180 BOOST_CHECK_EQUAL(dv2.size(),12);
181 for(i=0; i<4; i++) { BOOST_CHECK_EQUAL( iv1[i] , 48+map[i] ); iv1[i]+=16; }
182 for(i=0; i<4; i++)
for (j=0; j<3; j++) { BOOST_CHECK_EQUAL( dv2[i*3+j] , (
double)(72+3*map[i]+j) ); dv2[i*3+j]+=24.; }
184 std::vector<unsigned char> cv1; cv1.assign((
unsigned char*)&iv1[0],(
unsigned char*)&iv1[0]+4*
sizeof(
Uint));
185 std::vector<unsigned char> cv2; cv2.assign((
unsigned char*)&dv2[0],(
unsigned char*)&dv2[0]+12*
sizeof(
double));
190 cv1.assign(1000,0x00);
191 cv2.assign(1000,0x00);
196 BOOST_CHECK_EQUAL(cv1.size(),4*
sizeof(
Uint));
197 BOOST_CHECK_EQUAL(cv2.size(),12*
sizeof(double));
198 for(i=0; i<4; i++) { BOOST_CHECK_EQUAL( ((
Uint*)(&cv1[0]))[i] , 64+map[i] ); ((
Uint*)(&cv1[0]))[i]+=16; }
199 for(i=0; i<4; i++)
for (j=0; j<3; j++) { BOOST_CHECK_EQUAL( ((
double*)(&cv2[0]))[i*3+j] , (
double)(96+3*map[i]+j) ); ((
double*)(&cv2[0]))[i*3+j]+=24.; }
210 for(i=0; i<4; i++) iv1[map[i]]-=64;
211 for(i=0; i<4; i++)
for (j=0; j<3; j++) dv2[3*map[i]+j]-=96.;
212 for(i=0; i<16; i++) BOOST_CHECK_EQUAL(iv1[i],16+i);
213 for(i=0; i<24; i++) BOOST_CHECK_EQUAL(dv2[i],24.+(
double)i);
227 BOOST_CHECK_EQUAL(iwv1.
size(),16);
228 BOOST_CHECK_EQUAL(dwv2.
size(),24);
233 for(i=0; i<16; i++) BOOST_CHECK_EQUAL(ip[i],16+i);
234 for(i=0; i<24; i++) BOOST_CHECK_EQUAL(dp[i],24.+(
double)i);
239 BOOST_CHECK_EQUAL(cwv1.
size(),16*
sizeof(
Uint));
240 BOOST_CHECK_EQUAL(cwv2.
size(),24*
sizeof(double));
243 double* da=(
double*)cwv2();
245 for(i=0; i<16; i++) BOOST_CHECK_EQUAL(ia[i],16+i);
246 for(i=0; i<24; i++) BOOST_CHECK_EQUAL(da[i],24.+(
double)i);
257 BOOST_CHECK_EQUAL( w1->
size() , 26 );
258 BOOST_CHECK_EQUAL( w2->
size() , 18 );
259 BOOST_CHECK_EQUAL( w1->
stride() , 1 );
260 BOOST_CHECK_EQUAL( w2->
stride() , 3 );
265 BOOST_CHECK_EQUAL( w1->
size() , 11 );
266 BOOST_CHECK_EQUAL( w2->
size() , 3 );
267 BOOST_CHECK_EQUAL( w1->
stride() , 1 );
268 BOOST_CHECK_EQUAL( w2->
stride() , 3 );
273 BOOST_CHECK_EQUAL(iwv1.size(),11);
274 BOOST_CHECK_EQUAL(dwv2.
size(),9);
278 for (ia=iwv1(), i=0; i<(
const int)iwv1.size(); i++) BOOST_CHECK_EQUAL(ia[i],16+i);
279 for (da=dwv2(), i=0; i<(
const int)dwv2.
size(); i++) BOOST_CHECK_EQUAL(da[i],24.+(
double)i);
297 CFinfo.setFilterRankZero(
false);
307 double *d2=
new double[24];
308 std::vector<int>
map(4);
310 for(i=0; i<16; i++) i1[i]=16+i;
311 for(i=0; i<24; i++) d2[i]=24.+(
double)i;
312 for(i=0; i<4; i++) map[i]=1+2*i;
314 boost::shared_ptr< CommWrapperPtr<Uint> > wptr1= allocate_component< CommWrapperPtr<Uint> >(
"Ptr1");
315 boost::shared_ptr< CommWrapperPtr<double> > wptr2=allocate_component< CommWrapperPtr<double> >(
"Ptr2");
319 wptr1->setup(i1,16,1,
true);
320 wptr2->setup(d2,24,3,
false);
323 test_pack_unpack(w1,w2);
324 test_mapped_pack_unpack(w1,w2,map);
332 BOOST_CHECK_EQUAL(w1->size(),5);
340 BOOST_CHECK_EQUAL(w1->size(),6);
353 std::vector<Uint> i1(16);
354 std::vector<double> d2(24);
355 std::vector<int>
map(4);
357 for(i=0; i<16; i++) i1[i]=16+i;
358 for(i=0; i<24; i++) d2[i]=24.+(
double)i;
359 for(i=0; i<4; i++) map[i]=1+2*i;
361 boost::shared_ptr< CommWrapperVector<Uint> > wptr1= allocate_component< CommWrapperVector<Uint> >(
"Ptr1");
362 boost::shared_ptr< CommWrapperVector<double> > wptr2=allocate_component< CommWrapperVector<double> >(
"Ptr2");
366 wptr1->setup(i1,1,
true);
367 wptr2->setup(d2,3,
false);
370 test_pack_unpack(w1,w2);
371 test_mapped_pack_unpack(w1,w2,map);
381 boost::multi_array<Uint,1> i1;
382 boost::multi_array<double,2> d2;
383 std::vector<int>
map(4);
384 i1.resize(boost::extents[16]);
385 d2.resize(boost::extents[8][3]);
387 for(i=0; i<16; i++) i1[i]=16+i;
390 d2[i][j]=24.+(
double)(3*i+j);
391 for(i=0; i<4; i++) map[i]=1+2*i;
393 boost::shared_ptr< CommWrapperMArray<Uint,1> > wptr1= allocate_component< CommWrapperMArray<Uint,1> >(
"Ptr1");
394 boost::shared_ptr< CommWrapperMArray<double,2> > wptr2=allocate_component< CommWrapperMArray<double,2> >(
"Ptr2");
398 wptr1->setup(i1,
true);
399 wptr2->setup(d2,
false);
402 test_pack_unpack(w1,w2);
403 test_mapped_pack_unpack(w1,w2,map);
413 CFinfo.setFilterRankZero(
true);
420 BOOST_AUTO_TEST_SUITE_END()
#define CFinfo
these are always defined
void test_view(Handle< CommWrapper > &w1, Handle< CommWrapper > &w2)
helper function for testing views
Safe pointer to an object. This is the supported method for referring to components.
Parallel Communication Pattern. This class provides functionality to collect communication. For efficiency it works such a way that you submit your request via the constructor or the add/remove/move magic triangle and then call setup to modify the commpattern. The data needed to be kept synchronous can be registered via the insert function. The word node here means any kind of "point of storage", in this context it is not directly related with the computational mesh.
void test_setup(Handle< CommWrapper > &w1, Handle< CommWrapper > &w2)
helper function to test setup
bool needs_update() const
void test_resize(Handle< CommWrapper > &w1, Handle< CommWrapper > &w2)
helper function for testing resize
virtual void resize(const int size)=0
void test_pack_unpack(Handle< CommWrapper > &w1, Handle< CommWrapper > &w2)
helper function to test pack and unpack
Holds the Component class, as well as the ComponentIterator class plus some functions related to comp...
virtual int stride() const =0
virtual bool is_data_type_Uint() const =0
~CommWrapperFixture()
common tear-down for each test case
void init(int argc=0, char **args=0)
Top-level namespace for coolfluid.
BOOST_AUTO_TEST_CASE(init)
virtual const void * pack(std::vector< int > &map, void *buf=nullptr) const =0
CommWrapperFixture()
common setup for each test case
unsigned int Uint
typedef for unsigned int
Classes offering a MPI interface for COOLFluiD.
void test_mapped_pack_unpack(Handle< CommWrapper > &w1, Handle< CommWrapper > &w2, std::vector< int > &map)
helper function to test mapped pack and unpack
virtual int size_of() const =0
virtual int size() const =0
virtual void unpack(void *buf, std::vector< int > &map) const =0
static Comm & instance()
Return a reference to the current PE.
void map(Field &field, Eigen::Map< Derived > &v, const Uint row_idx, const Uint var_idx)
Most basic kernel library.
int size()
accessor to the length of the array, measured in items of sizeof(T)
#define PEProcessSortedExecute(irank, expression)