VCluster_unit_tests.hpp 5.62 KB
Newer Older
incardon's avatar
incardon committed
1
2
3
4
5
6
7
8
9
10
11
12
13
/*
 * VCluster_unit_tests.hpp
 *
 *  Created on: May 9, 2015
 *      Author: Pietro incardona
 */

#ifndef VCLUSTER_UNIT_TESTS_HPP_
#define VCLUSTER_UNIT_TESTS_HPP_

#include <sstream>
#include <boost/test/included/unit_test.hpp>
#include "timer.hpp"
incardon's avatar
incardon committed
14
#include <random>
15
#include "VCluster_unit_test_util.hpp"
16
#include "Point_test.hpp"
incardon's avatar
incardon committed
17
#include "VCluster_base.hpp"
18
#include "Vector/vector_test_util.hpp"
incardon's avatar
incardon committed
19
20
21

BOOST_AUTO_TEST_SUITE( VCluster_test )

incardon's avatar
incardon committed
22
23
BOOST_AUTO_TEST_CASE (Vcluster_robustness)
{
24
	Vcluster & vcl = create_vcluster();
incardon's avatar
incardon committed
25
26
27
28

	vcl.execute();
}

incardon's avatar
incardon committed
29
30
BOOST_AUTO_TEST_CASE( VCluster_use_reductions)
{
incardon's avatar
incardon committed
31
32
33

	//! [max min sum]

34
	Vcluster & vcl = create_vcluster();
incardon's avatar
incardon committed
35
36
37
38
39
40
41
42
43
44
45
46

	unsigned char uc = 1;
	char c = 1;
	short s = 1;
	unsigned short us = 1;
	int i = 1;
	unsigned int ui = 1;
	long int li = 1;
	unsigned long int uli = 1;
	float f = 1;
	double d = 1;

incardon's avatar
incardon committed
47
48
49
50
51
52
53
54
55
56
57
58
	unsigned char uc_max = vcl.getProcessUnitID();
	char c_max = vcl.getProcessUnitID();
	short s_max = vcl.getProcessUnitID();
	unsigned short us_max = vcl.getProcessUnitID();
	int i_max = vcl.getProcessUnitID();
	unsigned int ui_max = vcl.getProcessUnitID();
	long int li_max = vcl.getProcessUnitID();
	unsigned long int uli_max = vcl.getProcessUnitID();
	float f_max = vcl.getProcessUnitID();
	double d_max = vcl.getProcessUnitID();

	// Sum reductions
incardon's avatar
incardon committed
59
	if ( vcl.getProcessingUnits() < 128 )
60
		vcl.sum(c);
incardon's avatar
incardon committed
61
	if ( vcl.getProcessingUnits() < 256 )
62
		vcl.sum(uc);
incardon's avatar
incardon committed
63
	if ( vcl.getProcessingUnits() < 32768 )
64
		vcl.sum(s);
incardon's avatar
incardon committed
65
	if ( vcl.getProcessingUnits() < 65536 )
66
		vcl.sum(us);
incardon's avatar
incardon committed
67
	if ( vcl.getProcessingUnits() < 2147483648 )
68
		vcl.sum(i);
incardon's avatar
incardon committed
69
	if ( vcl.getProcessingUnits() < 4294967296 )
70
71
72
73
74
		vcl.sum(ui);
	vcl.sum(li);
	vcl.sum(uli);
	vcl.sum(f);
	vcl.sum(d);
incardon's avatar
incardon committed
75
76
77
78
79
80
81

	// Max reduction
	if ( vcl.getProcessingUnits() < 128 )
		vcl.max(c_max);
	if ( vcl.getProcessingUnits() < 256 )
		vcl.max(uc_max);
	if ( vcl.getProcessingUnits() < 32768 )
incardon's avatar
incardon committed
82
		vcl.max(s_max);
incardon's avatar
incardon committed
83
	if ( vcl.getProcessingUnits() < 65536 )
incardon's avatar
incardon committed
84
		vcl.max(us_max);
incardon's avatar
incardon committed
85
	if ( vcl.getProcessingUnits() < 2147483648 )
incardon's avatar
incardon committed
86
		vcl.max(i_max);
incardon's avatar
incardon committed
87
	if ( vcl.getProcessingUnits() < 4294967296 )
incardon's avatar
incardon committed
88
89
90
91
92
		vcl.max(ui_max);
	vcl.max(li_max);
	vcl.max(uli_max);
	vcl.max(f_max);
	vcl.max(d_max);
incardon's avatar
incardon committed
93
94
	vcl.execute();

incardon's avatar
incardon committed
95
96
	//! [max min sum]

incardon's avatar
incardon committed
97
	if ( vcl.getProcessingUnits() < 128 )
98
	{BOOST_REQUIRE_EQUAL(c_max,(char)vcl.getProcessingUnits()-1);}
incardon's avatar
incardon committed
99
	if ( vcl.getProcessingUnits() < 256 )
100
	{BOOST_REQUIRE_EQUAL(uc_max,(unsigned char)vcl.getProcessingUnits()-1);}
incardon's avatar
incardon committed
101
	if ( vcl.getProcessingUnits() < 32768 )
102
	{BOOST_REQUIRE_EQUAL(s_max,(short int) vcl.getProcessingUnits()-1);}
incardon's avatar
incardon committed
103
	if ( vcl.getProcessingUnits() < 65536 )
104
	{BOOST_REQUIRE_EQUAL(us_max,(unsigned short)vcl.getProcessingUnits()-1);}
incardon's avatar
incardon committed
105
	if ( vcl.getProcessingUnits() < 2147483648 )
106
	{BOOST_REQUIRE_EQUAL(i_max,(int)vcl.getProcessingUnits()-1);}
incardon's avatar
incardon committed
107
	if ( vcl.getProcessingUnits() < 4294967296 )
108
	{BOOST_REQUIRE_EQUAL(ui_max,(unsigned int)vcl.getProcessingUnits()-1);}
incardon's avatar
incardon committed
109

110
111
112
113
	BOOST_REQUIRE_EQUAL(li_max,(long int)vcl.getProcessingUnits()-1);
	BOOST_REQUIRE_EQUAL(uli_max,(unsigned long int)vcl.getProcessingUnits()-1);
	BOOST_REQUIRE_EQUAL(f_max,(float)vcl.getProcessingUnits()-1);
	BOOST_REQUIRE_EQUAL(d_max,(double)vcl.getProcessingUnits()-1);
incardon's avatar
incardon committed
114
115
}

116
#define N_V_ELEMENTS 16
incardon's avatar
incardon committed
117

118
119
BOOST_AUTO_TEST_CASE(VCluster_send_recv)
{
120
	Vcluster & vcl = create_vcluster();
121

incardon's avatar
incardon committed
122
123
124
125
126
127
128
129
130
131
132
	test_send_recv_complex(N_V_ELEMENTS,vcl);
	test_send_recv_primitives<unsigned char>(N_V_ELEMENTS,vcl);
	test_send_recv_primitives<char>(N_V_ELEMENTS,vcl);
	test_send_recv_primitives<short>(N_V_ELEMENTS,vcl);
	test_send_recv_primitives<unsigned short>(N_V_ELEMENTS,vcl);
	test_send_recv_primitives<int>(N_V_ELEMENTS,vcl);
	test_send_recv_primitives<unsigned int>(N_V_ELEMENTS,vcl);
	test_send_recv_primitives<long int>(N_V_ELEMENTS,vcl);
	test_send_recv_primitives<unsigned long int>(N_V_ELEMENTS,vcl);
	test_send_recv_primitives<float>(N_V_ELEMENTS,vcl);
	test_send_recv_primitives<double>(N_V_ELEMENTS,vcl);
133
}
incardon's avatar
incardon committed
134

incardon's avatar
incardon committed
135
136
BOOST_AUTO_TEST_CASE(VCluster_allgather)
{
137
	Vcluster & vcl = create_vcluster();
incardon's avatar
incardon committed
138

139
140
141
142
143
144
	if (vcl.getProcessingUnits() < 256)
		test_single_all_gather_primitives<unsigned char>(vcl);

	if (vcl.getProcessingUnits() < 128)
		test_single_all_gather_primitives<char>(vcl);

incardon's avatar
incardon committed
145
146
147
148
149
150
151
152
153
154
	test_single_all_gather_primitives<short>(vcl);
	test_single_all_gather_primitives<unsigned short>(vcl);
	test_single_all_gather_primitives<int>(vcl);
	test_single_all_gather_primitives<unsigned int>(vcl);
	test_single_all_gather_primitives<long int>(vcl);
	test_single_all_gather_primitives<unsigned long int>(vcl);
	test_single_all_gather_primitives<float>(vcl);
	test_single_all_gather_primitives<double>(vcl);
}

incardon's avatar
incardon committed
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
struct brt_test
{
	double a;
	double b;
};

BOOST_AUTO_TEST_CASE(VCluster_bcast_test)
{
	Vcluster & vcl = create_vcluster();

	std::cout << "Broadcast test" << std::endl;

	test_single_all_broadcast_primitives<unsigned char>(vcl);
	test_single_all_broadcast_primitives<char>(vcl);
	test_single_all_broadcast_primitives<short>(vcl);
	test_single_all_broadcast_primitives<unsigned short>(vcl);
	test_single_all_broadcast_primitives<int>(vcl);
	test_single_all_broadcast_primitives<unsigned int>(vcl);
	test_single_all_broadcast_primitives<long int>(vcl);
	test_single_all_broadcast_primitives<unsigned long int>(vcl);
	test_single_all_broadcast_primitives<float>(vcl);
	test_single_all_broadcast_primitives<double>(vcl);
}

incardon's avatar
incardon committed
179
180
BOOST_AUTO_TEST_CASE( VCluster_use_sendrecv)
{
incardon's avatar
incardon committed
181
	std::cout << "VCluster unit test start sendrecv" << "\n";
incardon's avatar
incardon committed
182

incardon's avatar
incardon committed
183
	totp_check = false;
incardon's avatar
incardon committed
184
	test<NBX>();
incardon's avatar
incardon committed
185

186
187
188
	totp_check = false;
	test_no_send_some_peer<NBX>();

incardon's avatar
incardon committed
189
	std::cout << "VCluster unit test stop sendrecv" << "\n";
incardon's avatar
incardon committed
190
191
}

incardon's avatar
incardon committed
192
193
BOOST_AUTO_TEST_CASE( VCluster_use_sendrecv_known)
{
incardon's avatar
incardon committed
194
	std::cout << "VCluster unit test start known" << "\n";
incardon's avatar
incardon committed
195
196
197

	test_known<NBX>();

incardon's avatar
incardon committed
198
	std::cout << "VCluster unit test stop known" << "\n";
incardon's avatar
incardon committed
199
200
201
202
}



incardon's avatar
incardon committed
203
204
205
206
BOOST_AUTO_TEST_SUITE_END()


#endif /* VCLUSTER_UNIT_TESTS_HPP_ */