vector_dist_dlb_test.hpp 7.62 KB
Newer Older
incardon's avatar
incardon committed
1 2 3 4 5 6 7 8 9 10 11 12
/*
 * vector_dist_dlb_test.hpp
 *
 *  Created on: Feb 21, 2017
 *      Author: i-bird
 */

#ifndef SRC_VECTOR_VECTOR_DIST_DLB_TEST_HPP_
#define SRC_VECTOR_VECTOR_DIST_DLB_TEST_HPP_

BOOST_AUTO_TEST_SUITE( vector_dist_dlb_test )

incardon's avatar
incardon committed
13
template<typename vector_type> void test_dlb_vector()
incardon's avatar
incardon committed
14 15 16 17 18 19 20 21 22 23
{
	Vcluster & v_cl = create_vcluster();

	if (v_cl.getProcessingUnits() > 8)
		return;

	Box<3,float> domain({0.0,0.0,0.0},{1.0,1.0,1.0});
	Ghost<3,float> g(0.1);
	size_t bc[3] = {PERIODIC,PERIODIC,PERIODIC};

incardon's avatar
incardon committed
24
	vector_type vd(0,domain,bc,g,DEC_GRAN(2048));
incardon's avatar
incardon committed
25 26 27 28 29

	// Only processor 0 initialy add particles on a corner of a domain

	if (v_cl.getProcessUnitID() == 0)
	{
30
		for(size_t i = 0 ; i < 50000 ; i++)
incardon's avatar
incardon committed
31 32 33 34 35 36 37 38 39 40
		{
			vd.add();

			vd.getLastPos()[0] = ((float)rand())/RAND_MAX * 0.3;
			vd.getLastPos()[1] = ((float)rand())/RAND_MAX * 0.3;
			vd.getLastPos()[2] = ((float)rand())/RAND_MAX * 0.3;
		}
	}

	vd.map();
incardon's avatar
incardon committed
41
	vd.template ghost_get<>();
incardon's avatar
incardon committed
42 43

	ModelSquare md;
incardon's avatar
incardon committed
44
	md.factor = 10;
incardon's avatar
incardon committed
45 46 47 48
	vd.addComputationCosts(md);
	vd.getDecomposition().decompose();
	vd.map();

incardon's avatar
incardon committed
49

incardon's avatar
incardon committed
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93
	vd.addComputationCosts(md);

	openfpm::vector<size_t> loads;
	size_t load = vd.getDecomposition().getDistribution().getProcessorLoad();
	v_cl.allGather(load,loads);
	v_cl.execute();

	for (size_t i = 0 ; i < loads.size() ; i++)
	{
		float load_f = load;
		float load_fc = loads.get(i);

		BOOST_REQUIRE_CLOSE(load_f,load_fc,7.0);
	}

	BOOST_REQUIRE(vd.size_local() != 0);

	Point<3,float> v({1.0,1.0,1.0});

	for (size_t i = 0 ; i < 25 ; i++)
	{
		// move the particles by 0.1

		auto it = vd.getDomainIterator();

		while (it.isNext())
		{
			auto p = it.get();

			vd.getPos(p)[0] += v.get(0) * 0.09;
			vd.getPos(p)[1] += v.get(1) * 0.09;
			vd.getPos(p)[2] += v.get(2) * 0.09;

			++it;
		}
		vd.map();

		ModelSquare md;
		vd.addComputationCosts(md);
		vd.getDecomposition().redecompose(200);
		vd.map();

		BOOST_REQUIRE(vd.size_local() != 0);

incardon's avatar
incardon committed
94
		vd.template ghost_get<>();
incardon's avatar
incardon committed
95 96 97 98 99 100 101 102 103 104 105 106 107

		vd.addComputationCosts(md);

		openfpm::vector<size_t> loads;
		size_t load = vd.getDecomposition().getDistribution().getProcessorLoad();
		v_cl.allGather(load,loads);
		v_cl.execute();

		for (size_t i = 0 ; i < loads.size() ; i++)
		{
			float load_f = load;
			float load_fc = loads.get(i);

108
			BOOST_REQUIRE_CLOSE(load_f,load_fc,10.0);
incardon's avatar
incardon committed
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 150 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 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

template<typename vector_type> void test_dlb_multi_phase_vector()
{
	Vcluster & v_cl = create_vcluster();

	if (v_cl.getProcessingUnits() > 8)
		return;

	Box<3,float> domain({0.0,0.0,0.0},{1.0,1.0,1.0});
	Ghost<3,float> g(0.1);
	size_t bc[3] = {PERIODIC,PERIODIC,PERIODIC};

	vector_type vd0(0,domain,bc,g,DEC_GRAN(2048));
	vector_type vd1(0,domain,bc,g,DEC_GRAN(2048));
	vector_type vd2(0,domain,bc,g,DEC_GRAN(2048));
	vector_type vd3(0,domain,bc,g,DEC_GRAN(2048));

	// Only processor 0 initialy add particles on a corner of a domain

	if (v_cl.getProcessUnitID() == 0)
	{
		for(size_t i = 0 ; i < 50000 ; i++)
		{
			vd0.add();
			vd1.add();
			vd2.add();
			vd3.add();

			vd0.getLastPos()[0] = ((float)rand())/RAND_MAX * 0.3;
			vd0.getLastPos()[1] = ((float)rand())/RAND_MAX * 0.3;
			vd0.getLastPos()[2] = ((float)rand())/RAND_MAX * 0.3;

			vd1.getLastPos()[0] = ((float)rand())/RAND_MAX * 0.3 + 0.1;
			vd1.getLastPos()[1] = ((float)rand())/RAND_MAX * 0.3 + 0.1;
			vd1.getLastPos()[2] = ((float)rand())/RAND_MAX * 0.3 + 0.1;

			vd2.getLastPos()[0] = ((float)rand())/RAND_MAX * 0.3 + 0.2;
			vd2.getLastPos()[1] = ((float)rand())/RAND_MAX * 0.3 + 0.2;
			vd2.getLastPos()[2] = ((float)rand())/RAND_MAX * 0.3 + 0.2;

			vd3.getLastPos()[0] = ((float)rand())/RAND_MAX * 0.3 + 0.3;
			vd3.getLastPos()[1] = ((float)rand())/RAND_MAX * 0.3 + 0.3;
			vd3.getLastPos()[2] = ((float)rand())/RAND_MAX * 0.3 + 0.3;
		}
	}

	vd0.map();
	vd0.template ghost_get<>();
	vd1.map();
	vd1.template ghost_get<>();
	vd2.map();
	vd2.template ghost_get<>();
	vd3.map();
	vd3.template ghost_get<>();

	ModelSquare md;
	md.factor = 1;
	vd0.initializeComputationCosts();
	vd0.addComputationCosts(vd0,md);
	vd0.addComputationCosts(vd1,md);
	vd0.addComputationCosts(vd2,md);
	vd0.addComputationCosts(vd3,md);
	vd0.finalizeComputationCosts();

	vd0.getDecomposition().decompose();

	// Copy the decomposition back to the other
	vd1.getDecomposition() = vd0.getDecomposition();
	vd2.getDecomposition() = vd0.getDecomposition();
	vd3.getDecomposition() = vd0.getDecomposition();

	vd0.map();
	vd1.map();
	vd2.map();
	vd3.map();

	vd0.initializeComputationCosts();
	vd0.addComputationCosts(vd0,md);
	vd0.addComputationCosts(vd1,md);
	vd0.addComputationCosts(vd2,md);
	vd0.addComputationCosts(vd3,md);
	vd0.finalizeComputationCosts();

	openfpm::vector<size_t> loads;
	size_t load = vd0.getDecomposition().getDistribution().getProcessorLoad();
	v_cl.allGather(load,loads);
	v_cl.execute();

	for (size_t i = 0 ; i < loads.size() ; i++)
	{
		float load_f = load;
		float load_fc = loads.get(i);

		BOOST_REQUIRE_CLOSE(load_f,load_fc,7.0);
	}

	Point<3,float> v({1.0,1.0,1.0});

	for (size_t i = 0 ; i < 25 ; i++)
	{
		// move the particles by 0.1

		{
		auto it = vd0.getDomainIterator();

		while (it.isNext())
		{
			auto p = it.get();

			vd0.getPos(p)[0] += v.get(0) * 0.09;
			vd0.getPos(p)[1] += v.get(1) * 0.09;
			vd0.getPos(p)[2] += v.get(2) * 0.09;

			++it;
		}
		}

		{
		auto it = vd1.getDomainIterator();
		while (it.isNext())
		{
			auto p = it.get();

			vd1.getPos(p)[0] += v.get(0) * 0.06;
			vd1.getPos(p)[1] += v.get(1) * 0.06;
			vd1.getPos(p)[2] += v.get(2) * 0.06;

			++it;
		}
		}

		{
		auto it = vd2.getDomainIterator();
		while (it.isNext())
		{
			auto p = it.get();

			vd2.getPos(p)[0] += v.get(0) * 0.06;
			vd2.getPos(p)[1] += v.get(1) * 0.06;
			vd2.getPos(p)[2] += v.get(2) * 0.06;

			++it;
		}
		}

		{
		auto it = vd3.getDomainIterator();
		while (it.isNext())
		{
			auto p = it.get();

			vd3.getPos(p)[0] += v.get(0) * 0.06;
			vd3.getPos(p)[1] += v.get(1) * 0.06;
			vd3.getPos(p)[2] += v.get(2) * 0.06;

			++it;
		}
		}

		vd0.map();
		vd1.map();
		vd2.map();
		vd3.map();

		ModelSquare md;
		vd0.initializeComputationCosts();
		vd0.addComputationCosts(vd0,md);
		vd0.addComputationCosts(vd1,md);
		vd0.addComputationCosts(vd2,md);
		vd0.addComputationCosts(vd3,md);
		vd0.finalizeComputationCosts();

		vd0.getDecomposition().redecompose(200);

		// Copy the decomposition back to the other
		vd1.getDecomposition() = vd0.getDecomposition();
		vd2.getDecomposition() = vd0.getDecomposition();
		vd3.getDecomposition() = vd0.getDecomposition();
		vd0.map();
		vd1.map();
		vd2.map();
		vd3.map();

		vd0.template ghost_get<>();
		vd1.template ghost_get<>();
		vd2.template ghost_get<>();
		vd3.template ghost_get<>();

		vd0.initializeComputationCosts();
		vd0.addComputationCosts(vd0,md);
		vd0.addComputationCosts(vd1,md);
		vd0.addComputationCosts(vd2,md);
		vd0.addComputationCosts(vd3,md);
		vd0.finalizeComputationCosts();

		openfpm::vector<size_t> loads;
		size_t load = vd0.getDecomposition().getDistribution().getProcessorLoad();
		v_cl.allGather(load,loads);
		v_cl.execute();

		for (size_t i = 0 ; i < loads.size() ; i++)
		{
			float load_f = load;
			float load_fc = loads.get(i);

			BOOST_REQUIRE_CLOSE(load_f,load_fc,10.0);
		}
	}
}

incardon's avatar
incardon committed
323 324 325 326 327
BOOST_AUTO_TEST_CASE( vector_dist_dlb_test_part )
{
	test_dlb_vector<vector_dist<3,float,aggregate<float>>>();
}

328 329 330 331 332
BOOST_AUTO_TEST_CASE( vector_dist_dlb_multi_phase_test_part )
{
	test_dlb_multi_phase_vector<vector_dist<3,float,aggregate<float>>>();
}

incardon's avatar
incardon committed
333 334
BOOST_AUTO_TEST_CASE( vector_dist_dlb_metis_test_part )
{
incardon's avatar
incardon committed
335 336 337 338 339 340
	test_dlb_vector<vector_dist<3,
	                            float,
								aggregate<float>,
								memory_traits_lin<aggregate<float>>::type,
								memory_traits_lin,
	                            CartDecomposition<3,float,HeapMemory,MetisDistribution<3,float>>>>();
incardon's avatar
incardon committed
341 342
}

incardon's avatar
incardon committed
343 344 345
BOOST_AUTO_TEST_SUITE_END()

#endif /* SRC_VECTOR_VECTOR_DIST_DLB_TEST_HPP_ */