OpenFPM_pdata  4.1.0
Project that contain the implementation of distributed structures
 
Loading...
Searching...
No Matches
Packer_nested_tests.hpp
1
8#ifndef SRC_PACKER_NESTED_TESTS_HPP_
9#define SRC_PACKER_NESTED_TESTS_HPP_
10
11#include "Pack_selector.hpp"
12#include "Packer.hpp"
13#include "Unpacker.hpp"
14#include "Grid/grid_util_test.hpp"
15#include <iostream>
16#include "data_type/aggregate.hpp"
17
19{
20 size_t i;
21 size_t j;
22 Box<3,float> bx;
23};
24
25//Testing packing and unpacking for different vectors
26
27BOOST_AUTO_TEST_SUITE( packer_unpacker )
28
29BOOST_AUTO_TEST_CASE ( vector_ptst_packer_unpacker )
30{
31 std::cout << "Vector pack/unpack test start" << "\n";
32
34 for (size_t i = 0; i < 5; i++) {
36 for (size_t j = 0; j < 6; j++) {
37 v4.add(allocate_openfpm<openfpm::vector<Point_test<float>>>(7));
38 }
39 v.add(v4);
40 }
41
42 typedef Point_test<float> pt;
43
44 size_t req = 0;
45
46 //Pack requesting
47
48 Packer<decltype(v),HeapMemory>::packRequest<pt::x, pt::v>(v,req);
49 BOOST_REQUIRE_EQUAL(req, ((((sizeof(float) + sizeof(float[3]))*7) + 8)*6 + 8)*5 + 8 );
50
51 // allocate the memory
52 HeapMemory pmem;
53 //pmem.allocate(req);
54 ExtPreAlloc<HeapMemory> & mem = *(new ExtPreAlloc<HeapMemory>(req,pmem));
55 mem.incRef();
56
57 //Packing
58 Pack_stat sts;
59
60 Packer<decltype(v),HeapMemory>::pack<pt::x,pt::v>(mem,v,sts);
61
62 //Unpacking
63 Unpack_stat ps;
64
66
67 Unpacker<decltype(v_unp),HeapMemory>::unpack<pt::x,pt::v>(mem,v_unp,ps);
68
69 //Check equality vector v_unp
70 for (size_t k = 0; k < v_unp.size(); k++)
71 {
72 for (size_t i = 0; i < v_unp.get(k).size(); i++)
73 {
74 auto it = v_unp.get(k).get(i).getIterator();
75
76 while (it.isNext())
77 {
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());
80
81 BOOST_REQUIRE_EQUAL(f1,f2);
82
83 for (size_t j = 0 ; j < 3 ; j++)
84 {
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];
87
88 BOOST_REQUIRE_EQUAL(f1,f2);
89 }
90 ++it;
91 }
92 }
93 }
94
95 mem.decRef();
96 delete &mem;
97}
98
99BOOST_AUTO_TEST_CASE ( vector_std_packer_unpacker )
100{
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++) {
107 v7.add(1);
108 }
109 v6.add(v7);
110 }
111 v2.add(v6);
112 }
113
114 //Pack requesting
115
116 size_t req = 0;
117
118 Packer<decltype(v2),HeapMemory>::packRequest<>(v2,req);
119 BOOST_REQUIRE_EQUAL(req,(((sizeof(float)*7) + 8)*6 + 8)*5 + 8);
120
121 // allocate the memory
122 HeapMemory pmem;
123 //pmem.allocate(req);
124 ExtPreAlloc<HeapMemory> & mem = *(new ExtPreAlloc<HeapMemory>(req,pmem));
125 mem.incRef();
126
127 //Packing
128
129 Pack_stat sts;
130
131 Packer<decltype(v2),HeapMemory>::pack<>(mem,v2,sts);
132
133 //Unpacking
134
135 Unpack_stat ps;
136
138
139 Unpacker<decltype(v2_unp),HeapMemory>::unpack<>(mem,v2_unp,ps);
140
141 //Check equality vector v2_unp
142 for (size_t k = 0; k < v2_unp.size(); k++)
143 {
144 for (size_t i = 0; i < v2_unp.get(k).size(); i++)
145 {
146 for (size_t j = 0; j < v2_unp.get(k).get(i).size(); j++)
147 {
148 float f1 = v2_unp.get(k).get(i).get(j);
149 float f2 = v2.get(k).get(i).get(j);
150
151 BOOST_REQUIRE_EQUAL(f1,f2);
152 }
153 }
154 }
155
156 mem.decRef();
157 delete &mem;
158}
159
160BOOST_AUTO_TEST_CASE ( vector_zerosize_packer_unpacker )
161{
163 for (size_t i = 0; i < 5; i++) {
165 for (size_t j = 0; j < 6; j++) {
166 v4.add(allocate_openfpm<openfpm::vector<Point_test<float>>>(7));
167 }
168 v5.add(v4);
169 }
171 for (size_t j = 0; j < 5; j++) {
172 v51.add(allocate_openfpm<openfpm::vector<Point_test<float>>>(7));
173 }
174 v51.add(allocate_openfpm<openfpm::vector<Point_test<float>>>(0));
175
176 v5.add(v51);
177
178 typedef Point_test<float> pt;
179
180 size_t req = 0;
181
182 //Pack requesting
183 Packer<decltype(v5),HeapMemory>::packRequest<pt::x, pt::v>(v5,req);
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));
185
186 // allocate the memory
187 HeapMemory pmem;
188 //pmem.allocate(req);
189 ExtPreAlloc<HeapMemory> & mem = *(new ExtPreAlloc<HeapMemory>(req,pmem));
190 mem.incRef();
191
192 //Packing
193 Pack_stat sts;
194
195 Packer<decltype(v5),HeapMemory>::pack<pt::x,pt::v>(mem,v5,sts);
196
197 //Unpacking
198 Unpack_stat ps;
199
201
202 Unpacker<decltype(v5_unp),HeapMemory>::unpack<pt::x,pt::v>(mem,v5_unp,ps);
203
204 //Check equality vector v5_unp
205 for (size_t k = 0; k < v5_unp.size(); k++)
206 {
207 for (size_t i = 0; i < v5_unp.get(k).size(); i++)
208 {
209 auto it = v5_unp.get(k).get(i).getIterator();
210
211 while (it.isNext())
212 {
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());
215
216 BOOST_REQUIRE_EQUAL(f1,f2);
217
218 for (size_t j = 0 ; j < 3 ; j++)
219 {
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];
222
223 BOOST_REQUIRE_EQUAL(f1,f2);
224 }
225 ++it;
226 }
227 }
228 }
229
230 mem.decRef();
231 delete &mem;
232}
233
234BOOST_AUTO_TEST_CASE ( vector_zerosize__lvl_2_packer_unpacker )
235{
237 for (size_t i = 0; i < 5; i++) {
239 for (size_t j = 0; j < 6; j++) {
240 v4.add(allocate_openfpm<openfpm::vector<Point_test<float>>>(7));
241 }
242 v5.add(v4);
243 }
245 v51.clear();
246 v5.add(v51);
247
248 typedef Point_test<float> pt;
249
250 size_t req = 0;
251
252 //Pack requesting
253 Packer<decltype(v5),HeapMemory>::packRequest<pt::x, pt::v>(v5,req);
254
255 BOOST_REQUIRE_EQUAL(req,(((((sizeof(float) + sizeof(float[3]))*7) + 8)*6 + 8)*5 + 8) + 8);
256
257 // allocate the memory
258 HeapMemory pmem;
259 //pmem.allocate(req);
260 ExtPreAlloc<HeapMemory> & mem = *(new ExtPreAlloc<HeapMemory>(req,pmem));
261 mem.incRef();
262
263 //Packing
264 Pack_stat sts;
265
266 Packer<decltype(v5),HeapMemory>::pack<pt::x,pt::v>(mem,v5,sts);
267
268 //Unpacking
269 Unpack_stat ps;
270
272
273 Unpacker<decltype(v5_unp),HeapMemory>::unpack<pt::x,pt::v>(mem,v5_unp,ps);
274
275 //Check equality vector v5_unp
276 BOOST_REQUIRE_EQUAL(v5_unp.size(),v5.size());
277 for (size_t k = 0; k < v5_unp.size(); k++)
278 {
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++)
281 {
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();
284
285 while (it.isNext())
286 {
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());
289
290 BOOST_REQUIRE_EQUAL(f1,f2);
291
292 for (size_t j = 0 ; j < 3 ; j++)
293 {
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];
296
297 BOOST_REQUIRE_EQUAL(f1,f2);
298 }
299 ++it;
300 }
301 }
302 }
303
304 mem.decRef();
305 delete &mem;
306}
307
308
309BOOST_AUTO_TEST_CASE ( vector_zerosize__lvl_2_packer_unpacker_float )
310{
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++) {
317 v7.add(1);
318 }
319 v6.add(v7);
320 }
321 v2.add(v6);
322 }
323
324 v2.get(0).clear();
325
326 size_t req = 0;
327
328 //Pack requesting
329
330 Packer<decltype(v2),HeapMemory>::packRequest<>(v2,req);
331 BOOST_REQUIRE_EQUAL(req,((((sizeof(float)*7) + 8)*6 + 8)*4 + 8) + 8);
332
333 // allocate the memory
334 HeapMemory pmem;
335 //pmem.allocate(req);
336 ExtPreAlloc<HeapMemory> & mem = *(new ExtPreAlloc<HeapMemory>(req,pmem));
337 mem.incRef();
338
339 //Packing
340
341 Pack_stat sts;
342
343 Packer<decltype(v2),HeapMemory>::pack<>(mem,v2,sts);
344
345 //Unpacking
346
347 Unpack_stat ps;
348
350
351 Unpacker<decltype(v2_unp),HeapMemory>::unpack<>(mem,v2_unp,ps);
352
353 //Check equality vector v2_unp
354 for (size_t k = 0; k < v2_unp.size(); k++)
355 {
356 for (size_t i = 0; i < v2_unp.get(k).size(); i++)
357 {
358 for (size_t j = 0; j < v2_unp.get(k).get(i).size(); j++)
359 {
360 float f1 = v2_unp.get(k).get(i).get(j);
361 float f2 = v2.get(k).get(i).get(j);
362
363 BOOST_REQUIRE_EQUAL(f1,f2);
364 }
365 }
366 }
367
368 mem.decRef();
369 delete &mem;
370}
371
372BOOST_AUTO_TEST_CASE ( vector_box_packer_unpacker )
373{
374 //Create an object
375
377
378 Box<3,float> bx;
379 bx.setHigh(0, 3.0);
380 bx.setHigh(1, 4.0);
381 bx.setHigh(2, 5.0);
382 bx.setLow(0, 6.0);
383 bx.setLow(1, 7.0);
384 bx.setLow(2, 8.0);
385
386 //Fill it with data
387
388 v.resize(4);
389 for (size_t i = 0; i < v.size(); i++)
390 {
391 v.get(i).resize(5);
392 for (size_t j = 0; j < v.get(i).size(); j++)
393 {
394 v.get(i).get(j) = bx;
395 }
396 }
397 size_t req = 0;
398
399 //Pack request
400 Packer<decltype(v),HeapMemory>::packRequest<>(v,req);
401
402 BOOST_REQUIRE_EQUAL(req,((sizeof(float)*6) * 5 + 8) * 4 + 8);
403
404 // allocate the memory
405 HeapMemory pmem;
406 //pmem.allocate(req);
407 ExtPreAlloc<HeapMemory> & mem = *(new ExtPreAlloc<HeapMemory>(req,pmem));
408 mem.incRef();
409
410 //Packing
411
412 Pack_stat sts;
413
414 Packer<decltype(v),HeapMemory>::pack<>(mem,v,sts);
415
416 //Unpacking
417
418 Unpack_stat ps;
419
421
422 Unpacker<decltype(v_unp),HeapMemory>::unpack<>(mem,v_unp,ps);
423
424 for (size_t i = 0; i < v.size(); i++)
425 {
426 for (size_t j = 0; j < v.get(i).size(); j++)
427 {
428 Box<3,float> b1 = v_unp.get(i).get(j);
429 Box<3,float> b2 = v.get(i).get(j);
430 BOOST_REQUIRE(b1 == b2);
431 }
432 }
433
434 mem.decRef();
435 delete &mem;
436}
437
438BOOST_AUTO_TEST_CASE ( vector_std_smarter_packer_unpacker )
439{
440 //Create an object
441
443
444 //Fill it with data
445
446 v.resize(4);
447 for (size_t i = 0; i < v.size(); i++)
448 {
449 v.get(i).resize(5);
450 for (size_t j = 0; j < v.get(i).size(); j++)
451 {
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);
460 }
461 }
462
463 size_t req = 0;
464
465 //Pack request
466 Packer<decltype(v),HeapMemory>::packRequest<>(v,req);
467
468 BOOST_REQUIRE_EQUAL(req,((sizeof(float)*6 + sizeof(size_t)*2) * 5 + 8) * 4 + 8);
469
470 // allocate the memory
471 HeapMemory pmem;
472 //pmem.allocate(req);
473 ExtPreAlloc<HeapMemory> & mem = *(new ExtPreAlloc<HeapMemory>(req,pmem));
474 mem.incRef();
475
476 //Packing
477
478 Pack_stat sts;
479
480 Packer<decltype(v),HeapMemory>::pack<>(mem,v,sts);
481
482 //Unpacking
483
484 Unpack_stat ps;
485
487
488 Unpacker<decltype(v_unp),HeapMemory>::unpack<>(mem,v_unp,ps);
489
490 for (size_t i = 0; i < v.size(); i++)
491 {
492 for (size_t j = 0; j < v.get(i).size(); j++)
493 {
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;
498
499 BOOST_REQUIRE_EQUAL(s1,s2);
500 BOOST_REQUIRE_EQUAL(s3,s4);
501
502 Box<3,float> b1 = v_unp.get(i).get(j).bx.getBox();
503 Box<3,float> b2 = v.get(i).get(j).bx.getBox();
504 BOOST_REQUIRE(b1 == b2);
505 }
506 }
507
508 mem.decRef();
509 delete &mem;
510}
511
512BOOST_AUTO_TEST_CASE ( vector_smarter_packer_unpacker )
513{
514 //Create an object
516
517 //Fill it with data
518
519 v4.resize(3);
521 p.fill();
522 for (size_t i = 0 ; i < v4.size() ; i++)
523 {
524 v4.get(i).resize(4);
525 for (size_t j = 0 ; j < v4.get(i).size() ; j++)
526 {
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);
530
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;
533 }
534 }
535
536 size_t req = 0;
537
538 //Pack request
539 Packer<decltype(v4),HeapMemory>::packRequest<>(v4,req);
540
541#ifndef SE_CLASS3
542 BOOST_REQUIRE_EQUAL(req,(((((sizeof(float)*4 + sizeof(float[3]) + sizeof(float[3][3]))*2 + 8) + sizeof(float)*2) * 4 + 8) * 3 + 8));
543#endif
544
545 // allocate the memory
546 HeapMemory pmem;
547 //pmem.allocate(req);
548 ExtPreAlloc<HeapMemory> & mem = *(new ExtPreAlloc<HeapMemory>(req,pmem));
549 mem.incRef();
550
551 //Packing
552
553 Pack_stat sts;
554
555 Packer<decltype(v4),HeapMemory>::pack<>(mem,v4,sts);
556
557 //Unpacking
558
559 Unpack_stat ps;
560
562
563 Unpacker<decltype(v4_unp),HeapMemory>::unpack<>(mem,v4_unp,ps);
564
565 //Check the data
566
567 for (size_t i = 0 ; i < v4.size() ; i++)
568 {
569 for (size_t j = 0 ; j < v4.get(i).size() ; j++)
570 {
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);
575
576 BOOST_REQUIRE_EQUAL(f1,f2);
577 BOOST_REQUIRE_EQUAL(f3,f4);
578
579 for (size_t k = 0 ; k < v4.get(i).template get<2>(j).size() ; k++)
580 {
581 Point_test<float> p1 = v4_unp.get(i).template get<2>(j).get(k);
582 Point_test<float> p2 = v4.get(i).template get<2>(j).get(k);
583
584 BOOST_REQUIRE(p1 == p2);
585 }
586 }
587 }
588
589 mem.decRef();
590 delete &mem;
591}
592
593BOOST_AUTO_TEST_CASE ( vector_smarter_packer_unpacker_2 )
594{
595 //Create an object
597
598 //Fill it with data
599 v4.resize(1);
601 p.fill();
602 for (size_t i = 0 ; i < v4.size() ; i++)
603 {
604 v4.get(i).resize(50);
605 for (size_t j = 0 ; j < v4.get(i).size() ; j++)
606 {
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;
616 }
617 }
618
619 size_t req = 0;
620
621 //Pack request
622 Packer<decltype(v4),HeapMemory>::packRequest<>(v4,req);
623
624#ifndef SE_CLASS3
625 BOOST_REQUIRE_EQUAL(req,((sizeof(float)*4 + sizeof(float[3]) + sizeof(float[3][3]))*7 + sizeof(float)*2) * 50 + sizeof(size_t)*2);
626#endif
627
628 // allocate the memory
629 HeapMemory pmem;
630 //pmem.allocate(req);
631 ExtPreAlloc<HeapMemory> & mem = *(new ExtPreAlloc<HeapMemory>(req,pmem));
632 mem.incRef();
633
634 //Packing
635
636 Pack_stat sts;
637
638 Packer<decltype(v4),HeapMemory>::pack<>(mem,v4,sts);
639
640 //Unpacking
641
642 Unpack_stat ps;
643
645
646 Unpacker<decltype(v4_unp),HeapMemory>::unpack<>(mem,v4_unp,ps);
647
648 //Checking the data
649 for (size_t i = 0; i < v4.size(); i++)
650 {
651 for (size_t j = 0; j < v4.get(i).size(); j++)
652 {
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);
657
658 BOOST_REQUIRE_EQUAL(f1,f2);
659 BOOST_REQUIRE_EQUAL(f3,f4);
660
661 Point_test<float> p1 = v4_unp.get(i).template get<2>(j);
662 Point_test<float> p2 = v4.get(i).template get<2>(j);
663
664 BOOST_REQUIRE(p1 == p2);
665
666 p1 = v4_unp.get(i).template get<3>(j);
667 p2 = v4.get(i).template get<3>(j);
668
669 BOOST_REQUIRE(p1 == p2);
670
671 p1 = v4_unp.get(i).template get<4>(j);
672 p2 = v4.get(i).template get<4>(j);
673
674 BOOST_REQUIRE(p1 == p2);
675
676 p1 = v4_unp.get(i).template get<5>(j);
677 p2 = v4.get(i).template get<5>(j);
678
679 BOOST_REQUIRE(p1 == p2);
680
681 p1 = v4_unp.get(i).template get<6>(j);
682 p2 = v4.get(i).template get<6>(j);
683
684 BOOST_REQUIRE(p1 == p2);
685
686 p1 = v4_unp.get(i).template get<7>(j);
687 p2 = v4.get(i).template get<7>(j);
688
689 BOOST_REQUIRE(p1 == p2);
690
691 p1 = v4_unp.get(i).template get<8>(j);
692 p2 = v4.get(i).template get<8>(j);
693
694 BOOST_REQUIRE(p1 == p2);
695 }
696 }
697
698 mem.decRef();
699 delete &mem;
700}
701
702BOOST_AUTO_TEST_CASE ( vector_smarter_packer_unpacker_3 )
703{
704 //Create an object
706
707 //Fill it with data
708
709 v.resize(3);
711 p.fill();
712 for (size_t i = 0 ; i < v.size() ; i++)
713 {
714 v.template get<1>(i).resize(2);
715
716 for (size_t k = 0 ; k < v.template get<1>(i).size() ; k++)
717 v.template get<1>(i).get(k) = p;
718 }
719
720 size_t req = 0;
721
722 //Pack request
723 Packer<decltype(v),HeapMemory>::packRequest<1>(v,req);
724
725#ifndef SE_CLASS3
726 BOOST_REQUIRE_EQUAL(req, 3*(sizeof(Point_test<float>)*2+8)+8);
727#endif
728
729 // allocate the memory
730 HeapMemory pmem;
731 //pmem.allocate(req);
732 ExtPreAlloc<HeapMemory> & mem = *(new ExtPreAlloc<HeapMemory>(req,pmem));
733 mem.incRef();
734
735 //Packing
736
737 Pack_stat sts;
738
739 Packer<decltype(v),HeapMemory>::pack<1>(mem,v,sts);
740
741 //Unpacking
742
743 Unpack_stat ps;
744
746
747 Unpacker<decltype(v_unp),HeapMemory>::unpack<1>(mem,v_unp,ps);
748
749 //Checking the data
750 for (size_t i = 0; i < v.size(); i++)
751 {
752 for (size_t j = 0 ; j < v.template get<1>(i).size() ; j++)
753 {
754 Point_test<float> p1 = v_unp.template get<1>(i).get(j);
755 Point_test<float> p2 = v.template get<1>(i).get(j);
756
757 BOOST_REQUIRE(p1 == p2);
758 }
759 }
760
761 mem.decRef();
762 delete &mem;
763}
764
765BOOST_AUTO_TEST_CASE ( vector_aggr_packer_unpacker_zero_prop )
766{
767 //Create an object
769
770 //Fill it with data
771
772 v4.resize(3);
773
774 for (size_t i = 0 ; i < v4.size() ; i++)
775 {
776 v4.template get<0>(i) = 1.0;
777 v4.template get<1>(i) = 2.0;
778 }
779
780 size_t req = 0;
781 size_t req2 = 0;
782
783
784 //Pack request
785 Packer<decltype(v4),HeapMemory>::packRequest<>(v4,req);
786#ifndef SE_CLASS3
787 BOOST_REQUIRE_EQUAL(req, 3*(sizeof(float)*2)+8);
788#endif
789
790 Packer<decltype(v4),HeapMemory>::packRequest<0,1>(v4,req2);
791 BOOST_REQUIRE_EQUAL(req2, 3*(sizeof(float)*2)+8);
792
793 // allocate the memory
794 HeapMemory pmem;
795 //pmem.allocate(req);
796 ExtPreAlloc<HeapMemory> & mem = *(new ExtPreAlloc<HeapMemory>(req,pmem));
797 mem.incRef();
798
799 // allocate the memory
800 HeapMemory pmem2;
801 //pmem.allocate(req);
802 ExtPreAlloc<HeapMemory> & mem2 = *(new ExtPreAlloc<HeapMemory>(req2,pmem2));
803 mem2.incRef();
804
805 //Packing
806
807 Pack_stat sts;
808 Pack_stat sts2;
809
810 Packer<decltype(v4),HeapMemory>::pack<>(mem,v4,sts);
811
812 Packer<decltype(v4),HeapMemory>::pack<0,1>(mem2,v4,sts2);
813
814 //Unpacking
815
816 Unpack_stat ps;
817 Unpack_stat ps2;
818
820
822
823 Unpacker<decltype(v4_unp),HeapMemory>::unpack<>(mem,v4_unp,ps);
824
825 Unpacker<decltype(v4_unp_2),HeapMemory>::unpack<0,1>(mem2,v4_unp_2,ps2);
826
827 //Check the data
828
829 for (size_t i = 0 ; i < v4.size() ; i++)
830 {
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);
835
836 BOOST_REQUIRE_EQUAL(f1,f2);
837 BOOST_REQUIRE_EQUAL(f3,f4);
838 }
839
840 for (size_t i = 0 ; i < v4.size() ; i++)
841 {
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);
846
847 BOOST_REQUIRE_EQUAL(f1,f2);
848 BOOST_REQUIRE_EQUAL(f3,f4);
849 }
850
851 mem.decRef();
852 delete &mem;
853}
854
855BOOST_AUTO_TEST_CASE ( vector_aggr_packer_unpacker_zero_prop_2 )
856{
857 //Create an object
859
860 //Fill it with data
861
862 v4.resize(3);
863
864 for (size_t i = 0 ; i < v4.size() ; i++)
865 {
866 v4.template get<0>(i) = 1.0;
867 v4.template get<1>(i).add(5);
868 v4.template get<1>(i).add(6);
869 }
870
871 size_t req = 0;
872 size_t req2 = 0;
873
874 //Pack request
875 Packer<decltype(v4),HeapMemory>::packRequest<>(v4,req);
876#ifndef SE_CLASS3
877 BOOST_REQUIRE_EQUAL(req, 3*(sizeof(float)*3 + 8)+8);
878#endif
879
880 Packer<decltype(v4),HeapMemory>::packRequest<0,1>(v4,req2);
881 BOOST_REQUIRE_EQUAL(req2, 3*(sizeof(float)*3 + 8)+8);
882
883 // allocate the memory
884 HeapMemory pmem;
885 //pmem.allocate(req);
886 ExtPreAlloc<HeapMemory> & mem = *(new ExtPreAlloc<HeapMemory>(req,pmem));
887 mem.incRef();
888
889 // allocate the memory
890 HeapMemory pmem2;
891 //pmem.allocate(req);
892 ExtPreAlloc<HeapMemory> & mem2 = *(new ExtPreAlloc<HeapMemory>(req2,pmem2));
893 mem2.incRef();
894
895 //Packing
896
897 Pack_stat sts;
898 Pack_stat sts2;
899
900 Packer<decltype(v4),HeapMemory>::pack<>(mem,v4,sts);
901
902 Packer<decltype(v4),HeapMemory>::pack<0,1>(mem2,v4,sts2);
903
904 //Unpacking
905
906 Unpack_stat ps;
907 Unpack_stat ps2;
908
910
912
913 Unpacker<decltype(v4_unp),HeapMemory>::unpack<>(mem,v4_unp,ps);
914
915 Unpacker<decltype(v4_unp_2),HeapMemory>::unpack<0,1>(mem2,v4_unp_2,ps2);
916
917 //Check the data
918
919 for (size_t i = 0 ; i < v4.size() ; i++)
920 {
921 float f1 = v4_unp.template get<0>(i);
922 float f2 = v4.template get<0>(i);
923
924 BOOST_REQUIRE_EQUAL(f1,f2);
925
926 for (size_t j = 0; j < v4.template get<1>(i).size(); j++)
927 {
928 float f3 = v4_unp.template get<1>(i).get(j);
929 float f4 = v4.template get<1>(i).get(j);
930
931 BOOST_REQUIRE_EQUAL(f3,f4);
932 }
933 }
934
935 for (size_t i = 0 ; i < v4.size() ; i++)
936 {
937 float f1 = v4_unp_2.template get<0>(i);
938 float f2 = v4.template get<0>(i);
939
940 BOOST_REQUIRE_EQUAL(f1,f2);
941
942 for (size_t j = 0; j < v4.template get<1>(i).size(); j++)
943 {
944 float f3 = v4_unp_2.template get<1>(i).get(j);
945 float f4 = v4.template get<1>(i).get(j);
946
947 BOOST_REQUIRE_EQUAL(f3,f4);
948 }
949 }
950
951 mem.decRef();
952 delete &mem;
953
954 std::cout << "Vector pack/unpack test stop" << "\n";
955}
956
957BOOST_AUTO_TEST_CASE ( grid_ptst_packer_unpacker )
958{
959 std::cout << "Grid pack/unpack test start" << "\n";
960
961 size_t sz[] = {16,16,16};
963 g.setMemory();
964 fill_grid<3>(g);
965
966 typedef Point_test<float> pt;
967
968 size_t req = 0;
969 //Pack request
970 Packer<decltype(g),HeapMemory>::packRequest<pt::x,pt::v>(g,req);
971
972#ifndef SE_CLASS3
973 BOOST_REQUIRE_EQUAL(req,(sizeof(float) + sizeof(float[3])) * 16 * 16 * 16 + sizeof(size_t)*3);
974#endif
975
976 // allocate the memory
977 HeapMemory pmem;
978 //pmem.allocate(req);
979 ExtPreAlloc<HeapMemory> & mem = *(new ExtPreAlloc<HeapMemory>(req,pmem));
980 mem.incRef();
981
982 //Packing
983 Pack_stat sts;
984
985 Packer<decltype(g),HeapMemory>::pack<pt::x,pt::v>(mem,g,sts);
986
987 //Unpacking
988
989 Unpack_stat ps;
990
991 //size_t sz2[] = {16,16,16};
993
994 Unpacker<decltype(g_unp),HeapMemory>::unpack<pt::x,pt::v>(mem,g_unp,ps);
995
996 // Check the unpacked grid
997 auto it = g_unp.getIterator();
998
999 while (it.isNext())
1000 {
1001 float f1 = g_unp.template get<pt::x>(it.get());
1002 float f2 = g.template get<pt::x>(it.get());
1003
1004 BOOST_REQUIRE_EQUAL(f1,f2);
1005
1006 for (size_t i = 0 ; i < 3 ; i++)
1007 {
1008 f1 = g_unp.template get<pt::v>(it.get())[i];
1009 f2 = g.template get<pt::v>(it.get())[i];
1010
1011 BOOST_REQUIRE_EQUAL(f1,f2);
1012 }
1013
1014 ++it;
1015 }
1016
1017 // destroy the packed memory
1018 mem.decRef();
1019 delete &mem;
1020
1021}
1022
1023template <unsigned int dim>
1024void test_packer_aggr_smp(grid_cpu<dim, aggregate<float, float, float, float, float>> & g, size_t (& sz)[dim])
1025{
1026 g.setMemory();
1027
1028 auto key_it = g.getIterator();
1029
1030 while (key_it.isNext())
1031 {
1032 auto kk = key_it.get();
1033
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;
1039
1040 ++key_it;
1041 }
1042
1043 size_t req = 0;
1044
1045 size_t sz_tot = 1;
1046
1047 for (size_t i = 0 ; i < dim ; i++)
1048 {
1049 sz_tot *= sz[i];
1050 }
1051
1052 Packer<typename std::remove_reference<decltype(g)>::type,HeapMemory>::template packRequest<>(g,req);
1053#ifndef SE_CLASS3
1054 BOOST_REQUIRE_EQUAL(req,(sizeof(float))* 5 * sz_tot + sizeof(size_t)*dim);
1055#endif
1056
1057 // allocate the memory
1058 HeapMemory pmem;
1059 //pmem.allocate(req);
1060 ExtPreAlloc<HeapMemory> & mem = *(new ExtPreAlloc<HeapMemory>(req,pmem));
1061 mem.incRef();
1062
1063 //Packing
1064 Pack_stat sts;
1065
1066 Packer<typename std::remove_reference<decltype(g)>::type,HeapMemory>::template pack<>(mem,g,sts);
1067
1068 //Unpacking
1069
1070 Unpack_stat ps;
1071
1073
1074 Unpacker<decltype(g_unp),HeapMemory>::template unpack<>(mem,g_unp,ps);
1075
1076 // Check the unpacked grid
1077 auto it = g_unp.getIterator();
1078
1079 while (it.isNext())
1080 {
1081 float f1 = g_unp.template get<0>(it.get());
1082 float f2 = g.template get<0>(it.get());
1083
1084 BOOST_REQUIRE_EQUAL(f1,f2);
1085
1086 f1 = g_unp.template get<1>(it.get());
1087 f2 = g.template get<1>(it.get());
1088
1089 BOOST_REQUIRE_EQUAL(f1,f2);
1090
1091 f1 = g_unp.template get<2>(it.get());
1092 f2 = g.template get<2>(it.get());
1093
1094 BOOST_REQUIRE_EQUAL(f1,f2);
1095
1096 f1 = g_unp.template get<3>(it.get());
1097 f2 = g.template get<3>(it.get());
1098
1099 BOOST_REQUIRE_EQUAL(f1,f2);
1100
1101 f1 = g_unp.template get<4>(it.get());
1102 f2 = g.template get<4>(it.get());
1103
1104 BOOST_REQUIRE_EQUAL(f1,f2);
1105
1106 ++it;
1107 }
1108
1109 // destroy the packed memory
1110 mem.decRef();
1111 delete &mem;
1112}
1113
1114BOOST_AUTO_TEST_CASE ( grid_aggr_packer_unpacker_3D )
1115{
1116 size_t sz[] = {64,4,16};
1118
1119 test_packer_aggr_smp<3>(g,sz);
1120}
1121
1122BOOST_AUTO_TEST_CASE ( grid_aggr_packer_unpacker_2D )
1123{
1124 size_t sz[] = {64,4};
1126
1127 test_packer_aggr_smp<2>(g,sz);
1128}
1129
1130BOOST_AUTO_TEST_CASE ( grid_aggr_packer_unpacker_4D )
1131{
1132 size_t sz[] = {64,4,3,3};
1134
1135 test_packer_aggr_smp<4>(g,sz);
1136}
1137
1138template <unsigned int dim>
1139void test_packer_aggr_nd(grid_cpu<dim, Point_test<float>> & g2, size_t (& sz)[dim], size_t (& sz2)[dim])
1140{
1141 g2.setMemory();
1142 fill_grid<dim>(g2);
1143
1145 g.setMemory();
1146
1147 auto key_it = g.getIterator();
1148
1149 while (key_it.isNext())
1150 {
1151 auto kk = key_it.get();
1152
1153 g.template get<0>(kk) = 1;
1154 g.template get<1>(kk) = 2;
1155 g.template get<2>(kk) = g2;
1156
1157 ++key_it;
1158 }
1159
1160 size_t req = 0;
1161
1162 Packer<decltype(g),HeapMemory>::template packRequest<1,2>(g,req);
1163
1164 size_t sz_tot = 1;
1165 size_t sz2_tot = 1;
1166 for (size_t i = 0 ; i < dim ; i++)
1167 {
1168 sz_tot *= sz[i];
1169 sz2_tot *= sz2[i];
1170 }
1171
1172#ifndef SE_CLASS3
1173 BOOST_REQUIRE_EQUAL(req,(sz_tot*(sizeof(float) + sz2_tot * 64 + sizeof(size_t)*dim) + sizeof(size_t)*dim));
1174#endif
1175
1176 // allocate the memory
1177 HeapMemory pmem;
1178 //pmem.allocate(req);
1179 ExtPreAlloc<HeapMemory> & mem = *(new ExtPreAlloc<HeapMemory>(req,pmem));
1180 mem.incRef();
1181
1182 //Packing
1183 Pack_stat sts;
1184
1185 Packer<decltype(g),HeapMemory>::template pack<1,2>(mem,g,sts);
1186
1187 //Unpacking
1188
1189 Unpack_stat ps;
1190
1192
1193 Unpacker<decltype(g_unp),HeapMemory>::template unpack<1,2>(mem,g_unp,ps);
1194
1195 typedef Point_test<float> pt;
1196
1197 // Check the unpacked grid
1198 auto it = g_unp.getIterator();
1199
1200 while (it.isNext())
1201 {
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);
1205
1206
1207 auto g_unp_1 = g_unp.template get<2>(it.get());
1208 auto g_unp_2 = g.template get<2>(it.get());
1209
1210 auto it_unp = g_unp_1.getIterator();
1211
1212 {
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());
1217
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());
1222
1223 BOOST_REQUIRE_EQUAL(x1,x2);
1224 BOOST_REQUIRE_EQUAL(y1,y2);
1225 BOOST_REQUIRE_EQUAL(z1,z2);
1226 BOOST_REQUIRE_EQUAL(s1,s2);
1227
1228 for (size_t i = 0 ; i < 3 ; i++)
1229 {
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);
1233 }
1234
1235 for (size_t i = 0 ; i < 3 ; i++)
1236 {
1237 for (size_t j = 0 ; j < 3 ; j++)
1238 {
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);
1242 }
1243 }
1244
1245 ++it_unp;
1246 }
1247
1248 ++it;
1249 }
1250
1251 // destroy the packed memory
1252 mem.decRef();
1253 delete &mem;
1254
1255 std::cout << "Grid pack/unpack test stop " << dim << "D" << "\n";
1256}
1257
1258BOOST_AUTO_TEST_CASE ( grid_aggr_grid_packer_unpacker_3D )
1259{
1260 size_t sz[] = {8,7,5};
1261 size_t sz2[] = {2,4,13};
1262
1264
1265 test_packer_aggr_nd<3>(g2,sz,sz2);
1266}
1267
1268// Test 2D
1269
1270
1271BOOST_AUTO_TEST_CASE ( grid_aggr_grid_packer_unpacker_2D )
1272{
1273 size_t sz[] = {8,7};
1274 size_t sz2[] = {2,4};
1275
1277
1278 test_packer_aggr_nd<2>(g2,sz,sz2);
1279}
1280
1281BOOST_AUTO_TEST_CASE ( grid_aggr_grid_packer_unpacker_4D )
1282{
1283 size_t sz[] = {8,7,2,2};
1284 size_t sz2[] = {2,4,2,2};
1285
1287
1288 test_packer_aggr_nd<4>(g2,sz,sz2);
1289}
1290
1291BOOST_AUTO_TEST_SUITE_END()
1292
1293#endif /* SRC_PACKER_NESTED_TESTS_HPP_ */
This class represent an N-dimensional box.
Definition Box.hpp:61
__device__ __host__ void setHigh(int i, T val)
set the high interval of the box
Definition Box.hpp:544
__device__ __host__ void setLow(int i, T val)
set the low interval of the box
Definition Box.hpp:533
virtual void decRef()
Decrement the reference counter.
virtual void incRef()
Increment the reference counter.
This class allocate, and destroy CPU memory.
Packing status object.
Definition Pack_stat.hpp:61
Packing class.
Definition Packer.hpp:50
Test structure used for several test.
void fill()
fill
Unpacking status object.
Definition Pack_stat.hpp:16
Unpacker class.
Definition Unpacker.hpp:34
Implementation of 1-D std::vector like structure.
size_t size()
Stub size.
aggregate of properties, from a list of object if create a struct that follow the OPENFPM native stru...
It model an expression expr1 * expr2.
Definition mul.hpp:120