8 #ifndef SRC_PACKER_NESTED_TESTS_HPP_ 9 #define SRC_PACKER_NESTED_TESTS_HPP_ 11 #include "Pack_selector.hpp" 13 #include "Unpacker.hpp" 14 #include "Grid/grid_util_test.hpp" 16 #include "data_type/aggregate.hpp" 27 BOOST_AUTO_TEST_SUITE( packer_unpacker )
29 BOOST_AUTO_TEST_CASE ( vector_ptst_packer_unpacker )
31 std::cout <<
"Vector pack/unpack test start" <<
"\n";
34 for (
size_t i = 0; i < 5; i++) {
36 for (
size_t j = 0; j < 6; j++) {
49 BOOST_REQUIRE_EQUAL(req, ((((
sizeof(
float) +
sizeof(
float[3]))*7) + 8)*6 + 8)*5 + 8 );
70 for (
size_t k = 0; k < v_unp.
size(); k++)
72 for (
size_t i = 0; i < v_unp.get(k).
size(); i++)
74 auto it = v_unp.get(k).get(i).getIterator();
78 float f1 = v_unp.get(k).get(i).template get<pt::x>(it.get());
79 float f2 = v.get(k).get(i).template get<pt::x>(it.get());
81 BOOST_REQUIRE_EQUAL(f1,f2);
83 for (
size_t j = 0 ; j < 3 ; j++)
85 f1 = v_unp.get(k).get(i).template get<pt::v>(it.get())[j];
86 f2 = v.get(k).get(i).template get<pt::v>(it.get())[j];
88 BOOST_REQUIRE_EQUAL(f1,f2);
99 BOOST_AUTO_TEST_CASE ( vector_std_packer_unpacker )
102 for (
size_t i = 0; i < 5; i++) {
104 for (
size_t j = 0; j < 6; j++) {
106 for (
size_t k = 0; k < 7; k++) {
119 BOOST_REQUIRE_EQUAL(req,(((
sizeof(
float)*7) + 8)*6 + 8)*5 + 8);
142 for (
size_t k = 0; k < v2_unp.
size(); k++)
144 for (
size_t i = 0; i < v2_unp.get(k).
size(); i++)
146 for (
size_t j = 0; j < v2_unp.get(k).get(i).
size(); j++)
148 float f1 = v2_unp.get(k).get(i).get(j);
149 float f2 = v2.get(k).get(i).get(j);
151 BOOST_REQUIRE_EQUAL(f1,f2);
160 BOOST_AUTO_TEST_CASE ( vector_zerosize_packer_unpacker )
163 for (
size_t i = 0; i < 5; i++) {
165 for (
size_t j = 0; j < 6; j++) {
171 for (
size_t j = 0; j < 5; j++) {
184 BOOST_REQUIRE_EQUAL(req,(((((
sizeof(
float) +
sizeof(
float[3]))*7) + 8)*6 + 8)*5 + 8) + (((((
sizeof(
float) +
sizeof(
float[3]))*7) + 8)*5 + 8) + 8));
205 for (
size_t k = 0; k < v5_unp.
size(); k++)
207 for (
size_t i = 0; i < v5_unp.get(k).
size(); i++)
209 auto it = v5_unp.get(k).get(i).getIterator();
213 float f1 = v5_unp.get(k).get(i).template get<pt::x>(it.get());
214 float f2 = v5.get(k).get(i).template get<pt::x>(it.get());
216 BOOST_REQUIRE_EQUAL(f1,f2);
218 for (
size_t j = 0 ; j < 3 ; j++)
220 f1 = v5_unp.get(k).get(i).template get<pt::v>(it.get())[j];
221 f2 = v5.get(k).get(i).template get<pt::v>(it.get())[j];
223 BOOST_REQUIRE_EQUAL(f1,f2);
234 BOOST_AUTO_TEST_CASE ( vector_zerosize__lvl_2_packer_unpacker )
237 for (
size_t i = 0; i < 5; i++) {
239 for (
size_t j = 0; j < 6; j++) {
255 BOOST_REQUIRE_EQUAL(req,(((((
sizeof(
float) +
sizeof(
float[3]))*7) + 8)*6 + 8)*5 + 8) + 8);
276 BOOST_REQUIRE_EQUAL(v5_unp.
size(),v5.
size());
277 for (
size_t k = 0; k < v5_unp.
size(); k++)
279 BOOST_REQUIRE_EQUAL(v5_unp.get(k).
size(),v5.get(k).
size());
280 for (
size_t i = 0; i < v5_unp.get(k).
size(); i++)
282 BOOST_REQUIRE_EQUAL(v5_unp.get(k).get(i).
size(),v5.get(k).get(i).
size());
283 auto it = v5_unp.get(k).get(i).getIterator();
287 float f1 = v5_unp.get(k).get(i).template get<pt::x>(it.get());
288 float f2 = v5.get(k).get(i).template get<pt::x>(it.get());
290 BOOST_REQUIRE_EQUAL(f1,f2);
292 for (
size_t j = 0 ; j < 3 ; j++)
294 f1 = v5_unp.get(k).get(i).template get<pt::v>(it.get())[j];
295 f2 = v5.get(k).get(i).template get<pt::v>(it.get())[j];
297 BOOST_REQUIRE_EQUAL(f1,f2);
309 BOOST_AUTO_TEST_CASE ( vector_zerosize__lvl_2_packer_unpacker_float )
312 for (
size_t i = 0; i < 5; i++) {
314 for (
size_t j = 0; j < 6; j++) {
316 for (
size_t k = 0; k < 7; k++) {
331 BOOST_REQUIRE_EQUAL(req,((((
sizeof(
float)*7) + 8)*6 + 8)*4 + 8) + 8);
354 for (
size_t k = 0; k < v2_unp.
size(); k++)
356 for (
size_t i = 0; i < v2_unp.get(k).
size(); i++)
358 for (
size_t j = 0; j < v2_unp.get(k).get(i).
size(); j++)
360 float f1 = v2_unp.get(k).get(i).get(j);
361 float f2 = v2.get(k).get(i).get(j);
363 BOOST_REQUIRE_EQUAL(f1,f2);
372 BOOST_AUTO_TEST_CASE ( vector_box_packer_unpacker )
389 for (
size_t i = 0; i < v.size(); i++)
392 for (
size_t j = 0; j < v.get(i).size(); j++)
394 v.get(i).get(j) = bx;
402 BOOST_REQUIRE_EQUAL(req,((
sizeof(
float)*6) * 5 + 8) * 4 + 8);
424 for (
size_t i = 0; i < v.size(); i++)
426 for (
size_t j = 0; j < v.get(i).size(); j++)
430 BOOST_REQUIRE(b1 == b2);
438 BOOST_AUTO_TEST_CASE ( vector_std_smarter_packer_unpacker )
447 for (
size_t i = 0; i < v.size(); i++)
450 for (
size_t j = 0; j < v.get(i).size(); j++)
452 v.get(i).get(j).i = 1;
453 v.get(i).get(j).j = 2;
454 v.get(i).get(j).bx.setHigh(0, 3.0);
455 v.get(i).get(j).bx.setHigh(1, 4.0);
456 v.get(i).get(j).bx.setHigh(2, 5.0);
457 v.get(i).get(j).bx.setLow(0, 6.0);
458 v.get(i).get(j).bx.setLow(1, 7.0);
459 v.get(i).get(j).bx.setLow(2, 8.0);
468 BOOST_REQUIRE_EQUAL(req,((
sizeof(
float)*6 +
sizeof(
size_t)*2) * 5 + 8) * 4 + 8);
490 for (
size_t i = 0; i < v.size(); i++)
492 for (
size_t j = 0; j < v.get(i).size(); j++)
494 float s1 = v_unp.get(i).get(j).i;
495 float s2 = v.get(i).get(j).i;
496 float s3 = v_unp.get(i).get(j).j;
497 float s4 = v.get(i).get(j).j;
499 BOOST_REQUIRE_EQUAL(s1,s2);
500 BOOST_REQUIRE_EQUAL(s3,s4);
504 BOOST_REQUIRE(b1 == b2);
512 BOOST_AUTO_TEST_CASE ( vector_smarter_packer_unpacker )
522 for (
size_t i = 0 ; i < v4.
size() ; i++)
525 for (
size_t j = 0 ; j < v4.get(i).
size() ; j++)
527 v4.get(i).template get<0>(j) = 1.0;
528 v4.get(i).template get<1>(j) = 2.0;
529 v4.get(i).template get<2>(j).resize(2);
531 for (
size_t k = 0 ; k < v4.get(i).template get<2>(j).
size() ; k++)
532 v4.get(i).template get<2>(j).get(k) = p;
542 BOOST_REQUIRE_EQUAL(req,(((((
sizeof(
float)*4 +
sizeof(
float[3]) +
sizeof(
float[3][3]))*2 + 8) +
sizeof(
float)*2) * 4 + 8) * 3 + 8));
567 for (
size_t i = 0 ; i < v4.
size() ; i++)
569 for (
size_t j = 0 ; j < v4.get(i).
size() ; j++)
571 float f1 = v4_unp.get(i).template get<0>(j);
572 float f2 = v4.get(i).template get<0>(j);
573 float f3 = v4_unp.get(i).template get<1>(j);
574 float f4 = v4.get(i).template get<1>(j);
576 BOOST_REQUIRE_EQUAL(f1,f2);
577 BOOST_REQUIRE_EQUAL(f3,f4);
579 for (
size_t k = 0 ; k < v4.get(i).template get<2>(j).
size() ; k++)
584 BOOST_REQUIRE(p1 == p2);
593 BOOST_AUTO_TEST_CASE ( vector_smarter_packer_unpacker_2 )
602 for (
size_t i = 0 ; i < v4.
size() ; i++)
604 v4.get(i).resize(50);
605 for (
size_t j = 0 ; j < v4.get(i).
size() ; j++)
607 v4.get(i).template get<0>(j) = 1.0;
608 v4.get(i).template get<1>(j) = 2.0;
609 v4.get(i).template get<2>(j) = p;
610 v4.get(i).template get<3>(j) = p;
611 v4.get(i).template get<4>(j) = p;
612 v4.get(i).template get<5>(j) = p;
613 v4.get(i).template get<6>(j) = p;
614 v4.get(i).template get<7>(j) = p;
615 v4.get(i).template get<8>(j) = p;
625 BOOST_REQUIRE_EQUAL(req,((
sizeof(
float)*4 +
sizeof(
float[3]) +
sizeof(
float[3][3]))*7 +
sizeof(
float)*2) * 50 +
sizeof(
size_t)*2);
649 for (
size_t i = 0; i < v4.
size(); i++)
651 for (
size_t j = 0; j < v4.get(i).
size(); j++)
653 float f1 = v4_unp.get(i).template get<0>(j);
654 float f2 = v4.get(i).template get<0>(j);
655 float f3 = v4_unp.get(i).template get<1>(j);
656 float f4 = v4.get(i).template get<1>(j);
658 BOOST_REQUIRE_EQUAL(f1,f2);
659 BOOST_REQUIRE_EQUAL(f3,f4);
664 BOOST_REQUIRE(p1 == p2);
666 p1 = v4_unp.get(i).template get<3>(j);
667 p2 = v4.get(i).template get<3>(j);
669 BOOST_REQUIRE(p1 == p2);
671 p1 = v4_unp.get(i).template get<4>(j);
672 p2 = v4.get(i).template get<4>(j);
674 BOOST_REQUIRE(p1 == p2);
676 p1 = v4_unp.get(i).template get<5>(j);
677 p2 = v4.get(i).template get<5>(j);
679 BOOST_REQUIRE(p1 == p2);
681 p1 = v4_unp.get(i).template get<6>(j);
682 p2 = v4.get(i).template get<6>(j);
684 BOOST_REQUIRE(p1 == p2);
686 p1 = v4_unp.get(i).template get<7>(j);
687 p2 = v4.get(i).template get<7>(j);
689 BOOST_REQUIRE(p1 == p2);
691 p1 = v4_unp.get(i).template get<8>(j);
692 p2 = v4.get(i).template get<8>(j);
694 BOOST_REQUIRE(p1 == p2);
702 BOOST_AUTO_TEST_CASE ( vector_smarter_packer_unpacker_3 )
712 for (
size_t i = 0 ; i < v.size() ; i++)
714 v.template get<1>(i).resize(2);
716 for (
size_t k = 0 ; k < v.template get<1>(i).size() ; k++)
717 v.template get<1>(i).get(k) = p;
750 for (
size_t i = 0; i < v.size(); i++)
752 for (
size_t j = 0 ; j < v.template get<1>(i).size() ; j++)
757 BOOST_REQUIRE(p1 == p2);
765 BOOST_AUTO_TEST_CASE ( vector_aggr_packer_unpacker_zero_prop )
774 for (
size_t i = 0 ; i < v4.
size() ; i++)
776 v4.template get<0>(i) = 1.0;
777 v4.template get<1>(i) = 2.0;
787 BOOST_REQUIRE_EQUAL(req, 3*(
sizeof(
float)*2)+8);
791 BOOST_REQUIRE_EQUAL(req2, 3*(
sizeof(
float)*2)+8);
829 for (
size_t i = 0 ; i < v4.
size() ; i++)
831 float f1 = v4_unp.template get<0>(i);
832 float f2 = v4.template get<0>(i);
833 float f3 = v4_unp.template get<1>(i);
834 float f4 = v4.template get<1>(i);
836 BOOST_REQUIRE_EQUAL(f1,f2);
837 BOOST_REQUIRE_EQUAL(f3,f4);
840 for (
size_t i = 0 ; i < v4.
size() ; i++)
842 float f1 = v4_unp_2.template get<0>(i);
843 float f2 = v4.template get<0>(i);
844 float f3 = v4_unp_2.template get<1>(i);
845 float f4 = v4.template get<1>(i);
847 BOOST_REQUIRE_EQUAL(f1,f2);
848 BOOST_REQUIRE_EQUAL(f3,f4);
855 BOOST_AUTO_TEST_CASE ( vector_aggr_packer_unpacker_zero_prop_2 )
864 for (
size_t i = 0 ; i < v4.
size() ; i++)
866 v4.template get<0>(i) = 1.0;
867 v4.template get<1>(i).add(5);
868 v4.template get<1>(i).add(6);
877 BOOST_REQUIRE_EQUAL(req, 3*(
sizeof(
float)*3 + 8)+8);
881 BOOST_REQUIRE_EQUAL(req2, 3*(
sizeof(
float)*3 + 8)+8);
919 for (
size_t i = 0 ; i < v4.
size() ; i++)
921 float f1 = v4_unp.template get<0>(i);
922 float f2 = v4.template get<0>(i);
924 BOOST_REQUIRE_EQUAL(f1,f2);
926 for (
size_t j = 0; j < v4.template get<1>(i).
size(); j++)
928 float f3 = v4_unp.template get<1>(i).get(j);
929 float f4 = v4.template get<1>(i).get(j);
931 BOOST_REQUIRE_EQUAL(f3,f4);
935 for (
size_t i = 0 ; i < v4.
size() ; i++)
937 float f1 = v4_unp_2.template get<0>(i);
938 float f2 = v4.template get<0>(i);
940 BOOST_REQUIRE_EQUAL(f1,f2);
942 for (
size_t j = 0; j < v4.template get<1>(i).
size(); j++)
944 float f3 = v4_unp_2.template get<1>(i).get(j);
945 float f4 = v4.template get<1>(i).get(j);
947 BOOST_REQUIRE_EQUAL(f3,f4);
954 std::cout <<
"Vector pack/unpack test stop" <<
"\n";
957 BOOST_AUTO_TEST_CASE ( grid_ptst_packer_unpacker )
959 std::cout <<
"Grid pack/unpack test start" <<
"\n";
961 size_t sz[] = {16,16,16};
973 BOOST_REQUIRE_EQUAL(req,(
sizeof(
float) +
sizeof(
float[3])) * 16 * 16 * 16 +
sizeof(
size_t)*3);
997 auto it = g_unp.getIterator();
1001 float f1 = g_unp.template get<pt::x>(it.get());
1002 float f2 = g.template get<pt::x>(it.get());
1004 BOOST_REQUIRE_EQUAL(f1,f2);
1006 for (
size_t i = 0 ; i < 3 ; i++)
1008 f1 = g_unp.template get<pt::v>(it.get())[i];
1009 f2 = g.template get<pt::v>(it.get())[i];
1011 BOOST_REQUIRE_EQUAL(f1,f2);
1023 template <
unsigned int dim>
1028 auto key_it = g.getIterator();
1030 while (key_it.isNext())
1032 auto kk = key_it.get();
1034 g.template get<0>(kk) = 1;
1035 g.template get<1>(kk) = 2;
1036 g.template get<2>(kk) = 3;
1037 g.template get<3>(kk) = 4;
1038 g.template get<4>(kk) = 5;
1047 for (
size_t i = 0 ; i < dim ; i++)
1052 Packer<
typename std::remove_reference<decltype(g)>::type,
HeapMemory>::template packRequest<>(g,req);
1054 BOOST_REQUIRE_EQUAL(req,(
sizeof(
float))* 5 * sz_tot +
sizeof(
size_t)*dim);
1066 Packer<
typename std::remove_reference<decltype(g)>::type,
HeapMemory>::template pack<>(mem,g,sts);
1077 auto it = g_unp.getIterator();
1081 float f1 = g_unp.template get<0>(it.get());
1082 float f2 = g.template get<0>(it.get());
1084 BOOST_REQUIRE_EQUAL(f1,f2);
1086 f1 = g_unp.template get<1>(it.get());
1087 f2 = g.template get<1>(it.get());
1089 BOOST_REQUIRE_EQUAL(f1,f2);
1091 f1 = g_unp.template get<2>(it.get());
1092 f2 = g.template get<2>(it.get());
1094 BOOST_REQUIRE_EQUAL(f1,f2);
1096 f1 = g_unp.template get<3>(it.get());
1097 f2 = g.template get<3>(it.get());
1099 BOOST_REQUIRE_EQUAL(f1,f2);
1101 f1 = g_unp.template get<4>(it.get());
1102 f2 = g.template get<4>(it.get());
1104 BOOST_REQUIRE_EQUAL(f1,f2);
1114 BOOST_AUTO_TEST_CASE ( grid_aggr_packer_unpacker_3D )
1116 size_t sz[] = {64,4,16};
1119 test_packer_aggr_smp<3>(g,sz);
1122 BOOST_AUTO_TEST_CASE ( grid_aggr_packer_unpacker_2D )
1124 size_t sz[] = {64,4};
1127 test_packer_aggr_smp<2>(g,sz);
1130 BOOST_AUTO_TEST_CASE ( grid_aggr_packer_unpacker_4D )
1132 size_t sz[] = {64,4,3,3};
1135 test_packer_aggr_smp<4>(g,sz);
1138 template <
unsigned int dim>
1147 auto key_it = g.getIterator();
1149 while (key_it.isNext())
1151 auto kk = key_it.get();
1153 g.template get<0>(kk) = 1;
1154 g.template get<1>(kk) = 2;
1155 g.template get<2>(kk) = g2;
1166 for (
size_t i = 0 ; i < dim ; i++)
1173 BOOST_REQUIRE_EQUAL(req,(sz_tot*(
sizeof(
float) + sz2_tot * 64 +
sizeof(
size_t)*dim) +
sizeof(
size_t)*dim));
1198 auto it = g_unp.getIterator();
1202 float f1 = g_unp.template get<1>(it.get());
1203 float f2 = g.template get<1>(it.get());
1204 BOOST_REQUIRE_EQUAL(f1,f2);
1207 auto g_unp_1 = g_unp.template get<2>(it.get());
1208 auto g_unp_2 = g.template get<2>(it.get());
1210 auto it_unp = g_unp_1.getIterator();
1213 float x1 = g_unp_1.template get<pt::x>(it_unp.get());
1214 float y1 = g_unp_1.template get<pt::y>(it_unp.get());
1215 float z1 = g_unp_1.template get<pt::z>(it_unp.get());
1216 float s1 = g_unp_1.template get<pt::s>(it_unp.get());
1218 float x2 = g_unp_2.template get<pt::x>(it_unp.get());
1219 float y2 = g_unp_2.template get<pt::y>(it_unp.get());
1220 float z2 = g_unp_2.template get<pt::z>(it_unp.get());
1221 float s2 = g_unp_2.template get<pt::s>(it_unp.get());
1223 BOOST_REQUIRE_EQUAL(x1,x2);
1224 BOOST_REQUIRE_EQUAL(y1,y2);
1225 BOOST_REQUIRE_EQUAL(z1,z2);
1226 BOOST_REQUIRE_EQUAL(s1,s2);
1228 for (
size_t i = 0 ; i < 3 ; i++)
1230 float v1 = g_unp_1.template get<pt::v>(it_unp.get())[i];
1231 float v2 = g_unp_2.template get<pt::v>(it_unp.get())[i];
1232 BOOST_REQUIRE_EQUAL(v1,v2);
1235 for (
size_t i = 0 ; i < 3 ; i++)
1237 for (
size_t j = 0 ; j < 3 ; j++)
1239 float t1 = g_unp_1.template get<pt::t>(it_unp.get())[i][j];
1240 float t2 = g_unp_2.template get<pt::t>(it_unp.get())[i][j];
1241 BOOST_REQUIRE_EQUAL(
t1,
t2);
1255 std::cout <<
"Grid pack/unpack test stop " << dim <<
"D" <<
"\n";
1258 BOOST_AUTO_TEST_CASE ( grid_aggr_grid_packer_unpacker_3D )
1260 size_t sz[] = {8,7,5};
1261 size_t sz2[] = {2,4,13};
1265 test_packer_aggr_nd<3>(g2,sz,sz2);
1271 BOOST_AUTO_TEST_CASE ( grid_aggr_grid_packer_unpacker_2D )
1273 size_t sz[] = {8,7};
1274 size_t sz2[] = {2,4};
1278 test_packer_aggr_nd<2>(g2,sz,sz2);
1281 BOOST_AUTO_TEST_CASE ( grid_aggr_grid_packer_unpacker_4D )
1283 size_t sz[] = {8,7,2,2};
1284 size_t sz2[] = {2,4,2,2};
1288 test_packer_aggr_nd<4>(g2,sz,sz2);
1291 BOOST_AUTO_TEST_SUITE_END()
This class allocate, and destroy CPU memory.
__device__ __host__ void setHigh(int i, T val)
set the high interval of the box
It model an expression expr1 * expr2.
__device__ __host__ void setLow(int i, T val)
set the low interval of the box
virtual void incRef()
Increment the reference counter.
virtual void decRef()
Decrement the reference counter.
aggregate of properties, from a list of object if create a struct that follow the OPENFPM native stru...
Test structure used for several test.
Implementation of 1-D std::vector like structure.