8#ifndef SRC_DECOMPOSITION_DISTRIBUTION_DISTRIBUTION_UNIT_TESTS_HPP_
9#define SRC_DECOMPOSITION_DISTRIBUTION_DISTRIBUTION_UNIT_TESTS_HPP_
12#include "SpaceDistribution.hpp"
14#include "BoxDistribution.hpp"
26template<
unsigned int dim,
typename Distribution>
void setSphereComputationCosts(Distribution & dist,
grid_sm<dim, void> & gr,
Point<3, float> center,
float radius,
size_t max_l,
size_t min_l)
28 float radius2 = radius * radius;
34 for (
size_t i = 0; i < dist.getNSubSubDomains(); i++)
36 dist.getSubSubDomainPosition(i, pos);
39 for (
size_t j = 0; j < dim; j++)
40 eq += (pos[j] - center.
get(j)) * (pos[j] - center.
get(j));
44 dist.setComputationCost(i, max_l);
45 dist.setMigrationCost(i, max_l * 2);
49 dist.setComputationCost(i, min_l);
50 dist.setMigrationCost(i, min_l * 2);
54 for (
size_t j = 0; j < dist.getNSubSubDomainNeighbors(i); j++)
55 dist.setCommunicationCost(i, j, 1);
59BOOST_AUTO_TEST_SUITE (Distribution_test)
61BOOST_AUTO_TEST_CASE( Metis_distribution_test)
73 size_t sz[3] = { GS_SIZE, GS_SIZE, GS_SIZE };
86 met_dist.createCartGraph(info,box);
89 BOOST_REQUIRE_EQUAL(met_dist.get_ndec(),1ul);
93 BOOST_REQUIRE(met_dist.getUnbalance() < 0.03);
96 {met_dist.write(
"vtk_metis_distribution");}
98 size_t b = GS_SIZE * GS_SIZE * GS_SIZE / 5;
107 for (
size_t k = 0; k < met_dist.getNOwnerSubSubDomains(); k++)
109 size_t i = met_dist.getOwnerSubSubDomain(k);
111 if (i == 0 || i == b || i == 2*b || i == 3*b || i == 4*b)
112 met_dist.setComputationCost(i,10);
114 met_dist.setComputationCost(i,1);
117 for (
size_t i = 0 ; i < met_dist.getNSubSubDomains() ; i++)
121 met_dist.setMigrationCost(i,1);
123 for (
size_t j = 0; j < met_dist.getNSubSubDomainNeighbors(i); j++)
124 met_dist.setCommunicationCost(i,j,1);
127 met_dist.decompose();
129 BOOST_REQUIRE_EQUAL(met_dist.get_ndec(),2ul);
133 BOOST_REQUIRE(met_dist.getUnbalance() < 0.06);
136 {met_dist.write(
"vtk_metis_distribution_red");}
147 test = compare(
"0_vtk_metis_distribution.vtk",
"src/Decomposition/Distribution/test_data/vtk_metis_distribution_osx_test.vtk");
148 BOOST_REQUIRE_EQUAL(
true,test);
149 test = compare(
"0_vtk_metis_distribution_red.vtk",
"src/Decomposition/Distribution/test_data/vtk_metis_distribution_red_osx_test.vtk");
150 BOOST_REQUIRE_EQUAL(
true,test);
153 #elif __GNUC__ == 6 && __GNUC_MINOR__ == 3
155 test = compare(
"0_vtk_metis_distribution.vtk",
"src/Decomposition/Distribution/test_data/vtk_metis_distribution_test.vtk");
156 BOOST_REQUIRE_EQUAL(
true,test);
157 test = compare(
"0_vtk_metis_distribution_red.vtk",
"src/Decomposition/Distribution/test_data/vtk_metis_distribution_red_test.vtk");
158 BOOST_REQUIRE_EQUAL(
true,test);
167 met_dist2 = met_dist;
169 test = (met_dist2 == met_dist);
171 BOOST_REQUIRE_EQUAL(test,
true);
184BOOST_AUTO_TEST_CASE( Parmetis_distribution_test)
202 pmet_dist.createCartGraph(info,box);
209 setSphereComputationCosts(pmet_dist, info, center, 2.0f, 5ul, 1ul);
212 pmet_dist.decompose();
214 BOOST_REQUIRE_EQUAL(pmet_dist.get_ndec(),1ul);
221 pmet_dist.write(
"vtk_parmetis_distribution_0");
226 bool test = compare(std::to_string(v_cl.
getProcessUnitID()) +
"_vtk_parmetis_distribution_0.vtk",
"src/Decomposition/Distribution/test_data/" + std::to_string(v_cl.
getProcessUnitID()) +
"_vtk_parmetis_distribution_0_osx_test.vtk");
227 BOOST_REQUIRE_EQUAL(
true,test);
232 bool test = compare(std::to_string(v_cl.
getProcessUnitID()) +
"_vtk_parmetis_distribution_0.vtk",
"src/Decomposition/Distribution/test_data/" + std::to_string(v_cl.
getProcessUnitID()) +
"_vtk_parmetis_distribution_0_test.vtk");
233 BOOST_REQUIRE_EQUAL(
true,test);
240 float stime = 0.0, etime = 10.0, tstep = 0.1;
248 for(
float t = stime; t < etime; t = t + tstep, iter++)
255 setSphereComputationCosts(pmet_dist, info, center, 2.0f, 5, 1);
258 if ((
size_t)iter % 10 == 0)
262 BOOST_REQUIRE_EQUAL(pmet_dist.get_ndec(),n_dec);
266 std::stringstream str;
267 str <<
"vtk_parmetis_distribution_" << iter;
268 pmet_dist.write(str.str());
274 bool test = compare(std::to_string(v_cl.
getProcessUnitID()) +
"_" + str.str() +
".vtk",
"src/Decomposition/Distribution/test_data/" + std::to_string(v_cl.
getProcessUnitID()) +
"_" + str.str() +
"_osx_test.vtk");
275 BOOST_REQUIRE_EQUAL(
true,test);
281 bool test = compare(std::to_string(v_cl.
getProcessUnitID()) +
"_" + str.str() +
".vtk",
"src/Decomposition/Distribution/test_data/" + std::to_string(v_cl.
getProcessUnitID()) +
"_" + str.str() +
"_test.vtk");
282 BOOST_REQUIRE_EQUAL(
true,test);
294BOOST_AUTO_TEST_CASE( DistParmetis_distribution_test)
312 pmet_dist.createCartGraph(info,box);
319 setSphereComputationCosts(pmet_dist, info, center, 2.0f, 5ul, 1ul);
322 pmet_dist.decompose();
327 pmet_dist.write(
"vtk_dist_parmetis_distribution_0");
336 bool test = compare(
"vtk_dist_parmetis_distribution_0.vtk",
"src/Decomposition/Distribution/test_data/vtk_dist_parmetis_distribution_0_osx_test.vtk");
337 BOOST_REQUIRE_EQUAL(
true,test);
342 bool test = compare(
"vtk_dist_parmetis_distribution_0.vtk",
"src/Decomposition/Distribution/test_data/vtk_dist_parmetis_distribution_0_test.vtk");
343 BOOST_REQUIRE_EQUAL(
true,test);
351 float stime = 0.0, etime = 10.0, tstep = 0.1;
358 for(
float t = stime; t < etime; t = t + tstep, iter++)
365 setSphereComputationCosts(pmet_dist, info, center, 2.0f, 5, 1);
368 if ((
size_t)iter % 10 == 0)
372 std::stringstream str;
373 str <<
"vtk_dist_parmetis_distribution_" << iter;
374 pmet_dist.write(str.str());
382 bool test = compare(str.str() +
".vtk",std::string(
"src/Decomposition/Distribution/test_data/") + str.str() +
"_osx_test.vtk");
383 BOOST_REQUIRE_EQUAL(
true,test);
388 bool test = compare(str.str() +
".vtk",std::string(
"src/Decomposition/Distribution/test_data/") + str.str() +
"_test.vtk");
389 BOOST_REQUIRE_EQUAL(
true,test);
400BOOST_AUTO_TEST_CASE( Space_distribution_test)
418 space_dist.createCartGraph(info,box);
421 space_dist.decompose();
428 space_dist.write(
"vtk_dist_space_distribution_0");
430 bool test = compare(std::to_string(v_cl.
getProcessUnitID()) +
"_vtk_dist_space_distribution_0.vtk",
"src/Decomposition/Distribution/test_data/" + std::to_string(v_cl.
getProcessUnitID()) + +
"_vtk_dist_space_distribution_0_test.vtk");
431 BOOST_REQUIRE_EQUAL(
true,test);
438BOOST_AUTO_TEST_CASE( Box_distribution_test)
442 if (v_cl.
size() > 16)
456 box_dist.createCartGraph(info,box);
462 box_dist.decompose();
464 BOOST_REQUIRE_EQUAL(box_dist.get_ndec(),0ul);
466 auto & graph = box_dist.getGraph();
468 for (
int i = 0 ; i < graph.getNVertex() ; i++)
470 BOOST_REQUIRE(graph.vertex(i).template get<nm_v_proc_id>() < v_cl.
size());
473 size_t n_sub = box_dist.getNOwnerSubSubDomains();
475 size_t n_sub_tot = info.size();
476 size_t n_sub_bal = n_sub_tot / v_cl.
size();
478 BOOST_REQUIRE( (((
int)n_sub_bal - 64) <= (
long int)n_sub) && (n_sub_bal + 64 >= n_sub) );
485BOOST_AUTO_TEST_SUITE_END()
Class that distribute sub-sub-domains across processors using Metis Library.
This class represent an N-dimensional box.
Class that distribute sub-sub-domains across processors using Metis Library.
Class that distribute sub-sub-domains across processors using ParMetis Library.
This class implement the point shape in an N-dimensional space.
__device__ __host__ const T & get(unsigned int i) const
Get coordinate.
Class that distribute sub-sub-domains across processors using an hilbert curve to divide the space.
size_t size()
Get the total number of processors.
size_t getProcessUnitID()
Get the process unit id.
size_t getProcessingUnits()
Get the total number of processors.
Implementation of VCluster class.