VCluster_semantic_unit_tests.hpp 8.94 KB
Newer Older
1 2 3 4 5 6 7 8 9 10
/*
 * VCluster_semantic_unit_test.hpp
 *
 *  Created on: Feb 8, 2016
 *      Author: i-bird
 */

#ifndef OPENFPM_VCLUSTER_SRC_VCLUSTER_SEMANTIC_UNIT_TESTS_HPP_
#define OPENFPM_VCLUSTER_SRC_VCLUSTER_SEMANTIC_UNIT_TESTS_HPP_

Yaroslav's avatar
Yaroslav committed
11 12
#include "data_type/aggregate.hpp"

13 14 15 16 17 18 19 20 21 22 23 24
struct A
{
	size_t a;
	float b;
	double c;
};


BOOST_AUTO_TEST_SUITE( VCluster_semantic_test )

BOOST_AUTO_TEST_CASE (Vcluster_semantic_gather)
{
25
	for (size_t i = 0 ; i < 100 ; i++)
26
	{
27
		Vcluster & vcl = create_vcluster();
Pietro Incardona's avatar
Pietro Incardona committed
28 29 30

		if (vcl.getProcessingUnits() >= 32)
			return;
31

Pietro Incardona's avatar
Pietro Incardona committed
32 33
		openfpm::vector<size_t> v1;
		v1.resize(vcl.getProcessUnitID());
34

Pietro Incardona's avatar
Pietro Incardona committed
35 36 37 38 39
		for(size_t i = 0 ; i < vcl.getProcessUnitID() ; i++)
			v1.get(i) = 5;

		openfpm::vector<size_t> v2;

40
		vcl.SGather(v1,v2,(i%vcl.getProcessingUnits()));
Pietro Incardona's avatar
Pietro Incardona committed
41

42
		if (vcl.getProcessUnitID() == (i%vcl.getProcessingUnits()))
Pietro Incardona's avatar
Pietro Incardona committed
43 44 45 46 47 48 49 50 51 52
		{
			size_t n = vcl.getProcessingUnits();
			BOOST_REQUIRE_EQUAL(v2.size(),n*(n-1)/2);

			bool is_five = true;
			for (size_t i = 0 ; i < v2.size() ; i++)
				is_five &= (v2.get(i) == 5);

			BOOST_REQUIRE_EQUAL(is_five,true);
		}
53 54 55 56 57 58
	}
}


BOOST_AUTO_TEST_CASE (Vcluster_semantic_struct_gather)
{
59
	for (size_t i = 0 ; i < 100 ; i++)
60
	{
61
		Vcluster & vcl = create_vcluster();
Pietro Incardona's avatar
Pietro Incardona committed
62 63 64

		if (vcl.getProcessingUnits() >= 32)
			return;
65

Pietro Incardona's avatar
Pietro Incardona committed
66 67 68 69
		openfpm::vector<A> v1;
		v1.resize(vcl.getProcessUnitID());

		for(size_t i = 0 ; i < vcl.getProcessUnitID() ; i++)
70
		{
Pietro Incardona's avatar
Pietro Incardona committed
71 72 73
			v1.get(i).a = 5;
			v1.get(i).b = 10.0;
			v1.get(i).c = 11.0;
74 75
		}

Pietro Incardona's avatar
Pietro Incardona committed
76 77
		openfpm::vector<A> v2;

78
		vcl.SGather(v1,v2,(i%vcl.getProcessingUnits()));
Pietro Incardona's avatar
Pietro Incardona committed
79

80
		if (vcl.getProcessUnitID() == (i%vcl.getProcessingUnits()))
Pietro Incardona's avatar
Pietro Incardona committed
81 82 83 84 85 86 87 88 89 90 91 92 93 94
		{
			size_t n = vcl.getProcessingUnits();
			BOOST_REQUIRE_EQUAL(v2.size(),n*(n-1)/2);

			bool is_correct = true;
			for (size_t i = 0 ; i < v2.size() ; i++)
			{
				is_correct &= (v2.get(i).a == 5);
				is_correct &= (v2.get(i).b == 10.0);
				is_correct &= (v2.get(i).c == 11.0);
			}

			BOOST_REQUIRE_EQUAL(is_correct,true);
		}
95 96 97
	}
}

Pietro Incardona's avatar
Pietro Incardona committed
98 99 100 101 102 103
#define SSCATTER_MAX 7

BOOST_AUTO_TEST_CASE (Vcluster_semantic_scatter)
{
	for (size_t i = 0 ; i < 100 ; i++)
	{
104
		Vcluster & vcl = create_vcluster();
Pietro Incardona's avatar
Pietro Incardona committed
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149

		if (vcl.getProcessingUnits() >= 32)
			return;

		size_t nc = vcl.getProcessingUnits() / SSCATTER_MAX;
		size_t nr = vcl.getProcessingUnits() - nc * SSCATTER_MAX;
		nr = ((nr-1) * nr) / 2;

		size_t n_elements = nc * SSCATTER_MAX * (SSCATTER_MAX - 1) / 2 + nr;

		openfpm::vector<size_t> v1;
		v1.resize(n_elements);

		for(size_t i = 0 ; i < n_elements ; i++)
			v1.get(i) = 5;

		openfpm::vector<size_t> v2;

		openfpm::vector<size_t> prc;
		openfpm::vector<size_t> sz;

		// Scatter pattern
		for (size_t i = 0 ; i < vcl.getProcessingUnits() ; i++)
		{
			sz.add(i % SSCATTER_MAX);
			prc.add(i);
		}

		vcl.SScatter(v1,v2,prc,sz,(i%vcl.getProcessingUnits()));

		BOOST_REQUIRE_EQUAL(v2.size(),vcl.getProcessUnitID() % SSCATTER_MAX);

		bool is_five = true;
		for (size_t i = 0 ; i < v2.size() ; i++)
			is_five &= (v2.get(i) == 5);

		BOOST_REQUIRE_EQUAL(is_five,true);
	}
}


BOOST_AUTO_TEST_CASE (Vcluster_semantic_struct_scatter)
{
	for (size_t i = 0 ; i < 100 ; i++)
	{
150
		Vcluster & vcl = create_vcluster();
Pietro Incardona's avatar
Pietro Incardona committed
151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193

		if (vcl.getProcessingUnits() >= 32)
			return;

		size_t nc = vcl.getProcessingUnits() / SSCATTER_MAX;
		size_t nr = vcl.getProcessingUnits() - nc * SSCATTER_MAX;
		nr = ((nr-1) * nr) / 2;

		size_t n_elements = nc * SSCATTER_MAX * (SSCATTER_MAX - 1) / 2 + nr;

		openfpm::vector<size_t> v1;
		v1.resize(n_elements);

		for(size_t i = 0 ; i < n_elements ; i++)
			v1.get(i) = 5;

		openfpm::vector<size_t> v2;

		openfpm::vector<size_t> prc;
		openfpm::vector<size_t> sz;

		// Scatter pattern
		for (size_t i = 0 ; i < vcl.getProcessingUnits() ; i++)
		{
			sz.add(i % SSCATTER_MAX);
			prc.add(i);
		}

		vcl.SScatter(v1,v2,prc,sz,(i%vcl.getProcessingUnits()));

		if (vcl.getProcessUnitID() == (i%vcl.getProcessingUnits()))
		{
			BOOST_REQUIRE_EQUAL(v2.size(),vcl.getProcessUnitID() % SSCATTER_MAX);

			bool is_five = true;
			for (size_t i = 0 ; i < v2.size() ; i++)
				is_five &= (v2.get(i) == 5);

			BOOST_REQUIRE_EQUAL(is_five,true);
		}
	}
}

Pietro Incardona's avatar
Pietro Incardona committed
194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331
BOOST_AUTO_TEST_CASE (Vcluster_semantic_sendrecv)
{
	for (size_t i = 0 ; i < 100 ; i++)
	{
		Vcluster & vcl = create_vcluster();

		if (vcl.getProcessingUnits() >= 32)
			return;

		openfpm::vector<size_t> prc_recv2;
		openfpm::vector<size_t> prc_recv3;
		openfpm::vector<size_t> prc_send;
		openfpm::vector<size_t> sz_recv2;
		openfpm::vector<size_t> sz_recv3;
		openfpm::vector<openfpm::vector<size_t>> v1;
		openfpm::vector<size_t> v2;
		openfpm::vector<openfpm::vector<size_t>> v3;

		v1.resize(vcl.getProcessingUnits());

		size_t nc = vcl.getProcessingUnits() / SSCATTER_MAX;
		size_t nr = vcl.getProcessingUnits() - nc * SSCATTER_MAX;
		nr = ((nr-1) * nr) / 2;

		size_t n_ele = nc * SSCATTER_MAX * (SSCATTER_MAX - 1) / 2 + nr;

		for(size_t i = 0 ; i < v1.size() ; i++)
		{
			for (size_t j = 0 ; j < i % SSCATTER_MAX ; j++)
				v1.get(i).add(j);

			prc_send.add((i + vcl.getProcessUnitID()) % vcl.getProcessingUnits());
		}

		vcl.SSendRecv(v1,v2,prc_send,prc_recv2,sz_recv2);
		vcl.SSendRecv(v1,v3,prc_send,prc_recv3,sz_recv3);

		BOOST_REQUIRE_EQUAL(v2.size(),n_ele);
		BOOST_REQUIRE_EQUAL(v3.size(),vcl.getProcessingUnits()-1-nc);

		bool match = true;
		size_t s = 0;

		for (size_t i = 0 ; i < sz_recv2.size() ; i++)
		{
			for (size_t j = 0 ; j < sz_recv2.get(i) % SSCATTER_MAX ; j++)
			{
				match &= v2.get(s+j) == j;
			}
			s += sz_recv2.get(i) % SSCATTER_MAX;
		}

		BOOST_REQUIRE_EQUAL(match,true);

		for (size_t i = 0 ; i < sz_recv3.size() ; i++)
		{
			for (size_t j = 0 ; j < sz_recv3.get(i) % SSCATTER_MAX ; j++)
			{
				match &= v3.get(i).get(j) == j;
			}
		}

		BOOST_REQUIRE_EQUAL(match,true);
	}
}


BOOST_AUTO_TEST_CASE (Vcluster_semantic_struct_sendrecv)
{
	for (size_t i = 0 ; i < 100 ; i++)
	{
		Vcluster & vcl = create_vcluster();

		if (vcl.getProcessingUnits() >= 32)
			return;

		openfpm::vector<size_t> prc_recv2;
		openfpm::vector<size_t> prc_recv3;
		openfpm::vector<size_t> prc_send;
		openfpm::vector<size_t> sz_recv2;
		openfpm::vector<size_t> sz_recv3;
		openfpm::vector<openfpm::vector<Box<3,size_t>>> v1;
		openfpm::vector<Box<3,size_t>> v2;
		openfpm::vector<openfpm::vector<Box<3,size_t>>> v3;

		v1.resize(vcl.getProcessingUnits());

		size_t nc = vcl.getProcessingUnits() / SSCATTER_MAX;
		size_t nr = vcl.getProcessingUnits() - nc * SSCATTER_MAX;
		nr = ((nr-1) * nr) / 2;

		size_t n_ele = nc * SSCATTER_MAX * (SSCATTER_MAX - 1) / 2 + nr;

		for(size_t i = 0 ; i < v1.size() ; i++)
		{
			for (size_t j = 0 ; j < i % SSCATTER_MAX ; j++)
			{
				Box<3,size_t> b({j,j,j},{j,j,j});
				v1.get(i).add(b);
			}

			prc_send.add((i + vcl.getProcessUnitID()) % vcl.getProcessingUnits());
		}

		vcl.SSendRecv(v1,v2,prc_send,prc_recv2,sz_recv2);
		vcl.SSendRecv(v1,v3,prc_send,prc_recv3,sz_recv3);

		BOOST_REQUIRE_EQUAL(v2.size(),n_ele);
		BOOST_REQUIRE_EQUAL(v3.size(),vcl.getProcessingUnits()-1-nc);

		bool match = true;
		size_t s = 0;

		for (size_t i = 0 ; i < sz_recv2.size() ; i++)
		{
			for (size_t j = 0 ; j < sz_recv2.get(i) % SSCATTER_MAX ; j++)
			{
				Box<3,size_t> b({j,j,j},{j,j,j});
				Box<3,size_t> bt = v2.get(s+j);
				match &= bt == b;
			}
			s += sz_recv2.get(i) % SSCATTER_MAX;
		}

		BOOST_REQUIRE_EQUAL(match,true);

		for (size_t i = 0 ; i < sz_recv3.size() ; i++)
		{
			for (size_t j = 0 ; j < sz_recv3.get(i) % SSCATTER_MAX ; j++)
			{
				Box<3,size_t> b({j,j,j},{j,j,j});
				Box<3,size_t> bt = v3.get(i).get(j);
				match &= bt == b;
			}
		}

		BOOST_REQUIRE_EQUAL(match,true);
	}
Pietro Incardona's avatar
Pietro Incardona committed
332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357

	// Send and receive 0 and check

	{
		Vcluster & vcl = create_vcluster();

		openfpm::vector<size_t> prc_recv2;
		openfpm::vector<size_t> prc_send;
		openfpm::vector<size_t> sz_recv2;
		openfpm::vector<openfpm::vector<Box<3,size_t>>> v1;
		openfpm::vector<Box<3,size_t>> v2;

		v1.resize(vcl.getProcessingUnits());


		for(size_t i = 0 ; i < v1.size() ; i++)
		{
			prc_send.add((i + vcl.getProcessUnitID()) % vcl.getProcessingUnits());
		}

		vcl.SSendRecv(v1,v2,prc_send,prc_recv2,sz_recv2);

		BOOST_REQUIRE_EQUAL(v2.size(),0ul);
		BOOST_REQUIRE_EQUAL(prc_recv2.size(),0ul);
		BOOST_REQUIRE_EQUAL(sz_recv2.size(),0ul);
	}
Pietro Incardona's avatar
Pietro Incardona committed
358 359
}

Yaroslav's avatar
Yaroslav committed
360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400
BOOST_AUTO_TEST_CASE (Vcluster_semantic_gather_ptst)
{
	for (size_t i = 0 ; i < 100 ; i++)
	{
		Vcluster & vcl = create_vcluster();

		if (vcl.getProcessingUnits() >= 32)
			return;

		openfpm::vector<aggregate<openfpm::vector<int>>> v1;

		openfpm::vector<int> v1_int;

		v1_int.resize(10);

		for (size_t i = 0; i < v1_int.size(); i++)
			v1_int.get(i) = 5;

		v1.resize(vcl.getProcessUnitID());

		for(size_t i = 0 ; i < vcl.getProcessUnitID() ; i++)
			v1.template get<0>(i) = v1_int;

		openfpm::vector<aggregate<openfpm::vector<int>>> v2;
		/*
		vcl.SGather(v1,v2,(i%vcl.getProcessingUnits()));

		if (vcl.getProcessUnitID() == (i%vcl.getProcessingUnits()))
		{
			size_t n = vcl.getProcessingUnits();
			BOOST_REQUIRE_EQUAL(v2.size(),n*(n-1)/2);

			bool is_five = true;
			for (size_t i = 0 ; i < v2.size() ; i++)
				is_five &= (v2.get(i) == 5);

			BOOST_REQUIRE_EQUAL(is_five,true);
		}*/
	}
}

401 402 403
BOOST_AUTO_TEST_SUITE_END()

#endif /* OPENFPM_VCLUSTER_SRC_VCLUSTER_SEMANTIC_UNIT_TESTS_HPP_ */