OpenFPM_pdata  4.1.0
Project that contain the implementation of distributed structures
 
Loading...
Searching...
No Matches
vector_dist_complex_prp_unit_test.cpp
1/*
2 * vector_dist_complex_prp_unit_test.hpp
3 *
4 * Created on: Sep 18, 2016
5 * Author: i-bird
6 */
7#define BOOST_TEST_DYN_LINK
8#include <boost/test/unit_test.hpp>
9
10#include "Vector/vector_dist.hpp"
11#include "Vector/performance/vector_dist_performance_util.hpp"
12#include "vector_dist_util_unit_tests.hpp"
13
14extern void print_test_v(std::string test, size_t sz);
15extern long int decrement(long int k, long int step);
16
17BOOST_AUTO_TEST_CASE( vector_dist_periodic_complex_prp_test_use_3d )
18{
19 Vcluster<> & v_cl = create_vcluster();
20
21 if (v_cl.getProcessingUnits() > 48)
22 return;
23
24 // set the seed
25 // create the random generator engine
26 std::srand(v_cl.getProcessUnitID());
27 std::default_random_engine eg;
28 std::uniform_real_distribution<float> ud(0.0f, 1.0f);
29
30#ifdef TEST_COVERAGE_MODE
31 long int k = 24288 * v_cl.getProcessingUnits();
32#else
33 long int k = 124288 * v_cl.getProcessingUnits();
34#endif
35
36 long int big_step = k / 4;
37 big_step = (big_step == 0)?1:big_step;
38
39 print_test_v( "Testing 3D vector full complex prp vector k<=",k);
40
41 // 3D test
42 for ( ; k >= 2 ; k-= decrement(k,big_step) )
43 {
44 BOOST_TEST_CHECKPOINT( "Testing 3D full complex prp vector k=" << k );
45
46 Box<3,float> box({0.0,0.0,0.0},{1.0,1.0,1.0});
47
48 // Boundary conditions
49 size_t bc[3]={NON_PERIODIC,NON_PERIODIC,NON_PERIODIC};
50
51 // factor
52 float factor = pow(create_vcluster().getProcessingUnits()/2.0f,1.0f/3.0f);
53
54 // ghost
55 Ghost<3,float> ghost(0.05 / factor);
56
57 // ghost2 (a little bigger because of round off error)
58 Ghost<3,float> ghost2(0.05001 / factor);
59
60 // Distributed vector
62
63 auto it = vd.getIterator();
64
65 while (it.isNext())
66 {
67 auto key = it.get();
68
69 vd.getPos(key)[0] = ud(eg);
70 vd.getPos(key)[1] = ud(eg);
71 vd.getPos(key)[2] = ud(eg);
72
73 // initalize vector property and grid
74
75 vd.getProp<0>(key).add(vd.getPos(key)[0]);
76 vd.getProp<0>(key).add(vd.getPos(key)[1]);
77 vd.getProp<0>(key).add(vd.getPos(key)[2]);
78
79 vd.getProp<0>(key).add(vd.getPos(key)[0]+vd.getPos(key)[1]);
80 vd.getProp<0>(key).add(vd.getPos(key)[1]+vd.getPos(key)[2]);
81 vd.getProp<0>(key).add(vd.getPos(key)[0]+vd.getPos(key)[2]);
82
83 // Grid
84 size_t sz[] = {3,3,3};
85 vd.getProp<1>(key).resize(sz);
86
87 vd.getProp<1>(key).get<0>({0,0,0}) = vd.getPos(key)[0];
88 vd.getProp<1>(key).get<0>({0,0,1}) = vd.getPos(key)[1];
89 vd.getProp<1>(key).get<0>({0,0,2}) = vd.getPos(key)[2];
90
91 vd.getProp<1>(key).get<0>({0,1,0}) = 2.0*vd.getPos(key)[0];
92 vd.getProp<1>(key).get<0>({0,1,1}) = 2.0*vd.getPos(key)[1];
93 vd.getProp<1>(key).get<0>({0,1,2}) = 2.0*vd.getPos(key)[2];
94
95 vd.getProp<1>(key).get<0>({0,2,0}) = 3.0*vd.getPos(key)[0];
96 vd.getProp<1>(key).get<0>({0,2,1}) = 3.0*vd.getPos(key)[1];
97 vd.getProp<1>(key).get<0>({0,2,2}) = 3.0*vd.getPos(key)[2];
98
99 vd.getProp<1>(key).get<0>({1,0,0}) = 4.0*vd.getPos(key)[0];
100 vd.getProp<1>(key).get<0>({1,0,1}) = 4.0*vd.getPos(key)[1];
101 vd.getProp<1>(key).get<0>({1,0,2}) = 4.0*vd.getPos(key)[2];
102
103 vd.getProp<1>(key).get<0>({1,1,0}) = 5.0*vd.getPos(key)[0];
104 vd.getProp<1>(key).get<0>({1,1,1}) = 5.0*vd.getPos(key)[1];
105 vd.getProp<1>(key).get<0>({1,1,2}) = 5.0*vd.getPos(key)[2];
106
107 vd.getProp<1>(key).get<0>({1,2,0}) = 6.0*vd.getPos(key)[0];
108 vd.getProp<1>(key).get<0>({1,2,1}) = 6.0*vd.getPos(key)[1];
109 vd.getProp<1>(key).get<0>({1,2,2}) = 6.0*vd.getPos(key)[2];
110
111 vd.getProp<1>(key).get<0>({2,0,0}) = 7.0*vd.getPos(key)[0];
112 vd.getProp<1>(key).get<0>({2,0,1}) = 7.0*vd.getPos(key)[1];
113 vd.getProp<1>(key).get<0>({2,0,2}) = 7.0*vd.getPos(key)[2];
114
115 vd.getProp<1>(key).get<0>({2,1,0}) = 8.0*vd.getPos(key)[0];
116 vd.getProp<1>(key).get<0>({2,1,1}) = 8.0*vd.getPos(key)[1];
117 vd.getProp<1>(key).get<0>({2,1,2}) = 8.0*vd.getPos(key)[2];
118
119 vd.getProp<1>(key).get<0>({2,2,0}) = 9.0*vd.getPos(key)[0];
120 vd.getProp<1>(key).get<0>({2,2,1}) = 9.0*vd.getPos(key)[1];
121 vd.getProp<1>(key).get<0>({2,2,2}) = 9.0*vd.getPos(key)[2];
122
123 ++it;
124 }
125
126 vd.map();
127
128 // sync the ghost
129 vd.ghost_get<0,1>();
130
131 // Domain + ghost
132 Box<3,float> dom_ext = box;
133 dom_ext.enlarge(ghost2);
134
135 // Iterate on all particles domain + ghost
136 size_t l_cnt = 0;
137 size_t nl_cnt = 0;
138 size_t n_out = 0;
139
140 auto it2 = vd.getIterator();
141 count_local_n_local<3,vector_dist<3,float, aggregate<openfpm::vector<float>,grid_cpu<3,aggregate<double,double[3]>>>> >(vd,it2,bc,box,dom_ext,l_cnt,nl_cnt,n_out);
142
143 // No particles should be out of domain + ghost
144 BOOST_REQUIRE_EQUAL(n_out,0ul);
145
146 // Ghost must populated because we synchronized them
147 if (k > 524288)
148 {
149 BOOST_REQUIRE(nl_cnt != 0);
150 BOOST_REQUIRE(l_cnt > nl_cnt);
151 }
152
153 // Sum all the particles inside the domain
154 v_cl.sum(l_cnt);
155 v_cl.execute();
156 BOOST_REQUIRE_EQUAL(l_cnt,(size_t)k);
157
158 l_cnt = 0;
159 nl_cnt = 0;
160
161 // Iterate only on the ghost particles
162 auto itg = vd.getGhostIterator();
163 count_local_n_local<3, vector_dist<3,float, aggregate<openfpm::vector<float>,grid_cpu<3,aggregate<double,double[3]>>>> >(vd,itg,bc,box,dom_ext,l_cnt,nl_cnt,n_out);
164
165 // No particle on the ghost must be inside the domain
166 BOOST_REQUIRE_EQUAL(l_cnt,0ul);
167
168 // Ghost must be populated
169 if (k > 524288)
170 {
171 BOOST_REQUIRE(nl_cnt != 0);
172 }
173
174 // check that the particles contain the correct information
175
176 bool ret = true;
177 auto it3 = vd.getDomainAndGhostIterator();
178
179 while (it3.isNext())
180 {
181 auto key = it3.get();
182
183 ret &= vd.getProp<0>(key).size() == 6;
184
185 ret &= vd.getProp<0>(key).get(0) == vd.getPos(key)[0];
186 ret &= vd.getProp<0>(key).get(1) == vd.getPos(key)[1];
187 ret &= vd.getProp<0>(key).get(2) == vd.getPos(key)[2];
188
189 ret &= vd.getProp<0>(key).get(3) == vd.getPos(key)[0]+vd.getPos(key)[1];
190 ret &= vd.getProp<0>(key).get(4) == vd.getPos(key)[1]+vd.getPos(key)[2];
191 ret &= vd.getProp<0>(key).get(5) == vd.getPos(key)[0]+vd.getPos(key)[2];
192
193// BOOST_REQUIRE_EQUAL(vd.getProp<0>(key).get(0),vd.getPos(key)[0]);
194
195 ret &= vd.getProp<1>(key).size() == 3*3*3;
196 ret &= vd.getProp<1>(key).get<0>({0,0,0}) == vd.getPos(key)[0];
197 ret &= vd.getProp<1>(key).get<0>({0,0,1}) == vd.getPos(key)[1];
198 ret &= vd.getProp<1>(key).get<0>({0,0,2}) == vd.getPos(key)[2];
199
200 ret &= vd.getProp<1>(key).get<0>({0,1,0}) == 2.0*vd.getPos(key)[0];
201 ret &= vd.getProp<1>(key).get<0>({0,1,1}) == 2.0*vd.getPos(key)[1];
202 ret &= vd.getProp<1>(key).get<0>({0,1,2}) == 2.0*vd.getPos(key)[2];
203
204 ret &= vd.getProp<1>(key).get<0>({0,2,0}) == 3.0*vd.getPos(key)[0];
205 ret &= vd.getProp<1>(key).get<0>({0,2,1}) == 3.0*vd.getPos(key)[1];
206 ret &= vd.getProp<1>(key).get<0>({0,2,2}) == 3.0*vd.getPos(key)[2];
207
208 ret &= vd.getProp<1>(key).get<0>({1,0,0}) == 4.0*vd.getPos(key)[0];
209 ret &= vd.getProp<1>(key).get<0>({1,0,1}) == 4.0*vd.getPos(key)[1];
210 ret &= vd.getProp<1>(key).get<0>({1,0,2}) == 4.0*vd.getPos(key)[2];
211
212 ret &= vd.getProp<1>(key).get<0>({1,1,0}) == 5.0*vd.getPos(key)[0];
213 ret &= vd.getProp<1>(key).get<0>({1,1,1}) == 5.0*vd.getPos(key)[1];
214 ret &= vd.getProp<1>(key).get<0>({1,1,2}) == 5.0*vd.getPos(key)[2];
215
216 ret &= vd.getProp<1>(key).get<0>({1,2,0}) == 6.0*vd.getPos(key)[0];
217 ret &= vd.getProp<1>(key).get<0>({1,2,1}) == 6.0*vd.getPos(key)[1];
218 ret &= vd.getProp<1>(key).get<0>({1,2,2}) == 6.0*vd.getPos(key)[2];
219
220 ret &= vd.getProp<1>(key).get<0>({2,0,0}) == 7.0*vd.getPos(key)[0];
221 ret &= vd.getProp<1>(key).get<0>({2,0,1}) == 7.0*vd.getPos(key)[1];
222 ret &= vd.getProp<1>(key).get<0>({2,0,2}) == 7.0*vd.getPos(key)[2];
223
224 ret &= vd.getProp<1>(key).get<0>({2,1,0}) == 8.0*vd.getPos(key)[0];
225 ret &= vd.getProp<1>(key).get<0>({2,1,1}) == 8.0*vd.getPos(key)[1];
226 ret &= vd.getProp<1>(key).get<0>({2,1,2}) == 8.0*vd.getPos(key)[2];
227
228 ret &= vd.getProp<1>(key).get<0>({2,2,0}) == 9.0*vd.getPos(key)[0];
229 ret &= vd.getProp<1>(key).get<0>({2,2,1}) == 9.0*vd.getPos(key)[1];
230 ret &= vd.getProp<1>(key).get<0>({2,2,2}) == 9.0*vd.getPos(key)[2];
231
232 ++it3;
233 }
234
235 BOOST_REQUIRE_EQUAL(ret,true);
236 }
237}
238
239
This class represent an N-dimensional box.
Definition Box.hpp:61
void enlarge(const Box< dim, T > &gh)
Enlarge the box with ghost margin.
Definition Box.hpp:823
void execute()
Execute all the requests.
void sum(T &num)
Sum the numbers across all processors and get the result.
size_t getProcessUnitID()
Get the process unit id.
size_t getProcessingUnits()
Get the total number of processors.
Implementation of VCluster class.
Definition VCluster.hpp:59
Distributed vector.