1#ifndef GRID_UNIT_TEST_HPP
2#define GRID_UNIT_TEST_HPP
6#include "Point_test.hpp"
7#include "Space/Shape/HyperCube.hpp"
9#include "grid_util_test.hpp"
10#include "grid_test_utils.hpp"
12#ifdef TEST_COVERAGE_MODE
13constexpr int GS_SIZE = 8;
15constexpr int GS_SIZE = 128;
18template<
unsigned int dim,
typename g>
void test_layout_gridNd(g & c3,
size_t sz);
19template<
unsigned int dim,
typename g>
void test_layout_gridObjNd(g & c3,
size_t sz);
20template<
typename g>
void test_layout_grid3d(g & c3,
size_t sz);
27template<
unsigned int dim>
void test_all_grid(
size_t sz)
31 for (
size_t i = 0 ; i < dim ; i++)
36 test_layout_gridNd<dim>(c3,sz);}
40 test_layout_gridObjNd<dim>(c3,sz);}
46 test_layout_gridNd<dim>(c3,sz);}
50 test_layout_gridObjNd<dim>(c3,sz);}
56 test_layout_gridObjNd<dim>(c3,sz);}
60 test_layout_gridNd<dim>(c3,sz);}
66 test_layout_gridNd<dim>(c3,sz);}
70 test_layout_gridObjNd<dim>(c3,sz);}
77template<
typename g>
void test_layout_grid3d(g & c3,
size_t sz)
81 std::cout <<
"3D Array with grid_key (without redundant dimension): " <<
"\n";
92 for (
size_t i = 0 ; i < sz ; i++)
94 for (
size_t j = 0 ; j < sz ; j++)
96 for (
size_t k = 0 ; k < sz ; k++)
101 c3.template get<P::x>(kk) = 1.1f;
102 c3.template get<P::y>(kk) = 1.2f;
103 c3.template get<P::z>(kk) = 1.3f;
104 c3.template get<P::s>(kk) = 1.0f;
106 c3.template get<P::v>(kk)[0] = 1.0f;
107 c3.template get<P::v>(kk)[1] = 2.0f;
108 c3.template get<P::v>(kk)[2] = 3.0f;
110 c3.template get<P::t>(kk)[0][0] = 1.0f;
111 c3.template get<P::t>(kk)[0][1] = 2.0f;
112 c3.template get<P::t>(kk)[0][2] = 3.0f;
113 c3.template get<P::t>(kk)[1][0] = 4.0f;
114 c3.template get<P::t>(kk)[1][1] = 5.0f;
115 c3.template get<P::t>(kk)[1][2] = 6.0f;
116 c3.template get<P::t>(kk)[2][0] = 7.0f;
117 c3.template get<P::t>(kk)[2][1] = 8.0f;
118 c3.template get<P::t>(kk)[2][2] = 9.0f;
129 std::cout <<
"End : " << sz*sz*sz*16*4 <<
" Byte " <<
" Bandwidth: " << sz*sz*sz*16*4/1024/1024/t.
getwct() <<
" MB/s ";
136 for (
size_t i = 0 ; i < sz ; i++)
138 for (
size_t j = 0 ; j < sz ; j++)
140 for (
size_t k = 0 ; k < sz ; k++)
144 c3.template get<P::x>(kk) = i;
145 c3.template get<P::y>(kk) = j;
146 c3.template get<P::z>(kk) = k;
147 c3.template get<P::s>(kk) = i+j+k;
149 c3.template get<P::v>(kk)[0] = i;
150 c3.template get<P::v>(kk)[1] = j;
151 c3.template get<P::v>(kk)[2] = k;
153 c3.template get<P::t>(kk)[0][0] = i+i;
154 c3.template get<P::t>(kk)[0][1] = i+j;
155 c3.template get<P::t>(kk)[0][2] = i+k;
156 c3.template get<P::t>(kk)[1][0] = j+i;
157 c3.template get<P::t>(kk)[1][1] = j+j;
158 c3.template get<P::t>(kk)[1][2] = j+k;
159 c3.template get<P::t>(kk)[2][0] = k+i;
160 c3.template get<P::t>(kk)[2][1] = k+j;
161 c3.template get<P::t>(kk)[2][2] = k+k;
166 for (
size_t i = 0 ; i < sz ; i++)
168 for (
size_t j = 0 ; j < sz ; j++)
170 for (
size_t k = 0 ; k < sz ; k++)
174 if (c3.template get<P::x>(kk) != i) passed =
false;
175 if (c3.template get<P::y>(kk) != j) passed =
false;
176 if (c3.template get<P::z>(kk) != k) passed =
false;
177 if (c3.template get<P::s>(kk) != i+j+k) passed =
false;
179 if (c3.template get<P::v>(kk)[0] != i) passed =
false;
180 if (c3.template get<P::v>(kk)[1] != j) passed =
false;
181 if (c3.template get<P::v>(kk)[2] != k) passed =
false;
183 if (c3.template get<P::t>(kk)[0][0] != i+i) passed =
false;
184 if (c3.template get<P::t>(kk)[0][1] != i+j) passed =
false;
185 if (c3.template get<P::t>(kk)[0][2] != i+k) passed =
false;
186 if (c3.template get<P::t>(kk)[1][0] != j+i) passed =
false;
187 if (c3.template get<P::t>(kk)[1][1] != j+j) passed =
false;
188 if (c3.template get<P::t>(kk)[1][2] != j+k) passed =
false;
189 if (c3.template get<P::t>(kk)[2][0] != k+i) passed =
false;
190 if (c3.template get<P::t>(kk)[2][1] != k+j) passed =
false;
191 if (c3.template get<P::t>(kk)[2][2] != k+k) passed =
false;
196 BOOST_REQUIRE_EQUAL(passed,
true);
199template<
unsigned int dim,
typename g>
void test_layout_gridObjNd(g & c3,
size_t sz)
202 std::cout << dim <<
"D Array with grid_key (without redundant dimension): " <<
"\n";
219 auto v = c3.get_o(kk);
223 v.template get<P::x>() = 1.1f;
224 v.template get<P::y>() = 1.2f;
225 v.template get<P::z>() = 1.3f;
226 v.template get<P::s>() = 1.0f;
228 v.template get<P::v>()[0] = 1.0f;
229 v.template get<P::v>()[1] = 2.0f;
230 v.template get<P::v>()[2] = 3.0f;
232 v.template get<P::t>()[0][0] = 1.0f;
233 v.template get<P::t>()[0][1] = 2.0f;
234 v.template get<P::t>()[0][2] = 3.0f;
235 v.template get<P::t>()[1][0] = 4.0f;
236 v.template get<P::t>()[1][1] = 5.0f;
237 v.template get<P::t>()[1][2] = 6.0f;
238 v.template get<P::t>()[2][0] = 7.0f;
239 v.template get<P::t>()[2][1] = 8.0f;
240 v.template get<P::t>()[2][2] = 9.0f;
260 std::cout <<
"End : " << pow(sz,dim)*16*4/1024/1024 <<
" MB " <<
" Bandwidth: " << pow(sz,dim)*16*4/1024/1024/t.getect() <<
" MB/s " <<
"\n";
270 key_it = c3.getIterator();
276 if (c3.template get<P::x>(kk) != c3.getGrid().LinId(kk)) passed =
false;
277 if (c3.template get<P::y>(kk) != c3.getGrid().LinId(kk)+1) passed =
false;
278 if (c3.template get<P::z>(kk) != c3.getGrid().LinId(kk)+2) passed =
false;
279 if (c3.template get<P::s>(kk) != c3.getGrid().LinId(kk)+3) passed =
false;
281 if (c3.template get<P::v>(kk)[0] != c3.getGrid().LinId(kk)+123) passed =
false;
282 if (c3.template get<P::v>(kk)[1] != c3.getGrid().LinId(kk)+124) passed =
false;
283 if (c3.template get<P::v>(kk)[2] != c3.getGrid().LinId(kk)+125) passed =
false;
285 if (c3.template get<P::t>(kk)[0][0] != c3.getGrid().LinId(kk)+567) passed =
false;
286 if (c3.template get<P::t>(kk)[0][1] != c3.getGrid().LinId(kk)+568) passed =
false;
287 if (c3.template get<P::t>(kk)[0][2] != c3.getGrid().LinId(kk)+569) passed =
false;
288 if (c3.template get<P::t>(kk)[1][0] != c3.getGrid().LinId(kk)+570) passed =
false;
289 if (c3.template get<P::t>(kk)[1][1] != c3.getGrid().LinId(kk)+571) passed =
false;
290 if (c3.template get<P::t>(kk)[1][2] != c3.getGrid().LinId(kk)+572) passed =
false;
291 if (c3.template get<P::t>(kk)[2][0] != c3.getGrid().LinId(kk)+573) passed =
false;
292 if (c3.template get<P::t>(kk)[2][1] != c3.getGrid().LinId(kk)+574) passed =
false;
293 if (c3.template get<P::t>(kk)[2][2] != c3.getGrid().LinId(kk)+575) passed =
false;
298 BOOST_REQUIRE_EQUAL(passed,
true);
302BOOST_AUTO_TEST_SUITE( grid_test )
304BOOST_AUTO_TEST_CASE( grid_safety_check )
306#if defined(SE_CLASS1) && defined (THROW_ON_ERROR)
312 size_t sz[] = {16,16,16};
328 {g.get<p::x>(keyOut);}
329 catch (std::exception & e)
332 BOOST_REQUIRE_EQUAL(e.what(),
"Runtime grid error");
334 BOOST_REQUIRE_EQUAL(error,
true);
339 {g.get<p::x>(keyOut);}
340 catch (std::exception & e)
343 BOOST_REQUIRE_EQUAL(e.what(),
"Runtime grid error");
345 BOOST_REQUIRE_EQUAL(error,
true);
351 catch (std::exception & e)
354 BOOST_REQUIRE_EQUAL(e.what(),
"Runtime grid error");
356 BOOST_REQUIRE_EQUAL(error,
true);
360 {g.set(keyGood,g2,keyOut);}
361 catch (std::exception & e)
364 BOOST_REQUIRE_EQUAL(e.what(),
"Runtime grid error");
366 BOOST_REQUIRE_EQUAL(error,
true);
372 {g.get<p::x>(keyNeg);}
373 catch (std::exception & e)
376 BOOST_REQUIRE_EQUAL(e.what(),
"Runtime grid error");
378 BOOST_REQUIRE_EQUAL(error,
true);
384 catch (std::exception & e)
387 BOOST_REQUIRE_EQUAL(e.what(),
"Runtime grid error");
389 BOOST_REQUIRE_EQUAL(error,
true);
393 {g.set(keyGood,g2,keyNeg);}
394 catch (std::exception & e)
397 BOOST_REQUIRE_EQUAL(e.what(),
"Runtime grid error");
399 BOOST_REQUIRE_EQUAL(error,
true);
404BOOST_AUTO_TEST_CASE( grid_set_prp_check )
406 size_t szz[2] = {8,8};
416 c2.template get<1>(k1) = 5.0;
418 c1.template set<1>(k1,c2,k1);
420 BOOST_REQUIRE_EQUAL(c1.template get<1>(k1),5.0);
423BOOST_AUTO_TEST_CASE( grid_use)
428 std::cout <<
"Grid unit test start" <<
"\n";
430 size_t sz[3] = {GS_SIZE,GS_SIZE,GS_SIZE};
437#ifndef TEST_COVERAGE_MODE
441 test_all_grid<5>(18);
442 test_all_grid<4>(37);
443 test_all_grid<3>(126);
444 test_all_grid<2>(1414);
445 test_all_grid<1>(2000000);
460 test_all_grid<2>(16);
461 test_all_grid<1>(256);
466 for (
int i = 0 ; i <= GS_SIZE ; i++)
475 test_layout_grid3d(c3,i);
482 test_layout_grid3d(c3,i);}
489 test_layout_grid3d(c3,i);}
495 test_layout_grid3d(c3,i);}
499 std::cout <<
"Grid unit test end" <<
"\n";
502BOOST_AUTO_TEST_CASE( grid_use_smb)
507 std::cout <<
"Grid smb unit test start" <<
"\n";
509 size_t sz[3] = {GS_SIZE,GS_SIZE,GS_SIZE};
514 for (
int i = 0 ; i <= GS_SIZE ; i+=4)
523 test_layout_grid3d(c3,i);
530 test_layout_grid3d(c3,i);}
537 test_layout_grid3d(c3,i);}
543 test_layout_grid3d(c3,i);}
547 std::cout <<
"Grid unit test end" <<
"\n";
550BOOST_AUTO_TEST_CASE( grid_use_zmb)
555 std::cout <<
"Grid zmb unit test start" <<
"\n";
557 size_t sz[3] = {GS_SIZE,GS_SIZE,GS_SIZE};
561 for (
int i = 4 ; i <= GS_SIZE ; i*=2)
570 test_layout_grid3d(c3,i);
577 test_layout_grid3d(c3,i);}
584 test_layout_grid3d(c3,i);}
590 test_layout_grid3d(c3,i);}
594 std::cout <<
"Grid unit test end" <<
"\n";
603BOOST_AUTO_TEST_CASE( C_array_test )
608 std::cout <<
"Grid size known at runtime" <<
"\n";
609 std::cout <<
"1D Array with index calculation: " <<
"\n";
614 int gs_sq = GS_SIZE*GS_SIZE;
622 for (
int i = 0 ; i < GS_SIZE ; i++)
624 for (
int j = 0 ; j < GS_SIZE ; j++)
626 for (
int k = 0 ; k < GS_SIZE ; k++)
628 pA[i*gs_sq+j*gs+k].x = 1.1f;
629 pA[i*gs_sq+j*gs+k].y = 1.2f;
630 pA[i*gs_sq+j*gs+k].z = 1.3f;
631 pA[i*gs_sq+j*gs+k].s = 1.0f;
633 pA[i*gs_sq+j*gs+k].v[0] = 1.0f;
634 pA[i*gs_sq+j*gs+k].v[1] = 2.0f;
635 pA[i*gs_sq+j*gs+k].v[2] = 3.0f;
637 pA[i*gs_sq+j*gs+k].t[0][0] = 1.0f;
638 pA[i*gs_sq+j*gs+k].t[0][1] = 2.0f;
639 pA[i*gs_sq+j*gs+k].t[0][2] = 3.0f;
640 pA[i*gs_sq+j*gs+k].t[1][0] = 4.0f;
641 pA[i*gs_sq+j*gs+k].t[1][1] = 5.0f;
642 pA[i*gs_sq+j*gs+k].t[1][2] = 6.0f;
643 pA[i*gs_sq+j*gs+k].t[2][0] = 7.0f;
644 pA[i*gs_sq+j*gs+k].t[2][1] = 8.0f;
645 pA[i*gs_sq+j*gs+k].t[2][2] = 9.0f;
655 std::cout <<
"End : " << GS_SIZE*GS_SIZE*GS_SIZE*16*4/1024/1024 <<
" MB " <<
" Bandwidth: " << GS_SIZE*GS_SIZE*GS_SIZE*16*4/1024/1024/t.
getcputime() <<
" MB/s \n";
659BOOST_AUTO_TEST_CASE(grid_operator_equal)
663 size_t sz[] = {16,16};
670 auto it = g1.getIterator();
676 g1.get<b::p1>(key)[0] = key.get(0);
677 g1.get<b::p2>(key)[1] = key.get(1);
687 bool ret = (g2 == g1);
689 BOOST_REQUIRE_EQUAL(ret,
true);
703 auto it1 = g1.getIterator();
707 auto key = it1.get();
709 g1.get<b::p1>(key)[0] = key.get(0);
710 g1.get<b::p2>(key)[1] = key.get(1);
715 auto it2 = g2.getIterator();
719 auto key = it2.get();
721 g2.get<b::p1>(key)[0] = key.get(0);
722 g2.get<b::p2>(key)[1] = key.get(1);
730BOOST_AUTO_TEST_CASE(grid_operator_swap)
732 size_t sz1[] = {16,16};
733 size_t sz2[] = {5,5};
744 fill_2_grid_data(g1_old,g2_old);
745 fill_2_grid_data(g1,g2);
753 bool ret = (g2 == g1_old);
754 BOOST_REQUIRE_EQUAL(ret,
true);
755 ret = (g1 == g2_old);
756 BOOST_REQUIRE_EQUAL(ret,
true);
759BOOST_AUTO_TEST_CASE(grid_resize_less)
761 size_t sz1[] = {256,256};
762 size_t sz2[] = {5,5};
767 fill_2_grid_data(g1,g1);
772 BOOST_REQUIRE_EQUAL(g1.size(),25ul);
775BOOST_AUTO_TEST_CASE(copy_encap_vector_fusion_test)
777 size_t sz2[] = {5,5};
786 g.template get<0>(key) = 1.0;
788 g.template get<1>(key)[0] = 2.0;
789 g.template get<1>(key)[1] = 3.0;
790 g.template get<1>(key)[2] = 4.0;
792 g.template get<2>(key)[0][0] = 5.0;
793 g.template get<2>(key)[0][1] = 6.0;
794 g.template get<2>(key)[0][2] = 7.0;
795 g.template get<2>(key)[1][0] = 8.0;
796 g.template get<2>(key)[1][1] = 9.0;
797 g.template get<2>(key)[1][2] = 10.0;
798 g.template get<2>(key)[2][0] = 11.0;
799 g.template get<2>(key)[2][1] = 12.0;
800 g.template get<2>(key)[2][2] = 13.0;
802 auto ge = g.get_o(key);
804 boost::mpl::for_each_ref< boost::mpl::range_c<int,0,aggregate<float,float[3],float[3][3]>::max_prop> >(cp);
808 BOOST_REQUIRE_EQUAL(g.template get<0>(key),g.template get<0>(key1));
810 BOOST_REQUIRE_EQUAL(g.template get<1>(key)[0],g.template get<1>(key1)[0]);
811 BOOST_REQUIRE_EQUAL(g.template get<1>(key)[1],g.template get<1>(key1)[1]);
812 BOOST_REQUIRE_EQUAL(g.template get<1>(key)[2],g.template get<1>(key1)[2]);
814 BOOST_REQUIRE_EQUAL(g.template get<2>(key)[0][0],g.template get<2>(key1)[0][0]);
815 BOOST_REQUIRE_EQUAL(g.template get<2>(key)[0][1],g.template get<2>(key1)[0][1]);
816 BOOST_REQUIRE_EQUAL(g.template get<2>(key)[0][2],g.template get<2>(key1)[0][2]);
817 BOOST_REQUIRE_EQUAL(g.template get<2>(key)[1][0],g.template get<2>(key1)[1][0]);
818 BOOST_REQUIRE_EQUAL(g.template get<2>(key)[1][1],g.template get<2>(key1)[1][1]);
819 BOOST_REQUIRE_EQUAL(g.template get<2>(key)[1][2],g.template get<2>(key1)[1][2]);
820 BOOST_REQUIRE_EQUAL(g.template get<2>(key)[2][0],g.template get<2>(key1)[2][0]);
821 BOOST_REQUIRE_EQUAL(g.template get<2>(key)[2][1],g.template get<2>(key1)[2][1]);
822 BOOST_REQUIRE_EQUAL(g.template get<2>(key)[2][2],g.template get<2>(key1)[2][2]);
826BOOST_AUTO_TEST_CASE(grid_test_copy_to)
828 size_t sz_dst[] = {5,5};
829 size_t sz_src[] = {3,2};
836 copy_test(g_src,g_dst,box_src,box_dst);
840BOOST_AUTO_TEST_SUITE_END()
This class represent an N-dimensional box.
Definition of a class Point in plain C++ and boost::vector for testing purpose.
Test structure used for several test.
const grid_key_dx< dim > & get() const
Get the actual key.
bool isNext()
Check if there is the next element.
grid_key_dx is the key to access any element in the grid
__device__ __host__ void set(a v, T...t)
set the Key from a list of numbers
Class for cpu time benchmarking.
void stop()
Stop the timer.
double getcputime()
Return the cpu time.
void start()
Start the timer.
double getwct()
Return the elapsed real time.
aggregate of properties, from a list of object if create a struct that follow the OPENFPM native stru...
boost::fusion::vector< list... > type
internal type containing the data
this class is a functor for "for_each" algorithm
It model an expression expr1 * expr2.