OpenFPM_pdata  4.1.0
Project that contain the implementation of distributed structures
 
Loading...
Searching...
No Matches
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#include "data_type/aggregate.hpp"
15
17typedef Point_test<float> P;
19
20#ifdef TEST_COVERAGE_MODE
21#define FIRST_PUSH 1000
22#define SECOND_PUSH 1000
23#else
24#define FIRST_PUSH 1000000
25#define SECOND_PUSH 1000000
26#endif
27
28#include "timer.hpp"
29
30static std::vector<Point_orig<float>> allocate_stl()
31{
32 std::vector<Point_orig<float>> v_stl_test;
33
34 // Now fill the vector
35
37 po.setx(1.0);
38 po.sety(2.0);
39 po.setz(3.0);
40 po.sets(4.0);
41
42 for (size_t i = 0 ; i < FIRST_PUSH ; i++)
43 {
44 // Modify po
45
46 po.v[0] = 1.0 + i;
47 po.v[1] = 2.0 + i;
48 po.v[2] = 7.0 + i;
49
50 po.t[0][0] = 10.0 + i;
51 po.t[0][1] = 13.0 + i;
52 po.t[0][2] = 8.0 + i;
53 po.t[1][0] = 19.0 + i;
54 po.t[1][1] = 23.0 + i;
55 po.t[1][2] = 5.0 + i;
56 po.t[2][0] = 4.0 + i;
57 po.t[2][1] = 3.0 + i;
58 po.t[2][2] = 11.0 + i;
59
60 // add p
61
62 v_stl_test.push_back(po);
63 }
64
65 return v_stl_test;
66}
67
68template <typename T>
69openfpm::vector<T> allocate_openfpm_primitive(size_t n, size_t fill)
70{
72
73 for (size_t i = 0 ; i < n ; i++)
74 v.add(fill);
75
76 return v;
77}
78
79static openfpm::vector<Point_test<float>> allocate_openfpm_fill(size_t n, size_t fill)
80{
83
84 pt.setx(fill);
85 pt.sety(fill);
86 pt.setz(fill);
87 pt.sets(fill);
88
89 pt.setv(0,fill);
90 pt.setv(1,fill);
91 pt.setv(2,fill);
92
93 pt.sett(0,0,fill);
94 pt.sett(0,1,fill);
95 pt.sett(0,2,fill);
96 pt.sett(1,0,fill);
97 pt.sett(1,1,fill);
98 pt.sett(1,2,fill);
99 pt.sett(2,0,fill);
100 pt.sett(2,1,fill);
101 pt.sett(2,2,fill);
102
103
104 // ADD n elements
105 for (size_t i = 0 ; i < n ; i++)
106 v_send.add(pt);
107
108 return v_send;
109}
110
111
112template<typename vector> vector allocate_openfpm(size_t n_ele)
113{
114 vector v_ofp_test;
115
119
120 p.setx(1.0);
121 p.sety(2.0);
122 p.setz(3.0);
123 p.sets(4.0);
124
125 // push objects
126
127 for (size_t i = 0 ; i < n_ele / 2 ; i++)
128 {
129 // Modify the point
130
132 p.get<P::v>()[0] = 1.0 + i;
133 p.get<P::v>()[1] = 2.0 + i;
134 p.get<P::v>()[2] = 7.0 + i;
135
136 p.get<P::t>()[0][0] = 10.0 + i;
137 p.get<P::t>()[0][1] = 13.0 + i;
138 p.get<P::t>()[0][2] = 8.0 + i;
139 p.get<P::t>()[1][0] = 19.0 + i;
140 p.get<P::t>()[1][1] = 23.0 + i;
141 p.get<P::t>()[1][2] = 5.0 + i;
142 p.get<P::t>()[2][0] = 4.0 + i;
143 p.get<P::t>()[2][1] = 3.0 + i;
144 p.get<P::t>()[2][2] = 11.0 + i;
146
147 // add p
148
149 v_ofp_test.add(p);
150 }
151
152 for (size_t i = n_ele / 2 ; i < n_ele ; i++)
153 {
154 v_ofp_test.add();
155
156 size_t last = v_ofp_test.size()-1;
157
158 // Modify the point
159
160 v_ofp_test.template get<P::v>(last)[0] = 1.0 + i;
161 v_ofp_test.template get<P::v>(last)[1] = 2.0 + i;
162 v_ofp_test.template get<P::v>(last)[2] = 7.0 + i;
163
164 v_ofp_test.template get<P::t>(last)[0][0] = 10.0 + i;
165 v_ofp_test.template get<P::t>(last)[0][1] = 13.0 + i;
166 v_ofp_test.template get<P::t>(last)[0][2] = 8.0 + i;
167 v_ofp_test.template get<P::t>(last)[1][0] = 19.0 + i;
168 v_ofp_test.template get<P::t>(last)[1][1] = 23.0 + i;
169 v_ofp_test.template get<P::t>(last)[1][2] = 5.0 + i;
170 v_ofp_test.template get<P::t>(last)[2][0] = 4.0 + i;
171 v_ofp_test.template get<P::t>(last)[2][1] = 3.0 + i;
172 v_ofp_test.template get<P::t>(last)[2][2] = 11.0 + i;
173 }
174
175 return v_ofp_test;
176}
177
178static openfpm::vector<Point_test_prp<float>> allocate_openfpm_prp(size_t n_ele)
179{
181
185
186 p.setx(1.0);
187 p.sety(2.0);
188 p.setz(3.0);
189 p.sets(4.0);
190
191 // push objects
192
193 for (size_t i = 0 ; i < n_ele / 2 ; i++)
194 {
195 // Modify the point
196
198 p.get<P::v>()[0] = 1.0 + i;
199 p.get<P::v>()[1] = 2.0 + i;
200 p.get<P::v>()[2] = 7.0 + i;
201
202 p.get<P::t>()[0][0] = 10.0 + i;
203 p.get<P::t>()[0][1] = 13.0 + i;
204 p.get<P::t>()[0][2] = 8.0 + i;
205 p.get<P::t>()[1][0] = 19.0 + i;
206 p.get<P::t>()[1][1] = 23.0 + i;
207 p.get<P::t>()[1][2] = 5.0 + i;
208 p.get<P::t>()[2][0] = 4.0 + i;
209 p.get<P::t>()[2][1] = 3.0 + i;
210 p.get<P::t>()[2][2] = 11.0 + i;
212
213 // add p
214
215 v_ofp_test.add(p);
216 }
217
218 for (size_t i = n_ele / 2 ; i < n_ele ; i++)
219 {
220 v_ofp_test.add();
221
222 size_t last = v_ofp_test.size()-1;
223
224 // Modify the point
225
226 v_ofp_test.get<P::v>(last)[0] = 1.0 + i;
227 v_ofp_test.get<P::v>(last)[1] = 2.0 + i;
228 v_ofp_test.get<P::v>(last)[2] = 7.0 + i;
229
230 v_ofp_test.get<P::t>(last)[0][0] = 10.0 + i;
231 v_ofp_test.get<P::t>(last)[0][1] = 13.0 + i;
232 v_ofp_test.get<P::t>(last)[0][2] = 8.0 + i;
233 v_ofp_test.get<P::t>(last)[1][0] = 19.0 + i;
234 v_ofp_test.get<P::t>(last)[1][1] = 23.0 + i;
235 v_ofp_test.get<P::t>(last)[1][2] = 5.0 + i;
236 v_ofp_test.get<P::t>(last)[2][0] = 4.0 + i;
237 v_ofp_test.get<P::t>(last)[2][1] = 3.0 + i;
238 v_ofp_test.get<P::t>(last)[2][2] = 11.0 + i;
239 }
240
241 return v_ofp_test;
242}
243
244
245static openfpm::vector< aggregate<float,float,float,float,float[3],float[3][3],openfpm::vector<int>> > allocate_openfpm_aggregate_with_complex(size_t n_ele)
246{
249
250 for (size_t i = 0 ; i < n_ele ; i++)
251 {
252 v_ofp_test.add();
253
254 size_t last = v_ofp_test.size()-1;
255
256 // Modify the point
257
258 v_ofp_test.get<P::x>(last) = 100.0 + i;
259 v_ofp_test.get<P::y>(last) = 102.0 + i;
260 v_ofp_test.get<P::z>(last) = 107.0 + i;
261 v_ofp_test.get<P::s>(last) = 109.0 + i;
262
263 v_ofp_test.get<P::v>(last)[0] = 1.0 + i;
264 v_ofp_test.get<P::v>(last)[1] = 2.0 + i;
265 v_ofp_test.get<P::v>(last)[2] = 7.0 + i;
266
267 v_ofp_test.get<P::t>(last)[0][0] = 10.0 + i;
268 v_ofp_test.get<P::t>(last)[0][1] = 13.0 + i;
269 v_ofp_test.get<P::t>(last)[0][2] = 8.0 + i;
270 v_ofp_test.get<P::t>(last)[1][0] = 19.0 + i;
271 v_ofp_test.get<P::t>(last)[1][1] = 23.0 + i;
272 v_ofp_test.get<P::t>(last)[1][2] = 5.0 + i;
273 v_ofp_test.get<P::t>(last)[2][0] = 4.0 + i;
274 v_ofp_test.get<P::t>(last)[2][1] = 3.0 + i;
275 v_ofp_test.get<P::t>(last)[2][2] = 11.0 + i;
276 }
277
279
280 return v_ofp_test;
281}
282
283#endif /* VECTOR_TEST_UTIL_HPP_ */
Definition of a class Point in plain C++ and boost::vector for testing purpose.
Definition Point_test.hpp:5
Test structure used for several test.
void sets(T s_)
set the s property
void setx(T x_)
set the x property
void setz(T z_)
set the z property
boost::fusion::result_of::at< type, boost::mpl::int_< i > >::type get()
getter method for a general property i
void sety(T y_)
set the y property
Test structure used for several test.
static const unsigned int x
x property is at position 0 in the boost::fusion::vector
void sety(T y_)
set the y property
static const unsigned int s
s property is at position 3 in the boost::fusion::vector
void setv(size_t i, T v_)
set the v property
void setz(T z_)
set the z property
auto get() -> decltype(boost::fusion::at_c< i >(data))
getter method for a general property i
static const unsigned int v
v property is at position 4 in the boost::fusion::vector
void sets(T s_)
set the s property
static const unsigned int y
y property is at position 1 in the boost::fusion::vector
static const unsigned int z
z property is at position 2 in the boost::fusion::vector
void setx(T x_)
set the x property
void sett(size_t i, size_t j, T t_)
set the t property
static const unsigned int t
t property is at position 5 in the boost::fusion::vector
Implementation of 1-D std::vector like structure.
size_t size()
Stub size.