8 #ifndef SRC_GRID_ITERATORS_GRID_DIST_ID_ITERATORS_UNIT_TESTS_HPP_
9 #define SRC_GRID_ITERATORS_GRID_DIST_ID_ITERATORS_UNIT_TESTS_HPP_
11 #include "grid_dist_id_iterator_dec_skin.hpp"
13 BOOST_AUTO_TEST_SUITE( grid_dist_id_iterators_test )
15 void print_test(std::
string test,
size_t sz)
17 if (create_vcluster().getProcessUnitID() == 0)
18 std::cout << test <<
" " << sz <<
"\n";
23 long int big_step = k / 30;
24 big_step = (big_step == 0)?1:big_step;
25 long int small_step = 21;
28 if (create_vcluster().getProcessingUnits() > 32)
31 print_test(
"Testing 2D grid sub iterator k<=",k);
34 for ( ; k >= 2 ; k-= (k > 2*big_step)?big_step:small_step )
36 BOOST_TEST_CHECKPOINT(
"Testing 2D grid k=" << k );
43 float factor = pow(create_vcluster().getProcessingUnits()/2.0f,1.0f/2.0f);
52 bool val = g_dist.getDecomposition().check_consistency();
53 BOOST_REQUIRE_EQUAL(val,
true);
70 auto dom = g_dist.getSubDomainIterator(one,one_end);
75 auto key_g = g_dist.getGKey(
key);
78 check &= (key_g.get(0) == 0 || key_g.get(0) == k-1)?
false:
true;
79 check &= (key_g.get(1) == 0 || key_g.get(1) == k-1)?
false:
true;
81 g_dist.template get<0>(
key) = info.LinId(key_g);
89 BOOST_REQUIRE_EQUAL(check,
true);
103 BOOST_REQUIRE_EQUAL(count,(
size_t)(k-2)*(k-2));
115 auto dom = g_dist.getSubDomainIterator(one,one_end);
119 auto key = dom.get();
120 auto key_g = g_dist.getGKey(
key);
123 BOOST_REQUIRE_EQUAL(key_g.get(0),k/2);
124 BOOST_REQUIRE_EQUAL(key_g.get(1),k/2);
126 auto key_s_it = dom.getGKey(
key);
128 BOOST_REQUIRE_EQUAL(key_g.get(0),key_s_it.get(0));
129 BOOST_REQUIRE_EQUAL(key_g.get(1),key_s_it.get(1));
141 BOOST_REQUIRE_EQUAL(count,1ul);
148 void Test3D_decit(
const Box<3,float> & domain,
long int k)
152 Vcluster & v_cl = create_vcluster();
157 long int big_step = k / 30;
158 big_step = (big_step == 0)?1:big_step;
159 long int small_step = 21;
161 print_test(
"Testing grid iterator from decomposition k<=",k);
164 for ( ; k >= 2 ; k-= (k > 2*big_step)?big_step:small_step )
166 BOOST_TEST_CHECKPOINT(
"Testing grid iterator from decomposition k<=" << k );
175 float factor = pow(create_vcluster().getProcessingUnits()/2.0f,1.0f/3.0f);
184 bool val = g_dist.getDecomposition().check_consistency();
185 BOOST_REQUIRE_EQUAL(val,
true);
190 auto dom = g_dist.getDomainIterator();
200 auto key = dom.get();
201 auto key_g = g_dist.getGKey(
key);
203 auto key_dec = it_dec.get();
206 match &= (key_dec == key_g);
212 BOOST_REQUIRE_EQUAL(match,
true);
219 Vcluster & v_cl = create_vcluster();
224 long int big_step = k / 30;
225 big_step = (big_step == 0)?1:big_step;
226 long int small_step = 21;
228 print_test(
"Testing grid iterator from decomposition subset k<=",k);
231 for ( ; k >= 2 ; k-= (k > 2*big_step)?big_step:small_step )
233 BOOST_TEST_CHECKPOINT(
"Testing grid iterator from decomposition k<=" << k );
242 float factor = pow(create_vcluster().getProcessingUnits()/2.0f,1.0f/3.0f);
251 bool val = g_dist.getDecomposition().check_consistency();
252 BOOST_REQUIRE_EQUAL(val,
true);
257 auto dom = g_dist.getSubDomainIterator({0,0,0},{(
long int)sz[0]-2,(
long int)sz[1]-2,(
long int)sz[2]-2});
267 auto key = dom.get();
268 auto key_g = g_dist.getGKey(
key);
270 auto key_dec = it_dec.get();
273 match &= (key_dec == key_g);
279 BOOST_REQUIRE_EQUAL(match,
true);
284 void Test3D_stencil(
const Box<3,float> & domain,
long int k)
295 Vcluster & v_cl = create_vcluster();
300 long int big_step = k / 30;
301 big_step = (big_step == 0)?1:big_step;
302 long int small_step = 21;
304 print_test(
"Testing grid stencil iterator k<=",k);
307 for ( ; k >= 2 ; k-= (k > 2*big_step)?big_step:small_step )
309 BOOST_TEST_CHECKPOINT(
"Testing grid skin iterator from decomposition k<=" << k );
327 auto it = g_dist.getDomainGhostIterator();
332 auto gkey = it.getGKey(p);
334 g_dist.template get<0>(p) = gkey.get(0) + gkey.get(1) + gkey.get(2);
339 g_dist.ghost_get<0>();
341 auto st_it = g_dist.getDomainIteratorStencil(star_stencil_3D);
345 while (st_it.isNext())
347 auto key = st_it.get();
350 auto Cp = st_it.getStencil<0>();
353 auto mx = st_it.getStencil<1>();
354 auto px = st_it.getStencil<2>();
355 auto my = st_it.getStencil<3>();
356 auto py = st_it.getStencil<4>();
357 auto mz = st_it.getStencil<5>();
358 auto pz = st_it.getStencil<6>();
360 size_t sum = 6*g_dist.template get<0>(Cp) -
361 g_dist.template get<0>(mx) -
362 g_dist.template get<0>(px) -
363 g_dist.template get<0>(my) -
364 g_dist.template get<0>(py) -
365 g_dist.template get<0>(mz) -
366 g_dist.template get<0>(pz);
374 ret &= info.
LinId(
key.getKey()) == (
long int)Cp.getKey();
379 BOOST_REQUIRE_EQUAL(ret,
true);
385 void Test3D_fast_vect(
const Box<3,float> & domain,
long int k)
396 Vcluster & v_cl = create_vcluster();
401 long int big_step = k / 30;
402 big_step = (big_step == 0)?1:big_step;
403 long int small_step = 21;
405 print_test(
"Testing grid 3D fast stencil k<=",k);
408 for ( ; k >= 2 ; k-= (k > 2*big_step)?big_step:small_step )
410 BOOST_TEST_CHECKPOINT(
"Testing grid skin iterator from decomposition k<=" << k );
428 auto it = g_dist.getDomainGhostIterator();
433 auto gkey = it.getGKey(p);
435 g_dist.template get<0>(p) = gkey.get(0)*gkey.get(0) + gkey.get(1)*gkey.get(1) + gkey.get(2)*gkey.get(2);
440 g_dist.ghost_get<0>();
444 WHILE_M(g_dist,star_stencil_3D)
445 auto & gstl = GET_GRID_M(g_dist);
448 auto Cp = it.getStencil<0>();
451 auto mx = it.getStencil<1>();
452 auto px = it.getStencil<2>();
453 auto my = it.getStencil<3>();
454 auto py = it.getStencil<4>();
455 auto mz = it.getStencil<5>();
456 auto pz = it.getStencil<6>();
458 long int sum = -6*gstl.template get<0>(Cp) +
459 gstl.template get<0>(mx) +
460 gstl.template get<0>(px) +
461 gstl.template get<0>(my) +
462 gstl.template get<0>(py) +
463 gstl.template get<0>(mz) +
464 gstl.template get<0>(pz);
470 BOOST_REQUIRE_EQUAL(ret,true);
478 void Test3D_decskinit(const
Box<3,
float> & domain,
long int k)
481 Vcluster & v_cl = create_vcluster();
486 long int big_step = k / 30;
487 big_step = (big_step == 0)?1:big_step;
488 long int small_step = 21;
490 print_test(
"Testing grid skin iterator from decomposition k<=",k);
493 for ( ; k >= 2 ; k-= (k > 2*big_step)?big_step:small_step )
495 BOOST_TEST_CHECKPOINT(
"Testing grid skin iterator from decomposition k<=" << k );
507 float factor = pow(create_vcluster().getProcessingUnits()/2.0f,1.0f/3.0f);
516 bool val = g_dist.getDecomposition().check_consistency();
517 BOOST_REQUIRE_EQUAL(val,
true);
524 Box<3,size_t> A({3,3,3},{(size_t)k-3,(
size_t)k-3,(size_t)k-3});
527 if (A.isValid() ==
false)
530 size_t bc[3] = {NON_PERIODIC,NON_PERIODIC,NON_PERIODIC};
535 bool tot_good =
true;
536 while (it_dec.isNext())
538 auto key_dec = it_dec.get();
543 bool eight_or_three =
false;
545 for (
size_t i = 0; i < 3 ; i++)
547 if (key_dec.get(i) == 3 || key_dec.get(i) == k - 3)
548 eight_or_three =
true;
550 if (key_dec.get(i) > k - 3 || key_dec.get(i) < 3 )
554 tot_good &= (eight_or_three) || good;
560 create_vcluster().sum(cnt);
561 create_vcluster().execute();
563 BOOST_REQUIRE_EQUAL(cnt,(
size_t)((k-5)*(k-5)*(k-5) - (k-7)*(k-7)*(k-7)));
564 BOOST_REQUIRE_EQUAL(tot_good,
true);
569 BOOST_AUTO_TEST_CASE( grid_dist_id_sub_iterator_test_use)
574 long int k = 1024*1024*create_vcluster().getProcessingUnits();
575 k = std::pow(k, 1/2.);
577 Test2D_sub(domain,k);
580 BOOST_AUTO_TEST_CASE( grid_dist_id_decomposition_iterator )
585 size_t k = 128*128*128*create_vcluster().getProcessingUnits();
586 k = std::pow(k, 1/3.);
587 Test3D_decit(domain3,k);
590 BOOST_AUTO_TEST_CASE( grid_dist_id_iterator_stencil )
595 size_t k = 128*128*128*create_vcluster().getProcessingUnits();
596 k = std::pow(k, 1/3.);
597 Test3D_stencil(domain3,k);
601 BOOST_AUTO_TEST_CASE( grid_dist_it_iterators_skin_test )
606 size_t k = 128*128*128*create_vcluster().getProcessingUnits();
607 k = std::pow(k, 1/3.);
608 Test3D_decskinit(domain3,k);
611 BOOST_AUTO_TEST_CASE( grid_dist_it_iterators_3D_fast )
616 size_t k = 128*128*128*create_vcluster().getProcessingUnits();
617 k = std::pow(k, 1/3.);
618 Test3D_fast_vect(domain3,k);
621 BOOST_AUTO_TEST_SUITE_END()
void sum(T &num)
Sum the numbers across all processors and get the result.
mem_id LinId(const grid_key_dx< N > &gk, const char sum_id[N]) const
Linearization of the grid_key_dx with a specified shift.
grid_key_dx is the key to access any element in the grid
void execute()
Execute all the requests.
Given the decomposition it create an iterator.
Implementation of VCluster class.
This class decompose a space into sub-sub-domains and distribute them across processors.
This is a distributed grid.
This class represent an N-dimensional box.
This class is a trick to indicate the compiler a specific specialization pattern. ...
It model an expression expr1 + ... exprn.
size_t getProcessingUnits()
Get the total number of processors.
Given the decomposition it create an iterator.