OpenFPM_data  0.1.0
Project that contain the implementation and interfaces for basic structure like vectors, grids, graph ... .
 All Data Structures Namespaces Functions Variables Typedefs Friends
vector_test_util.hpp
1 /*
2  * vector_test_util.hpp
3  *
4  * Created on: Jun 19, 2015
5  * Author: Pietro Incardona
6  */
7 
8 #ifndef VECTOR_TEST_UTIL_HPP_
9 #define VECTOR_TEST_UTIL_HPP_
10 
11 #include "config.h"
12 #include "Point_test.hpp"
13 #include "Vector/map_vector.hpp"
14 
16 typedef Point_test<float> P;
18 
19 #ifdef TEST_COVERAGE_MODE
20 #define FIRST_PUSH 1000
21 #define SECOND_PUSH 1000
22 #else
23 #define FIRST_PUSH 1000000
24 #define SECOND_PUSH 1000000
25 #endif
26 
27 #include "timer.hpp"
28 
29 std::vector<Point_orig<float>> allocate_stl()
30 {
31  std::vector<Point_orig<float>> v_stl_test;
32 
33  // Now fill the vector
34 
36  po.setx(1.0);
37  po.sety(2.0);
38  po.setz(3.0);
39  po.sets(4.0);
40 
41  for (size_t i = 0 ; i < FIRST_PUSH ; i++)
42  {
43  // Modify po
44 
45  po.v[0] = 1.0 + i;
46  po.v[1] = 2.0 + i;
47  po.v[2] = 7.0 + i;
48 
49  po.t[0][0] = 10.0 + i;
50  po.t[0][1] = 13.0 + i;
51  po.t[0][2] = 8.0 + i;
52  po.t[1][0] = 19.0 + i;
53  po.t[1][1] = 23.0 + i;
54  po.t[1][2] = 5.0 + i;
55  po.t[2][0] = 4.0 + i;
56  po.t[2][1] = 3.0 + i;
57  po.t[2][2] = 11.0 + i;
58 
59  // add p
60 
61  v_stl_test.push_back(po);
62  }
63 
64  return v_stl_test;
65 }
66 
67 template <typename T>
68 openfpm::vector<T> allocate_openfpm_primitive(size_t n, size_t fill)
69 {
71 
72  for (size_t i = 0 ; i < n ; i++)
73  v.add(fill);
74 
75  return v;
76 }
77 
78 openfpm::vector<Point_test<float>> allocate_openfpm_fill(size_t n, size_t fill)
79 {
80  // Test point
81  typedef Point_test<float> p;
82 
85 
86  pt.setx(fill);
87  pt.sety(fill);
88  pt.setz(fill);
89  pt.sets(fill);
90 
91  pt.setv(0,fill);
92  pt.setv(1,fill);
93  pt.setv(2,fill);
94 
95  pt.sett(0,0,fill);
96  pt.sett(0,1,fill);
97  pt.sett(0,2,fill);
98  pt.sett(1,0,fill);
99  pt.sett(1,1,fill);
100  pt.sett(1,2,fill);
101  pt.sett(2,0,fill);
102  pt.sett(2,1,fill);
103  pt.sett(2,2,fill);
104 
105 
106  // ADD n elements
107  for (size_t i = 0 ; i < n ; i++)
108  v_send.add(pt);
109 
110  return v_send;
111 }
112 
113 
114 openfpm::vector<Point_test<float>> allocate_openfpm(size_t n_ele)
115 {
118 
122 
123  p.setx(1.0);
124  p.sety(2.0);
125  p.setz(3.0);
126  p.sets(4.0);
127 
128  // push objects
129 
130  for (size_t i = 0 ; i < n_ele / 2 ; i++)
131  {
132  // Modify the point
133 
135  p.get<P::v>()[0] = 1.0 + i;
136  p.get<P::v>()[1] = 2.0 + i;
137  p.get<P::v>()[2] = 7.0 + i;
138 
139  p.get<P::t>()[0][0] = 10.0 + i;
140  p.get<P::t>()[0][1] = 13.0 + i;
141  p.get<P::t>()[0][2] = 8.0 + i;
142  p.get<P::t>()[1][0] = 19.0 + i;
143  p.get<P::t>()[1][1] = 23.0 + i;
144  p.get<P::t>()[1][2] = 5.0 + i;
145  p.get<P::t>()[2][0] = 4.0 + i;
146  p.get<P::t>()[2][1] = 3.0 + i;
147  p.get<P::t>()[2][2] = 11.0 + i;
149 
150  // add p
151 
152  v_ofp_test.add(p);
153  }
154 
155  for (size_t i = n_ele / 2 ; i < n_ele ; i++)
156  {
157  v_ofp_test.add();
158 
159  size_t last = v_ofp_test.size()-1;
160 
161  // Modify the point
162 
163  v_ofp_test.get<P::v>(last)[0] = 1.0 + i;
164  v_ofp_test.get<P::v>(last)[1] = 2.0 + i;
165  v_ofp_test.get<P::v>(last)[2] = 7.0 + i;
166 
167  v_ofp_test.get<P::t>(last)[0][0] = 10.0 + i;
168  v_ofp_test.get<P::t>(last)[0][1] = 13.0 + i;
169  v_ofp_test.get<P::t>(last)[0][2] = 8.0 + i;
170  v_ofp_test.get<P::t>(last)[1][0] = 19.0 + i;
171  v_ofp_test.get<P::t>(last)[1][1] = 23.0 + i;
172  v_ofp_test.get<P::t>(last)[1][2] = 5.0 + i;
173  v_ofp_test.get<P::t>(last)[2][0] = 4.0 + i;
174  v_ofp_test.get<P::t>(last)[2][1] = 3.0 + i;
175  v_ofp_test.get<P::t>(last)[2][2] = 11.0 + i;
176  }
177 
179 
180  return v_ofp_test;
181 }
182 
183 #endif /* VECTOR_TEST_UTIL_HPP_ */
Definition of a class Point in plain C++ and boost::vector for testing purpose.
Definition: Point_orig.hpp:19
Test structure used for several test.
Definition: Point_test.hpp:72
Implementation of 1-D std::vector like structure.
Definition: map_grid.hpp:94