VCluster_unit_tests.cpp 6.56 KB
Newer Older
1 2 3 4 5 6 7 8
/*
 * VCluster_unit_tests.hpp
 *
 *  Created on: May 9, 2015
 *      Author: Pietro incardona
 */

#include <sstream>
9
#define BOOST_TEST_DYN_LINK
10
#include <boost/test/unit_test.hpp>
11
#include "timer.hpp"
incardon's avatar
incardon committed
12
#include <random>
13
#include "VCluster_unit_test_util.hpp"
14
#include "Point_test.hpp"
incardon's avatar
incardon committed
15
#include "VCluster_base.hpp"
16
#include "Vector/vector_test_util.hpp"
17 18
#include "VCluster/VCluster.hpp"
#include "VCluster/cuda/VCluster_unit_test_util_cuda.cuh"
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();
}

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();
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
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 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);
93 94
	vcl.execute();

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

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 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);
114 115
}

116
#define N_V_ELEMENTS 16
117

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

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
}
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
struct brt_test
{
	double a;
	double b;
};

BOOST_AUTO_TEST_CASE(VCluster_bcast_test)
{
163
	Vcluster<> & vcl = create_vcluster();
incardon's avatar
incardon committed
164

incardon's avatar
incardon committed
165
	std::cout << "Broadcast test " << std::endl;
incardon's avatar
incardon committed
166

167 168 169 170 171 172 173 174 175 176 177 178 179 180
	test_single_all_broadcast_primitives<unsigned char,HeapMemory,memory_traits_lin>(vcl);
	test_single_all_broadcast_primitives<char,HeapMemory,memory_traits_lin>(vcl);
	test_single_all_broadcast_primitives<short,HeapMemory,memory_traits_lin>(vcl);
	test_single_all_broadcast_primitives<unsigned short,HeapMemory,memory_traits_lin>(vcl);
	test_single_all_broadcast_primitives<int,HeapMemory,memory_traits_lin>(vcl);
	test_single_all_broadcast_primitives<unsigned int,HeapMemory,memory_traits_lin>(vcl);
	test_single_all_broadcast_primitives<long int,HeapMemory,memory_traits_lin>(vcl);
	test_single_all_broadcast_primitives<unsigned long int,HeapMemory,memory_traits_lin>(vcl);
	test_single_all_broadcast_primitives<float,HeapMemory,memory_traits_lin>(vcl);
	test_single_all_broadcast_primitives<double,HeapMemory,memory_traits_lin>(vcl);
}

BOOST_AUTO_TEST_CASE(VCluster_bcast_complex_test)
{
181
	Vcluster<> & vcl = create_vcluster();
182 183 184 185 186

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

	test_single_all_broadcast_complex<aggregate<int,int>,HeapMemory,memory_traits_lin>(vcl);
	test_single_all_broadcast_complex<aggregate<int,int>,HeapMemory,memory_traits_inte>(vcl);
incardon's avatar
incardon committed
187 188
}

189 190
BOOST_AUTO_TEST_CASE( VCluster_use_sendrecv)
{
incardon's avatar
incardon committed
191
	std::cout << "VCluster unit test start sendrecv" << "\n";
192

incardon's avatar
incardon committed
193
	totp_check = false;
incardon's avatar
incardon committed
194
	test<NBX>(RECEIVE_UNKNOWN);
195

196 197 198
	totp_check = false;
	test_no_send_some_peer<NBX>();

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

incardon's avatar
incardon committed
202 203 204 205 206 207 208 209 210 211 212 213 214
BOOST_AUTO_TEST_CASE( VCluster_use_sendrecv_size_known)
{
	std::cout << "VCluster unit test start sendrecv known size" << "\n";

	totp_check = false;
	test<NBX>(RECEIVE_SIZE_UNKNOWN);

	totp_check = false;
	test_no_send_some_peer<NBX>();

	std::cout << "VCluster unit test stop sendrecv known size" << "\n";
}

215
BOOST_AUTO_TEST_CASE( VCluster_use_sendrecv_known )
216
{
incardon's avatar
incardon committed
217
	std::cout << "VCluster unit test start known" << "\n";
218 219 220

	test_known<NBX>();

incardon's avatar
incardon committed
221
	std::cout << "VCluster unit test stop known" << "\n";
222 223 224 225
}



226 227
BOOST_AUTO_TEST_SUITE_END()