OpenFPM_pdata  1.1.0
Project that contain the implementation of distributed structures
 All Data Structures Namespaces Functions Variables Typedefs Enumerations Friends Pages
VCluster_unit_tests.hpp
1 /*
2  * VCluster_unit_tests.hpp
3  *
4  * Created on: May 9, 2015
5  * Author: Pietro incardona
6  */
7 
8 #ifndef VCLUSTER_UNIT_TESTS_HPP_
9 #define VCLUSTER_UNIT_TESTS_HPP_
10 
11 #include <sstream>
12 #include <boost/test/included/unit_test.hpp>
13 #include "timer.hpp"
14 #include <random>
15 #include "VCluster_unit_test_util.hpp"
16 #include "Point_test.hpp"
17 #include "VCluster_base.hpp"
18 #include "Vector/vector_test_util.hpp"
19 
20 BOOST_AUTO_TEST_SUITE( VCluster_test )
21 
22 BOOST_AUTO_TEST_CASE (Vcluster_robustness)
23 {
24  Vcluster & vcl = create_vcluster();
25 
26  vcl.execute();
27 }
28 
29 BOOST_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 
118 BOOST_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 
135 BOOST_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 
155 struct brt_test
156 {
157  double a;
158  double b;
159 };
160 
161 BOOST_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>(vcl);
168  test_single_all_broadcast_primitives<char>(vcl);
169  test_single_all_broadcast_primitives<short>(vcl);
170  test_single_all_broadcast_primitives<unsigned short>(vcl);
171  test_single_all_broadcast_primitives<int>(vcl);
172  test_single_all_broadcast_primitives<unsigned int>(vcl);
173  test_single_all_broadcast_primitives<long int>(vcl);
174  test_single_all_broadcast_primitives<unsigned long int>(vcl);
175  test_single_all_broadcast_primitives<float>(vcl);
176  test_single_all_broadcast_primitives<double>(vcl);
177 }
178 
179 BOOST_AUTO_TEST_CASE( VCluster_use_sendrecv)
180 {
181  std::cout << "VCluster unit test start sendrecv" << "\n";
182 
183  totp_check = false;
184  test<NBX>(RECEIVE_UNKNOWN);
185 
186  totp_check = false;
187  test_no_send_some_peer<NBX>();
188 
189  std::cout << "VCluster unit test stop sendrecv" << "\n";
190 }
191 
192 BOOST_AUTO_TEST_CASE( VCluster_use_sendrecv_size_known)
193 {
194  std::cout << "VCluster unit test start sendrecv known size" << "\n";
195 
196  totp_check = false;
197  test<NBX>(RECEIVE_SIZE_UNKNOWN);
198 
199  totp_check = false;
200  test_no_send_some_peer<NBX>();
201 
202  std::cout << "VCluster unit test stop sendrecv known size" << "\n";
203 }
204 
205 BOOST_AUTO_TEST_CASE( VCluster_use_sendrecv_known)
206 {
207  std::cout << "VCluster unit test start known" << "\n";
208 
209  test_known<NBX>();
210 
211  std::cout << "VCluster unit test stop known" << "\n";
212 }
213 
214 
215 
216 BOOST_AUTO_TEST_SUITE_END()
217 
218 
219 #endif /* VCLUSTER_UNIT_TESTS_HPP_ */
void sum(T &num)
Sum the numbers across all processors and get the result.
size_t getProcessUnitID()
Get the process unit id.
void execute()
Execute all the requests.
void max(T &num)
Get the maximum number across all processors (or reduction with infinity norm)
Implementation of VCluster class.
Definition: VCluster.hpp:36
size_t getProcessingUnits()
Get the total number of processors.