OpenFPM_pdata  4.1.0
Project that contain the implementation of distributed structures
 
Loading...
Searching...
No Matches
VCluster_unit_tests.cpp
1/*
2 * VCluster_unit_tests.hpp
3 *
4 * Created on: May 9, 2015
5 * Author: Pietro incardona
6 */
7
8#include <sstream>
9#define BOOST_TEST_DYN_LINK
10#include <boost/test/unit_test.hpp>
11#include "timer.hpp"
12#include <random>
13#include "VCluster_unit_test_util.hpp"
14#include "Point_test.hpp"
15#include "VCluster_base.hpp"
16#include "Vector/vector_test_util.hpp"
17#include "VCluster/VCluster.hpp"
18#include "VCluster/cuda/VCluster_unit_test_util_cuda.cuh"
19
20BOOST_AUTO_TEST_SUITE( VCluster_test )
21
22BOOST_AUTO_TEST_CASE (Vcluster_robustness)
23{
24 Vcluster<> & vcl = create_vcluster();
25
26 vcl.execute();
27}
28
29BOOST_AUTO_TEST_CASE( VCluster_use_reductions)
30{
31
33
34 Vcluster<> & vcl = create_vcluster();
35
36 unsigned char uc = 1;
37 char c = 1;
38 short s = 1;
39 unsigned short us = 1;
40 int i = 1;
41 unsigned int ui = 1;
42 long int li = 1;
43 unsigned long int uli = 1;
44 float f = 1;
45 double d = 1;
46
47 unsigned char uc_max = vcl.getProcessUnitID();
48 char c_max = vcl.getProcessUnitID();
49 short s_max = vcl.getProcessUnitID();
50 unsigned short us_max = vcl.getProcessUnitID();
51 int i_max = vcl.getProcessUnitID();
52 unsigned int ui_max = vcl.getProcessUnitID();
53 long int li_max = vcl.getProcessUnitID();
54 unsigned long int uli_max = vcl.getProcessUnitID();
55 float f_max = vcl.getProcessUnitID();
56 double d_max = vcl.getProcessUnitID();
57
58 // Sum reductions
59 if ( vcl.getProcessingUnits() < 128 )
60 vcl.sum(c);
61 if ( vcl.getProcessingUnits() < 256 )
62 vcl.sum(uc);
63 if ( vcl.getProcessingUnits() < 32768 )
64 vcl.sum(s);
65 if ( vcl.getProcessingUnits() < 65536 )
66 vcl.sum(us);
67 if ( vcl.getProcessingUnits() < 2147483648 )
68 vcl.sum(i);
69 if ( vcl.getProcessingUnits() < 4294967296 )
70 vcl.sum(ui);
71 vcl.sum(li);
72 vcl.sum(uli);
73 vcl.sum(f);
74 vcl.sum(d);
75
76 // Max reduction
77 if ( vcl.getProcessingUnits() < 128 )
78 vcl.max(c_max);
79 if ( vcl.getProcessingUnits() < 256 )
80 vcl.max(uc_max);
81 if ( vcl.getProcessingUnits() < 32768 )
82 vcl.max(s_max);
83 if ( vcl.getProcessingUnits() < 65536 )
84 vcl.max(us_max);
85 if ( vcl.getProcessingUnits() < 2147483648 )
86 vcl.max(i_max);
87 if ( vcl.getProcessingUnits() < 4294967296 )
88 vcl.max(ui_max);
89 vcl.max(li_max);
90 vcl.max(uli_max);
91 vcl.max(f_max);
92 vcl.max(d_max);
93 vcl.execute();
94
96
97 if ( vcl.getProcessingUnits() < 128 )
98 {BOOST_REQUIRE_EQUAL(c_max,(char)vcl.getProcessingUnits()-1);}
99 if ( vcl.getProcessingUnits() < 256 )
100 {BOOST_REQUIRE_EQUAL(uc_max,(unsigned char)vcl.getProcessingUnits()-1);}
101 if ( vcl.getProcessingUnits() < 32768 )
102 {BOOST_REQUIRE_EQUAL(s_max,(short int) vcl.getProcessingUnits()-1);}
103 if ( vcl.getProcessingUnits() < 65536 )
104 {BOOST_REQUIRE_EQUAL(us_max,(unsigned short)vcl.getProcessingUnits()-1);}
105 if ( vcl.getProcessingUnits() < 2147483648 )
106 {BOOST_REQUIRE_EQUAL(i_max,(int)vcl.getProcessingUnits()-1);}
107 if ( vcl.getProcessingUnits() < 4294967296 )
108 {BOOST_REQUIRE_EQUAL(ui_max,(unsigned int)vcl.getProcessingUnits()-1);}
109
110 BOOST_REQUIRE_EQUAL(li_max,(long int)vcl.getProcessingUnits()-1);
111 BOOST_REQUIRE_EQUAL(uli_max,(unsigned long int)vcl.getProcessingUnits()-1);
112 BOOST_REQUIRE_EQUAL(f_max,(float)vcl.getProcessingUnits()-1);
113 BOOST_REQUIRE_EQUAL(d_max,(double)vcl.getProcessingUnits()-1);
114}
115
116#define N_V_ELEMENTS 16
117
118BOOST_AUTO_TEST_CASE(VCluster_send_recv)
119{
120 Vcluster<> & vcl = create_vcluster();
121
122 test_send_recv_complex(N_V_ELEMENTS,vcl);
123 test_send_recv_primitives<unsigned char>(N_V_ELEMENTS,vcl);
124 test_send_recv_primitives<char>(N_V_ELEMENTS,vcl);
125 test_send_recv_primitives<short>(N_V_ELEMENTS,vcl);
126 test_send_recv_primitives<unsigned short>(N_V_ELEMENTS,vcl);
127 test_send_recv_primitives<int>(N_V_ELEMENTS,vcl);
128 test_send_recv_primitives<unsigned int>(N_V_ELEMENTS,vcl);
129 test_send_recv_primitives<long int>(N_V_ELEMENTS,vcl);
130 test_send_recv_primitives<unsigned long int>(N_V_ELEMENTS,vcl);
131 test_send_recv_primitives<float>(N_V_ELEMENTS,vcl);
132 test_send_recv_primitives<double>(N_V_ELEMENTS,vcl);
133}
134
135BOOST_AUTO_TEST_CASE(VCluster_allgather)
136{
137 Vcluster<> & vcl = create_vcluster();
138
139 if (vcl.getProcessingUnits() < 256)
140 test_single_all_gather_primitives<unsigned char>(vcl);
141
142 if (vcl.getProcessingUnits() < 128)
143 test_single_all_gather_primitives<char>(vcl);
144
145 test_single_all_gather_primitives<short>(vcl);
146 test_single_all_gather_primitives<unsigned short>(vcl);
147 test_single_all_gather_primitives<int>(vcl);
148 test_single_all_gather_primitives<unsigned int>(vcl);
149 test_single_all_gather_primitives<long int>(vcl);
150 test_single_all_gather_primitives<unsigned long int>(vcl);
151 test_single_all_gather_primitives<float>(vcl);
152 test_single_all_gather_primitives<double>(vcl);
153}
154
156{
157 double a;
158 double b;
159};
160
161BOOST_AUTO_TEST_CASE(VCluster_bcast_test)
162{
163 Vcluster<> & vcl = create_vcluster();
164
165 std::cout << "Broadcast test " << std::endl;
166
167 test_single_all_broadcast_primitives<unsigned char,HeapMemory,memory_traits_lin>(vcl);
168 test_single_all_broadcast_primitives<char,HeapMemory,memory_traits_lin>(vcl);
169 test_single_all_broadcast_primitives<short,HeapMemory,memory_traits_lin>(vcl);
170 test_single_all_broadcast_primitives<unsigned short,HeapMemory,memory_traits_lin>(vcl);
171 test_single_all_broadcast_primitives<int,HeapMemory,memory_traits_lin>(vcl);
172 test_single_all_broadcast_primitives<unsigned int,HeapMemory,memory_traits_lin>(vcl);
173 test_single_all_broadcast_primitives<long int,HeapMemory,memory_traits_lin>(vcl);
174 test_single_all_broadcast_primitives<unsigned long int,HeapMemory,memory_traits_lin>(vcl);
175 test_single_all_broadcast_primitives<float,HeapMemory,memory_traits_lin>(vcl);
176 test_single_all_broadcast_primitives<double,HeapMemory,memory_traits_lin>(vcl);
177}
178
179BOOST_AUTO_TEST_CASE(VCluster_bcast_complex_test)
180{
181 Vcluster<> & vcl = create_vcluster();
182
183 std::cout << "Broadcast complex test " << std::endl;
184
185 test_single_all_broadcast_complex<aggregate<int,int>,HeapMemory,memory_traits_lin>(vcl);
186 test_single_all_broadcast_complex<aggregate<int,int>,HeapMemory,memory_traits_inte>(vcl);
187}
188
189BOOST_AUTO_TEST_CASE( VCluster_use_sendrecv_short_unkn)
190{
191 std::cout << "VCluster unit test start sendrecv short unknown" << "\n";
192
193 totp_check = false;
194 test_short<NBX>(RECEIVE_UNKNOWN);
195
196 std::cout << "VCluster unit test stop sendrecv short unknown" << "\n";
197}
198
199BOOST_AUTO_TEST_CASE( VCluster_use_sendrecv_short_unkn_async)
200{
201 std::cout << "VCluster unit test start sendrecv short unknown async" << "\n";
202
203 totp_check = false;
204 test_short<NBX_ASYNC>(RECEIVE_UNKNOWN);
205
206 std::cout << "VCluster unit test stop sendrecv short unknown async" << "\n";
207}
208
209BOOST_AUTO_TEST_CASE( VCluster_use_sendrecv_short_unkn_async_multiple)
210{
211 std::cout << "VCluster unit test start sendrecv short unknown async multiple" << "\n";
212
213 totp_check = false;
214 test_short_multiple<NBX_ASYNC>(RECEIVE_UNKNOWN);
215
216 std::cout << "VCluster unit test stop sendrecv short unknown async multiple" << "\n";
217}
218
219BOOST_AUTO_TEST_CASE( VCluster_use_sendrecv_rand_unkn)
220{
221 std::cout << "VCluster unit test start sendrecv random unknown" << "\n";
222
223 totp_check = false;
224 test_random<NBX>(RECEIVE_UNKNOWN);
225
226 std::cout << "VCluster unit test stop sendrecv random unknown" << "\n";
227}
228
229BOOST_AUTO_TEST_CASE( VCluster_use_sendrecv_rand_unkn_async)
230{
231 std::cout << "VCluster unit test start sendrecv random unknown async" << "\n";
232
233 totp_check = false;
234 test_random<NBX_ASYNC>(RECEIVE_UNKNOWN);
235
236 std::cout << "VCluster unit test stop sendrecv random unknown async" << "\n";
237}
238
239BOOST_AUTO_TEST_CASE( VCluster_use_sendrecv_rand_unkn_async_multiple)
240{
241 std::cout << "VCluster unit test start sendrecv random unknown async" << "\n";
242
243 totp_check = false;
244 test_random_multiple<NBX_ASYNC>(RECEIVE_UNKNOWN);
245
246 std::cout << "VCluster unit test stop sendrecv random unknown async" << "\n";
247}
248
249
250BOOST_AUTO_TEST_CASE( VCluster_use_sendrecv_someempty)
251{
252 std::cout << "VCluster unit test start sendrecv some empty" << "\n";
253
254 totp_check = false;
255 test_no_send_some_peer<NBX>();
256
257 std::cout << "VCluster unit test stop sendrecv some empty" << "\n";
258}
259
260BOOST_AUTO_TEST_CASE( VCluster_use_sendrecv_short_prc_known)
261{
262 std::cout << "VCluster unit test start sendrecv short known prc" << "\n";
263
264 totp_check = false;
265 test_short<NBX>(RECEIVE_SIZE_UNKNOWN);
266
267 std::cout << "VCluster unit test stop sendrecv short known prc" << "\n";
268}
269
270BOOST_AUTO_TEST_CASE( VCluster_use_sendrecv_short_prc_known_multiple)
271{
272 std::cout << "VCluster unit test start sendrecv short known prc" << "\n";
273
274 totp_check = false;
275 test_short_multiple<NBX>(RECEIVE_SIZE_UNKNOWN);
276
277 std::cout << "VCluster unit test stop sendrecv short known prc" << "\n";
278}
279
280BOOST_AUTO_TEST_CASE( VCluster_use_sendrecv_random_prc_known)
281{
282 std::cout << "VCluster unit test start sendrecv random known prc" << "\n";
283
284 totp_check = false;
285 test_random<NBX>(RECEIVE_SIZE_UNKNOWN);
286
287 std::cout << "VCluster unit test stop sendrecv random known prc" << "\n";
288}
289
290BOOST_AUTO_TEST_CASE( VCluster_use_sendrecv_known )
291{
292 std::cout << "VCluster unit test start known" << "\n";
293
294 test_known<NBX>(0);
295
296 std::cout << "VCluster unit test stop known" << "\n";
297}
298
299BOOST_AUTO_TEST_CASE( VCluster_use_sendrecv_known_async )
300{
301 std::cout << "VCluster unit test start known" << "\n";
302
303 test_known<NBX_ASYNC>(0);
304
305 std::cout << "VCluster unit test stop known" << "\n";
306}
307
308BOOST_AUTO_TEST_CASE( VCluster_use_sendrecv_known_async_multiple )
309{
310 std::cout << "VCluster unit test start known" << "\n";
311
312 test_known_multiple<NBX_ASYNC>(0);
313
314 std::cout << "VCluster unit test stop known" << "\n";
315}
316
317BOOST_AUTO_TEST_CASE( VCluster_use_sendrecv_known_prc )
318{
319 std::cout << "VCluster unit test start known prc" << "\n";
320
321 test_known<NBX>(KNOWN_PRC);
322
323 std::cout << "VCluster unit test stop known prc" << "\n";
324}
325
326BOOST_AUTO_TEST_CASE( VCluster_use_sendrecv_known_prc_async )
327{
328 std::cout << "VCluster unit test start known prc" << "\n";
329
330 test_known<NBX_ASYNC>(KNOWN_PRC);
331
332 std::cout << "VCluster unit test stop known prc" << "\n";
333}
334
335BOOST_AUTO_TEST_CASE( VCluster_use_sendrecv_known_prc_async_multiple )
336{
337 std::cout << "VCluster unit test start known prc" << "\n";
338
339 test_known_multiple<NBX_ASYNC>(KNOWN_PRC);
340
341 std::cout << "VCluster unit test stop known prc" << "\n";
342}
343
344BOOST_AUTO_TEST_SUITE_END()
345
This class allocate, and destroy CPU memory.
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.
void max(T &num)
Get the maximum number across all processors (or reduction with infinity norm)
Implementation of VCluster class.
Definition VCluster.hpp:59
Transform the boost::fusion::vector into memory specification (memory_traits)
Transform the boost::fusion::vector into memory specification (memory_traits)