OpenFPM_pdata  4.1.0
Project that contain the implementation of distributed structures
 
Loading...
Searching...
No Matches
EMatrix_unit_tests.cpp
1/*
2 * EMatrix_unit_tests.cpp
3 *
4 * Created on: Feb 13, 2018
5 * Author: i-bird
6 */
7
8#define BOOST_TEST_DYN_LINK
9#include <boost/test/unit_test.hpp>
10#include "DMatrix/EMatrix.hpp"
11#include "memory/HeapMemory.hpp"
12
13#ifdef HAVE_EIGEN
14
15BOOST_AUTO_TEST_SUITE (EMatrix_test)
16
17BOOST_AUTO_TEST_CASE( EMatrix_test_use)
18{
19 {
20 EMatrixXd em;
21
22 em.resize(8,5);
23
24 for (size_t i = 0 ; i < 8 ; i++)
25 {
26 for (size_t j = 0 ; j < 5 ; j++)
27 {em(i,j) = i*8+j;}
28 }
29
30 size_t pr = 0;
31 em.packRequest(pr);
32
33 // allocate the memory
34 HeapMemory pmem;
35 pmem.allocate(pr);
37 mem.incRef();
38
39 BOOST_REQUIRE_EQUAL(pr,8*5*sizeof(double) + 2*sizeof(size_t));
40
41 Pack_stat sts;
42 em.pack(mem,sts);
43
44 // Reset to zero
45 for (size_t i = 0 ; i < 8 ; i++)
46 {
47 for (size_t j = 0 ; j < 5 ; j++)
48 {em(i,j) = 0;}
49 }
50
51 Unpack_stat ps;
52 em.unpack(mem,ps);
53
54 for (size_t i = 0 ; i < 8 ; i++)
55 {
56 for (size_t j = 0 ; j < 5 ; j++)
57 {BOOST_REQUIRE_EQUAL(em(i,j),i*8+j);}
58 }
59 }
60
61
62 {
63 EMatrix3d em;
64
65 em.resize(3,3);
66
67 for (size_t i = 0 ; i < 3 ; i++)
68 {
69 for (size_t j = 0 ; j < 3 ; j++)
70 {em(i,j) = i*8+j;}
71 }
72
73 size_t pr = 0;
74 em.packRequest(pr);
75
76 // allocate the memory
77 HeapMemory pmem;
78 pmem.allocate(pr);
80 mem.incRef();
81
82 BOOST_REQUIRE_EQUAL(pr,3*3*sizeof(double) + 2*sizeof(size_t));
83
84 Pack_stat sts;
85 em.pack(mem,sts);
86
87 // Reset to zero
88 for (size_t i = 0 ; i < 3 ; i++)
89 {
90 for (size_t j = 0 ; j < 3 ; j++)
91 {em(i,j) = 0;}
92 }
93
94 Unpack_stat ps;
95 em.unpack(mem,ps);
96
97 for (size_t i = 0 ; i < 3 ; i++)
98 {
99 for (size_t j = 0 ; j < 3 ; j++)
100 {BOOST_REQUIRE_EQUAL(em(i,j),i*8+j);}
101 }
102 }
103}
104
105BOOST_AUTO_TEST_SUITE_END()
106
107
108#endif
virtual void incRef()
Increment the reference counter.
This class allocate, and destroy CPU memory.
virtual bool allocate(size_t sz)
allocate memory
Packing status object.
Definition Pack_stat.hpp:61
Unpacking status object.
Definition Pack_stat.hpp:16