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

#ifndef VCLUSTER_UNIT_TESTS_HPP_
#define VCLUSTER_UNIT_TESTS_HPP_

#include "VCluster.hpp"
#include <sstream>
#include <boost/test/included/unit_test.hpp>
#include "timer.hpp"
incardon's avatar
incardon committed
15
#include <random>
16
#include "VCluster_unit_test_util.hpp"
17
#include "Point_test.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)
{
31
	Vcluster & vcl = create_vcluster();
incardon's avatar
incardon committed
32 33 34 35 36 37 38 39 40 41 42 43

	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
44 45 46 47 48 49 50 51 52 53 54 55
	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
56
	if ( vcl.getProcessingUnits() < 128 )
57
		vcl.sum(c);
incardon's avatar
incardon committed
58
	if ( vcl.getProcessingUnits() < 256 )
59
		vcl.sum(uc);
incardon's avatar
incardon committed
60
	if ( vcl.getProcessingUnits() < 32768 )
61
		vcl.sum(s);
incardon's avatar
incardon committed
62
	if ( vcl.getProcessingUnits() < 65536 )
63
		vcl.sum(us);
incardon's avatar
incardon committed
64
	if ( vcl.getProcessingUnits() < 2147483648 )
65
		vcl.sum(i);
incardon's avatar
incardon committed
66
	if ( vcl.getProcessingUnits() < 4294967296 )
67 68 69 70 71
		vcl.sum(ui);
	vcl.sum(li);
	vcl.sum(uli);
	vcl.sum(f);
	vcl.sum(d);
incardon's avatar
incardon committed
72 73 74 75 76 77 78

	// 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
79
		vcl.max(s_max);
incardon's avatar
incardon committed
80
	if ( vcl.getProcessingUnits() < 65536 )
incardon's avatar
incardon committed
81
		vcl.max(us_max);
incardon's avatar
incardon committed
82
	if ( vcl.getProcessingUnits() < 2147483648 )
incardon's avatar
incardon committed
83
		vcl.max(i_max);
incardon's avatar
incardon committed
84
	if ( vcl.getProcessingUnits() < 4294967296 )
incardon's avatar
incardon committed
85 86 87 88 89
		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
90 91 92
	vcl.execute();

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

105 106 107 108
	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
109 110
}

111
#define N_V_ELEMENTS 16
incardon's avatar
incardon committed
112

113 114
BOOST_AUTO_TEST_CASE(VCluster_send_recv)
{
115
	Vcluster & vcl = create_vcluster();
116

incardon's avatar
incardon committed
117 118 119 120 121 122 123 124 125 126 127
	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);
128
}
incardon's avatar
incardon committed
129

incardon's avatar
incardon committed
130 131
BOOST_AUTO_TEST_CASE(VCluster_allgather)
{
132
	Vcluster & vcl = create_vcluster();
incardon's avatar
incardon committed
133

134 135 136 137 138 139
	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
140 141 142 143 144 145 146 147 148 149
	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
150 151 152 153
BOOST_AUTO_TEST_CASE( VCluster_use_sendrecv)
{
	std::cout << "VCluster unit test start" << "\n";

incardon's avatar
incardon committed
154
	totp_check = false;
incardon's avatar
incardon committed
155 156
	test<NBX>();
	totp_check = true;
incardon's avatar
incardon committed
157
	test<PCX>();
incardon's avatar
incardon committed
158

159 160 161 162 163
	totp_check = false;
	test_no_send_some_peer<NBX>();
	totp_check = false;
	test_no_send_some_peer<PCX>();

incardon's avatar
incardon committed
164 165 166 167 168 169 170
	std::cout << "VCluster unit test stop" << "\n";
}

BOOST_AUTO_TEST_SUITE_END()


#endif /* VCLUSTER_UNIT_TESTS_HPP_ */