OpenFPM_pdata  4.1.0
Project that contain the implementation of distributed structures
map_vector_sparse_unit_tests.cu
1 #include "config.h"
2 #define BOOST_TEST_DYN_LINK
3 #include <boost/test/unit_test.hpp>
4 #include "map_vector_sparse.hpp"
5 
6 BOOST_AUTO_TEST_SUITE( sparse_vector_test )
7 
8 
9 BOOST_AUTO_TEST_CASE ( test_sparse_vector_use )
10 {
12 
14  vs.template setBackground<0>(0);
15 
16  size_t v[3] = {0,0,0};
17 
18  vs.template setBackground<1>(v);
19 
20  size_t t[3][3] = {{0,0,0},{0,0,0},{0,0,0}};
21 
22  vs.template setBackground<2>(t);
23 
24  vs.template insert<0>(5) = 5;
25  vs.template insert<0>(8) = 8;
26  vs.template insert<0>(25) = 25;
27  vs.template insert<0>(84) = 84;
28  vs.template insert<0>(54) = 54;
29  vs.template insert<0>(81) = 81;
30  vs.template insert<0>(57) = 57;
31  vs.template insert<0>(83) = 83;
32  vs.template insert<0>(85) = 85;
33  vs.template insert<0>(82) = 82;
34  vs.template insert<0>(35) = 35;
35  vs.template insert<0>(28) = 28;
36 
37  mgpu::ofp_context_t ctx;
38  vs.template flush<sadd_<0>>(ctx);
39 
40  BOOST_REQUIRE_EQUAL(vs.get<0>(5),5);
41  BOOST_REQUIRE_EQUAL(vs.get<0>(54),54);
42  BOOST_REQUIRE_EQUAL(vs.get<0>(85),85);
43  BOOST_REQUIRE_EQUAL(vs.get<0>(1000),0);
44 
46 
47  vs.template insert<0>(4) = 4;
48  vs.template insert<0>(28) = 28;
49  vs.template insert<0>(45) = 45;
50  vs.template insert<0>(94) = 94;
51  vs.template insert<0>(88) = 88;
52  vs.template insert<0>(823) = 823;
53 
54  vs.template flush<sadd_<0>>(ctx);
55 
56  BOOST_REQUIRE_EQUAL(vs.get<0>(5),5);
57  BOOST_REQUIRE_EQUAL(vs.get<0>(54),54);
58  BOOST_REQUIRE_EQUAL(vs.get<0>(85),85);
59  BOOST_REQUIRE_EQUAL(vs.get<0>(1000),0);
60  BOOST_REQUIRE_EQUAL(vs.get<0>(4),4);
61  BOOST_REQUIRE_EQUAL(vs.get<0>(28),56);
62  BOOST_REQUIRE_EQUAL(vs.get<0>(45),45);
63  BOOST_REQUIRE_EQUAL(vs.get<0>(823),823);
64 
65  // we try to overlap some numbers
66 
67  vs.template insert<0>(45) = 450;
68  vs.template insert<0>(94) = 940;
69  vs.template insert<0>(88) = 880;
70 
71  vs.template flush<sadd_<0>>(ctx);
72 
73  BOOST_REQUIRE_EQUAL(vs.get<0>(45),495);
74  BOOST_REQUIRE_EQUAL(vs.get<0>(94),1034);
75  BOOST_REQUIRE_EQUAL(vs.get<0>(88),968);
76 
77  // try to insert the same thing multiple time
78 
79  vs.template insert<0>(101) = 1850;
80  vs.template insert<0>(45) = 1450;
81  vs.template insert<0>(45) = 1940;
82  vs.template insert<0>(45) = 1880;
83  vs.template insert<0>(1) = 2050;
84 
85  vs.template flush<sadd_<0>>(ctx);
86 
87  BOOST_REQUIRE_EQUAL(vs.get<0>(101),1850);
88  BOOST_REQUIRE_EQUAL(vs.get<0>(45),5765);
89  BOOST_REQUIRE_EQUAL(vs.get<0>(1),2050);
90 }
91 
92 BOOST_AUTO_TEST_SUITE_END()
auto get(Ti id) const -> decltype(vct_data.template get< p >(id))
Get an element of the vector.
aggregate of properties, from a list of object if create a struct that follow the OPENFPM native stru...
Definition: aggregate.hpp:214