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"
13BOOST_AUTO_TEST_SUITE( grid_dist_id_iterators_test )
15void 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);
148void Test3D_decit(
const Box<3,float> & domain,
long int k)
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);
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);
284void Test3D_stencil(
const Box<3,float> & domain,
long int k)
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);
385void Test3D_fast_vect(
const Box<3,float> & domain,
long int k)
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);
478void Test3D_decskinit(const
Box<3,
float> & domain,
long int k)
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);
517 auto it = g_dist.getDomainIterator();
522 auto gp = it.getGKey(p);
524 g_dist.template get<0>(p) = 0.0;
530 bool val = g_dist.getDecomposition().check_consistency();
531 BOOST_REQUIRE_EQUAL(val,
true);
538 Box<3,size_t> A({3,3,3},{(size_t)k-3,(
size_t)k-3,(size_t)k-3});
541 if (A.isValid() ==
false)
544 size_t bc[3] = {NON_PERIODIC,NON_PERIODIC,NON_PERIODIC};
549 bool tot_good =
true;
550 while (it_dec.isNext())
552 auto key_dec = it_dec.get();
553 auto key_dec_loc = it_dec.get_int();
558 bool eight_or_three =
false;
560 for (
size_t i = 0; i < 3 ; i++)
562 if (key_dec.get(i) == 3 || key_dec.get(i) == k - 3)
563 {eight_or_three =
true;}
565 if (key_dec.get(i) > k - 3 || key_dec.get(i) < 3 )
569 g_dist.template get<0>(key_dec_loc) = 1.0;
571 tot_good &= (eight_or_three) || good;
577 create_vcluster().sum(cnt);
578 create_vcluster().execute();
580 BOOST_REQUIRE_EQUAL(cnt,(
size_t)((k-5)*(k-5)*(k-5) - (k-7)*(k-7)*(k-7)));
581 BOOST_REQUIRE_EQUAL(tot_good,
true);
586BOOST_AUTO_TEST_CASE( grid_dist_id_sub_iterator_test_use)
591 long int k = 1024*1024*create_vcluster().getProcessingUnits();
592 k = std::pow(k, 1/2.);
594 Test2D_sub(domain,k);
597BOOST_AUTO_TEST_CASE( grid_dist_id_decomposition_iterator )
602 size_t k = 128*128*128*create_vcluster().getProcessingUnits();
603 k = std::pow(k, 1/3.);
604 Test3D_decit(domain3,k);
607BOOST_AUTO_TEST_CASE( grid_dist_id_iterator_stencil )
612 size_t k = 128*128*128*create_vcluster().getProcessingUnits();
613 k = std::pow(k, 1/3.);
614 Test3D_stencil(domain3,k);
618BOOST_AUTO_TEST_CASE( grid_dist_it_iterators_skin_test )
623 size_t k = 128*128*128*create_vcluster().getProcessingUnits();
624 k = std::pow(k, 1/3.);
625 Test3D_decskinit(domain3,k);
628BOOST_AUTO_TEST_CASE( grid_dist_it_iterators_3D_fast )
633 size_t k = 128*128*128*create_vcluster().getProcessingUnits();
634 k = std::pow(k, 1/3.);
635 Test3D_fast_vect(domain3,k);
638BOOST_AUTO_TEST_SUITE_END()
This class represent an N-dimensional box.
This class decompose a space into sub-sub-domains and distribute them across processors.
void execute()
Execute all the requests.
void sum(T &num)
Sum the numbers across all processors and get the result.
size_t getProcessingUnits()
Get the total number of processors.
Implementation of VCluster class.
Given the decomposition it create an iterator.
Given the decomposition it create an iterator.
This is a distributed grid.
grid_key_dx is the key to access any element in the grid
mem_id LinId(const grid_key_dx< N, ids_type > &gk, const signed char sum_id[N]) const
Linearization of the grid_key_dx with a specified shift.
KeyT const ValueT ValueT OffsetIteratorT OffsetIteratorT int
[in] The number of segments that comprise the sorting data
It model an expression expr1 + ... exprn.