From eb37bc20670692b20e62a136c20d6e3920bfeb8e Mon Sep 17 00:00:00 2001 From: Pietro Incardona <incardon@mpi-cbg.de> Date: Wed, 12 Aug 2015 19:51:50 +0200 Subject: [PATCH] Speed-up test --- src/Grid/grid_dist_id_unit_test.hpp | 407 ++++++++++++++++++++++------ src/gargabe.hpp | 86 ++++++ 2 files changed, 407 insertions(+), 86 deletions(-) diff --git a/src/Grid/grid_dist_id_unit_test.hpp b/src/Grid/grid_dist_id_unit_test.hpp index a795034c..4e46710f 100644 --- a/src/Grid/grid_dist_id_unit_test.hpp +++ b/src/Grid/grid_dist_id_unit_test.hpp @@ -6,26 +6,10 @@ BOOST_AUTO_TEST_SUITE( grid_dist_id_test ) -template<typename iterator> void jacobi_iteration(iterator g_it, grid_dist_id<2, float, scalar<float>, CartDecomposition<2,float>> & g_dist) +void print_test(std::string test, size_t sz) { - // scalar - typedef scalar<float> S; - - // iterator - - while(g_it.isNext()) - { - // Jacobi update - - auto pos = g_it.get(); - - g_dist.template get<S::ele>(pos) = (g_dist.template get<S::ele>(pos.move(0,1)) + - g_dist.template get<S::ele>(pos.move(0,-1)) + - g_dist.template get<S::ele>(pos.move(1,1)) + - g_dist.template get<S::ele>(pos.move(1,-1)) / 4.0); - - ++g_it; - } + if (global_v_cluster->getProcessUnitID() == 0) + std::cout << test << " " << sz << "\n"; } BOOST_AUTO_TEST_CASE( grid_dist_id_domain_grid_unit_converter_test) @@ -100,11 +84,7 @@ void Test2D(const Box<2,float> & domain, long int k) for ( ; k >= 2 ; k-= (k > 2*big_step)?big_step:small_step ) { BOOST_TEST_CHECKPOINT( "Testing 2D grid k=" << k ); - - if (global_v_cluster->getProcessUnitID() == 0) - { - std::cout << "Testing 2D: "<< k << "\n"; - } + print_test( "Testing 2D grid k=",k); // grid size size_t sz[2]; @@ -156,17 +136,21 @@ void Test2D(const Box<2,float> & domain, long int k) auto dom2 = g_dist.getDomainIterator(); + bool match = true; + // check that the grid store the correct information while (dom2.isNext()) { auto key = dom2.get(); auto key_g = g_dist.getGKey(key); - BOOST_REQUIRE_EQUAL(g_dist.template get<0>(key),info.LinId(key_g)); + match &= (g_dist.template get<0>(key) == info.LinId(key_g))?true:false; ++dom2; } + BOOST_REQUIRE_EQUAL(match,true); + g_dist.template ghost_get<0>(); // check that the communication is correctly completed @@ -182,13 +166,7 @@ void Test2D(const Box<2,float> & domain, long int k) // In this case the boundary condition are non periodic if (g_dist.isInside(key_g)) { - if (g_dist.template get<0>(key) != info.LinId(key_g)) - { - int debug = 0; - debug++; - } - - BOOST_REQUIRE_EQUAL(g_dist.template get<0>(key),info.LinId(key_g)); + match &= (g_dist.template get<0>(key),info.LinId(key_g)); } ++domg; @@ -206,10 +184,7 @@ void Test3D(const Box<3,float> & domain, long int k) for ( ; k >= 2 ; k-= (k > 2*big_step)?big_step:small_step ) { BOOST_TEST_CHECKPOINT( "Testing 3D grid k=" << k ); - if (global_v_cluster->getProcessUnitID() == 0) - { - std::cout << "Testing 3D: "<< k << "\n"; - } + print_test( "Testing 3D grid k=",k); // grid size size_t sz[3]; @@ -261,6 +236,8 @@ void Test3D(const Box<3,float> & domain, long int k) // Check BOOST_REQUIRE_EQUAL(count,k*k*k); + bool match = true; + auto dom2 = g_dist.getDomainIterator(); // check that the grid store the correct information @@ -269,11 +246,13 @@ void Test3D(const Box<3,float> & domain, long int k) auto key = dom2.get(); auto key_g = g_dist.getGKey(key); - BOOST_REQUIRE_EQUAL(g_dist.template get<0>(key),info.LinId(key_g)); + match &= (g_dist.template get<0>(key) == info.LinId(key_g))?true:false; ++dom2; } + BOOST_REQUIRE_EQUAL(match,true); + g_dist.template ghost_get<0>(); // check that the communication is correctly completed @@ -289,94 +268,350 @@ void Test3D(const Box<3,float> & domain, long int k) // In this case the boundary condition are non periodic if (g_dist.isInside(key_g)) { - BOOST_REQUIRE_EQUAL(g_dist.template get<0>(key),info.LinId(key_g)); + match &= (g_dist.template get<0>(key) == info.LinId(key_g))?true:false; } ++domg; } + + BOOST_REQUIRE_EQUAL(match,true); } } -BOOST_AUTO_TEST_CASE( grid_dist_id_iterator_test_use) +void Test2D_complex(const Box<2,float> & domain, long int k) { - // Domain - Box<2,float> domain({0.0,0.0},{1.0,1.0}); + typedef Point_test<float> p; - // Initialize the global VCluster - init_global_v_cluster(&boost::unit_test::framework::master_test_suite().argc,&boost::unit_test::framework::master_test_suite().argv); + long int big_step = k / 30; + big_step = (big_step == 0)?1:big_step; + long int small_step = 1; - long int k = 1024*1024*global_v_cluster->getProcessingUnits(); - k = std::pow(k, 1/2.); + // 2D test + for ( ; k >= 2 ; k-= (k > 2*big_step)?big_step:small_step ) + { + BOOST_TEST_CHECKPOINT( "Testing 2D complex grid k=" << k ); + print_test( "Testing 2D complex grid k=",k); - Test2D(domain,k); - // Domain - Box<3,float> domain3({0.0,0.0,0.0},{1.0,1.0,1.0}); + // grid size + size_t sz[2]; + sz[0] = k; + sz[1] = k; - k = 128*128*128*global_v_cluster->getProcessingUnits(); - k = std::pow(k, 1/3.); - Test3D(domain3,k); + float factor = pow(global_v_cluster->getProcessingUnits()/2.0f,1.0f/2.0f); - // 3D test + // Ghost + Ghost<2,float> g(0.01 / factor); -// g_dist.write(""); + // Distributed grid with id decomposition + grid_dist_id<2, float, Point_test<float>, CartDecomposition<2,float>> g_dist(sz,domain,g); -/* auto g_it = g_dist.getIteratorBulk(); + // check the consistency of the decomposition + bool val = g_dist.getDecomposition().check_consistency(); + BOOST_REQUIRE_EQUAL(val,true); - auto g_it_halo = g_dist.getHalo(); + // Grid sm + grid_sm<2,void> info(sz); - // Let try to solve the poisson equation d2(u) = f with f = 1 and computation - // comunication overlap (100 Jacobi iteration) + // get the domain iterator + size_t count = 0; - for (int i = 0 ; i < 100 ; i++) - { - g_dist.ghost_get(); + auto dom = g_dist.getDomainIterator(); + + while (dom.isNext()) + { + auto key = dom.get(); + auto key_g = g_dist.getGKey(key); + + size_t k = info.LinId(key_g); + + g_dist.template get<p::x>(key) = 1 + k; + g_dist.template get<p::y>(key) = 567 + k; + g_dist.template get<p::z>(key) = 341 + k; + g_dist.template get<p::s>(key) = 5670 + k; + g_dist.template get<p::v>(key)[0] = 921 + k; + g_dist.template get<p::v>(key)[1] = 5675 + k; + g_dist.template get<p::v>(key)[2] = 117 + k; + g_dist.template get<p::t>(key)[0][0] = 1921 + k; + g_dist.template get<p::t>(key)[0][1] = 25675 + k; + g_dist.template get<p::t>(key)[0][2] = 3117 + k; + g_dist.template get<p::t>(key)[1][0] = 4921 + k; + g_dist.template get<p::t>(key)[1][1] = 55675 + k; + g_dist.template get<p::t>(key)[1][2] = 6117 + k; + g_dist.template get<p::t>(key)[2][0] = 7921 + k; + g_dist.template get<p::t>(key)[2][1] = 85675 + k; + g_dist.template get<p::t>(key)[2][2] = 9117 + k; + + // Count the point + count++; + + ++dom; + } - // Compute the bulk + // Get the virtual cluster machine + Vcluster & vcl = g_dist.getVC(); - jacobi_iteration(g_it); + // reduce + vcl.reduce(count); + vcl.execute(); - g_dist.ghost_sync(); + // Check + BOOST_REQUIRE_EQUAL(count,k*k); + + auto dom2 = g_dist.getDomainIterator(); - // Compute the halo + bool match = true; - jacobi_iteration(g_it_halo); - }*/ + // check that the grid store the correct information + while (dom2.isNext()) + { + auto key = dom2.get(); + auto key_g = g_dist.getGKey(key); + + size_t k = info.LinId(key_g); + + match &= (g_dist.template get<p::x>(key) == 1 + k)?true:false; + match &= (g_dist.template get<p::y>(key) == 567 + k)?true:false; + match &= (g_dist.template get<p::z>(key) == 341 + k)?true:false; + match &= (g_dist.template get<p::s>(key) == 5670 + k)?true:false; + match &= (g_dist.template get<p::v>(key)[0] == 921 + k)?true:false; + match &= (g_dist.template get<p::v>(key)[1] == 5675 + k)?true:false; + match &= (g_dist.template get<p::v>(key)[2] == 117 + k)?true:false; + match &= (g_dist.template get<p::t>(key)[0][0] == 1921 + k)?true:false; + match &= (g_dist.template get<p::t>(key)[0][1] == 25675 + k)?true:false; + match &= (g_dist.template get<p::t>(key)[0][2] == 3117 + k)?true:false; + match &= (g_dist.template get<p::t>(key)[1][0] == 4921 + k)?true:false; + match &= (g_dist.template get<p::t>(key)[1][1] == 55675 + k)?true:false; + match &= (g_dist.template get<p::t>(key)[1][2] == 6117 + k)?true:false; + match &= (g_dist.template get<p::t>(key)[2][0] == 7921 + k)?true:false; + match &= (g_dist.template get<p::t>(key)[2][1] == 85675 + k)?true:false; + match &= (g_dist.template get<p::t>(key)[2][2] == 9117 + k)?true:false; + + ++dom2; + } + + BOOST_REQUIRE_EQUAL(match,true); + + g_dist.template ghost_get<p::x,p::y,p::z,p::s,p::v,p::t>(); + + // check that the communication is correctly completed + + auto domg = g_dist.getDomainGhostIterator(); + + // check that the grid with the ghost past store the correct information + while (domg.isNext()) + { + auto key = domg.get(); + auto key_g = g_dist.getGKey(key); + + // In this case the boundary condition are non periodic + if (g_dist.isInside(key_g)) + { + size_t k = info.LinId(key_g); + + match &= (g_dist.template get<p::x>(key) == 1 + k)?true:false; + match &= (g_dist.template get<p::y>(key) == 567 + k)?true:false; + match &= (g_dist.template get<p::z>(key) == 341 + k)?true:false; + match &= (g_dist.template get<p::s>(key) == 5670 + k)?true:false; + + match &= (g_dist.template get<p::v>(key)[0] == 921 + k)?true:false; + match &= (g_dist.template get<p::v>(key)[1] == 5675 + k)?true:false; + match &= (g_dist.template get<p::v>(key)[2] == 117 + k)?true:false; + + match &= (g_dist.template get<p::t>(key)[0][0] == 1921 + k)?true:false; + match &= (g_dist.template get<p::t>(key)[0][1] == 25675 + k)?true:false; + match &= (g_dist.template get<p::t>(key)[0][2] == 3117 + k)?true:false; + match &= (g_dist.template get<p::t>(key)[1][0] == 4921 + k)?true:false; + match &= (g_dist.template get<p::t>(key)[1][1] == 55675 + k)?true:false; + match &= (g_dist.template get<p::t>(key)[1][2] == 6117 + k)?true:false; + match &= (g_dist.template get<p::t>(key)[2][0] == 7921 + k)?true:false; + match &= (g_dist.template get<p::t>(key)[2][1] == 85675 + k)?true:false; + match &= (g_dist.template get<p::t>(key)[2][2] == 9117 + k)?true:false; + } + + ++domg; + } + } } -BOOST_AUTO_TEST_CASE( grid_dist_id_poisson_test_use) +void Test3D_complex(const Box<3,float> & domain, long int k) { - // grid size -/* size_t sz[2] = {1024,1024}; + typedef Point_test<float> p; - // Distributed grid with id decomposition + long int big_step = k / 30; + big_step = (big_step == 0)?1:big_step; + long int small_step = 1; - grid_dist_id<2, scalar<float>, CartDecomposition<2,size_t>> g_dist(sz); + // 2D test + for ( ; k >= 2 ; k-= (k > 2*big_step)?big_step:small_step ) + { + BOOST_TEST_CHECKPOINT( "Testing 3D complex grid k=" << k ); + print_test( "Testing 3D grid complex k=",k); + + // grid size + size_t sz[3]; + sz[0] = k; + sz[1] = k; + sz[2] = k; - // Create the grid on memory + // factor + float factor = pow(global_v_cluster->getProcessingUnits()/2.0f,1.0f/3.0f); - g_dist.Create();*/ + // Ghost + Ghost<3,float> g(0.01 / factor); -/* auto g_it = g_dist.getIteratorBulk(); + // Distributed grid with id decomposition + grid_dist_id<3, float, Point_test<float>, CartDecomposition<3,float>> g_dist(sz,domain,g); - auto g_it_halo = g_dist.getHalo(); + // check the consistency of the decomposition + bool val = g_dist.getDecomposition().check_consistency(); + BOOST_REQUIRE_EQUAL(val,true); - // Let try to solve the poisson equation d2(u) = f with f = 1 and computation - // comunication overlap (100 Jacobi iteration) + // Grid sm + grid_sm<3,void> info(sz); - for (int i = 0 ; i < 100 ; i++) - { - g_dist.ghost_get(); + // get the domain iterator + size_t count = 0; + + auto dom = g_dist.getDomainIterator(); + + while (dom.isNext()) + { + auto key = dom.get(); + auto key_g = g_dist.getGKey(key); + + size_t k = info.LinId(key_g); + + g_dist.template get<p::x>(key) = 1 + k; + g_dist.template get<p::y>(key) = 567 + k; + g_dist.template get<p::z>(key) = 341 + k; + g_dist.template get<p::s>(key) = 5670 + k; + g_dist.template get<p::v>(key)[0] = 921 + k; + g_dist.template get<p::v>(key)[1] = 5675 + k; + g_dist.template get<p::v>(key)[2] = 117 + k; + g_dist.template get<p::t>(key)[0][0] = 1921 + k; + g_dist.template get<p::t>(key)[0][1] = 25675 + k; + g_dist.template get<p::t>(key)[0][2] = 3117 + k; + g_dist.template get<p::t>(key)[1][0] = 4921 + k; + g_dist.template get<p::t>(key)[1][1] = 55675 + k; + g_dist.template get<p::t>(key)[1][2] = 6117 + k; + g_dist.template get<p::t>(key)[2][0] = 7921 + k; + g_dist.template get<p::t>(key)[2][1] = 85675 + k; + g_dist.template get<p::t>(key)[2][2] = 9117 + k; + + // Count the point + count++; + + ++dom; + } + + // Get the virtual cluster machine + Vcluster & vcl = g_dist.getVC(); + + // reduce + vcl.reduce(count); + vcl.execute(); + + // Check + BOOST_REQUIRE_EQUAL(count,k*k*k); - // Compute the bulk + bool match = true; - jacobi_iteration(g_it); + auto dom2 = g_dist.getDomainIterator(); + + // check that the grid store the correct information + while (dom2.isNext()) + { + auto key = dom2.get(); + auto key_g = g_dist.getGKey(key); + + size_t k = info.LinId(key_g); + + match &= (g_dist.template get<p::x>(key) == 1 + k)?true:false; + match &= (g_dist.template get<p::y>(key) == 567 + k)?true:false; + match &= (g_dist.template get<p::z>(key) == 341 + k)?true:false; + match &= (g_dist.template get<p::s>(key) == 5670 + k)?true:false; + match &= (g_dist.template get<p::v>(key)[0] == 921 + k)?true:false; + match &= (g_dist.template get<p::v>(key)[1] == 5675 + k)?true:false; + match &= (g_dist.template get<p::v>(key)[2] == 117 + k)?true:false; + match &= (g_dist.template get<p::t>(key)[0][0] == 1921 + k)?true:false; + match &= (g_dist.template get<p::t>(key)[0][1] == 25675 + k)?true:false; + match &= (g_dist.template get<p::t>(key)[0][2] == 3117 + k)?true:false; + match &= (g_dist.template get<p::t>(key)[1][0] == 4921 + k)?true:false; + match &= (g_dist.template get<p::t>(key)[1][1] == 55675 + k)?true:false; + match &= (g_dist.template get<p::t>(key)[1][2] == 6117 + k)?true:false; + match &= (g_dist.template get<p::t>(key)[2][0] == 7921 + k)?true:false; + match &= (g_dist.template get<p::t>(key)[2][1] == 85675 + k)?true:false; + match &= (g_dist.template get<p::t>(key)[2][2] == 9117 + k)?true:false; + + ++dom2; + } + + BOOST_REQUIRE_EQUAL(match,true); + + g_dist.template ghost_get<p::x,p::y,p::z,p::s,p::v,p::t>(); - g_dist.ghost_sync(); + // check that the communication is correctly completed - // Compute the halo + auto domg = g_dist.getDomainGhostIterator(); - jacobi_iteration(g_it_halo); - }*/ + // check that the grid with the ghost past store the correct information + while (domg.isNext()) + { + auto key = domg.get(); + auto key_g = g_dist.getGKey(key); + + size_t k = info.LinId(key_g); + + // In this case the boundary condition are non periodic + if (g_dist.isInside(key_g)) + { + match &= (g_dist.template get<p::x>(key),1 + k)?true:false; + match &= (g_dist.template get<p::y>(key),567 + k)?true:false; + match &= (g_dist.template get<p::z>(key), 341 + k)?true:false; + match &= (g_dist.template get<p::s>(key), 5670 + k)?true:false; + + match &= (g_dist.template get<p::v>(key)[0], 921 + k)?true:false; + match &= (g_dist.template get<p::v>(key)[1], 5675 + k)?true:false; + match &= (g_dist.template get<p::v>(key)[2], 117 + k)?true:false; + + match &= (g_dist.template get<p::t>(key)[0][0], 1921 + k)?true:false; + match &= (g_dist.template get<p::t>(key)[0][1], 25675 + k)?true:false; + match &= (g_dist.template get<p::t>(key)[0][2], 3117 + k)?true:false; + match &= (g_dist.template get<p::t>(key)[1][0], 4921 + k)?true:false; + match &= (g_dist.template get<p::t>(key)[1][1], 55675 + k)?true:false; + match &= (g_dist.template get<p::t>(key)[1][2], 6117 + k)?true:false; + match &= (g_dist.template get<p::t>(key)[2][0], 7921 + k)?true:false; + match &= (g_dist.template get<p::t>(key)[2][1], 85675 + k)?true:false; + match &= (g_dist.template get<p::t>(key)[2][2], 9117 + k)?true:false; + } + + ++domg; + } + + BOOST_REQUIRE_EQUAL(match,true); + } +} + +BOOST_AUTO_TEST_CASE( grid_dist_id_iterator_test_use) +{ + // Domain + Box<2,float> domain({0.0,0.0},{1.0,1.0}); + + // Initialize the global VCluster + init_global_v_cluster(&boost::unit_test::framework::master_test_suite().argc,&boost::unit_test::framework::master_test_suite().argv); + + long int k = 1024*1024*global_v_cluster->getProcessingUnits(); + k = std::pow(k, 1/2.); + + Test2D(domain,k); + Test2D_complex(domain,k); + // Domain + Box<3,float> domain3({0.0,0.0,0.0},{1.0,1.0,1.0}); + + k = 128*128*128*global_v_cluster->getProcessingUnits(); + k = std::pow(k, 1/3.); + Test3D(domain3,k); + Test3D_complex(domain3,k); } BOOST_AUTO_TEST_SUITE_END() diff --git a/src/gargabe.hpp b/src/gargabe.hpp index 26770898..3085d30c 100644 --- a/src/gargabe.hpp +++ b/src/gargabe.hpp @@ -165,4 +165,90 @@ ///////////////////////////////////// + + // 3D test + + // g_dist.write(""); + + /* auto g_it = g_dist.getIteratorBulk(); + + auto g_it_halo = g_dist.getHalo(); + + // Let try to solve the poisson equation d2(u) = f with f = 1 and computation + // comunication overlap (100 Jacobi iteration) + + for (int i = 0 ; i < 100 ; i++) + { + g_dist.ghost_get(); + + // Compute the bulk + + jacobi_iteration(g_it); + + g_dist.ghost_sync(); + + // Compute the halo + + jacobi_iteration(g_it_halo); + }*/ + + + BOOST_AUTO_TEST_CASE( grid_dist_id_poisson_test_use) + { + // grid size + /* size_t sz[2] = {1024,1024}; + + // Distributed grid with id decomposition + + grid_dist_id<2, scalar<float>, CartDecomposition<2,size_t>> g_dist(sz); + + // Create the grid on memory + + g_dist.Create();*/ + + /* auto g_it = g_dist.getIteratorBulk(); + + auto g_it_halo = g_dist.getHalo(); + + // Let try to solve the poisson equation d2(u) = f with f = 1 and computation + // comunication overlap (100 Jacobi iteration) + + for (int i = 0 ; i < 100 ; i++) + { + g_dist.ghost_get(); + + // Compute the bulk + + jacobi_iteration(g_it); + + g_dist.ghost_sync(); + + // Compute the halo + + jacobi_iteration(g_it_halo); + }*/ + } + + template<typename iterator> void jacobi_iteration(iterator g_it, grid_dist_id<2, float, scalar<float>, CartDecomposition<2,float>> & g_dist) + { + // scalar + typedef scalar<float> S; + + // iterator + + while(g_it.isNext()) + { + // Jacobi update + + auto pos = g_it.get(); + + g_dist.template get<S::ele>(pos) = (g_dist.template get<S::ele>(pos.move(0,1)) + + g_dist.template get<S::ele>(pos.move(0,-1)) + + g_dist.template get<S::ele>(pos.move(1,1)) + + g_dist.template get<S::ele>(pos.move(1,-1)) / 4.0); + + ++g_it; + } + } + #endif /* GARGABE_HPP_ */ -- GitLab