From e8947b1b94a331ccaaf02c54dede11da26a0834c Mon Sep 17 00:00:00 2001 From: Giovanni Alzetta Date: Thu, 19 Apr 2018 16:58:05 +0200 Subject: [PATCH] Fixed distributed cpt locations return tuple and added test --- .../changes/minor/20180423GiovanniAlzetta | 5 + source/grid/grid_tools.cc | 40 +++++-- .../distributed_compute_point_locations_03.cc | 113 ++++++++++++++++++ ...h_mpi=true.with_p4est=true.mpirun=2.output | 27 +++++ ...h_mpi=true.with_p4est=true.mpirun=3.output | 41 +++++++ 5 files changed, 214 insertions(+), 12 deletions(-) create mode 100644 doc/news/changes/minor/20180423GiovanniAlzetta create mode 100644 tests/grid/distributed_compute_point_locations_03.cc create mode 100644 tests/grid/distributed_compute_point_locations_03.with_mpi=true.with_p4est=true.mpirun=2.output create mode 100644 tests/grid/distributed_compute_point_locations_03.with_mpi=true.with_p4est=true.mpirun=3.output diff --git a/doc/news/changes/minor/20180423GiovanniAlzetta b/doc/news/changes/minor/20180423GiovanniAlzetta new file mode 100644 index 0000000000..fd3cb49979 --- /dev/null +++ b/doc/news/changes/minor/20180423GiovanniAlzetta @@ -0,0 +1,5 @@ +Fixed: GridTools::distributed_compute_point_locations now returns the correct +maps values (third component of the output tuple). Added a test to check it. +
+(Giovanni Alzetta, 2018/04/23) + diff --git a/source/grid/grid_tools.cc b/source/grid/grid_tools.cc index 0d6b768e27..8b65ba0acd 100644 --- a/source/grid/grid_tools.cc +++ b/source/grid/grid_tools.cc @@ -4143,18 +4143,21 @@ next_cell: { // Point inside locally owned cell: storing all its data std::vector < Point > cell_points(indices_loc.size()); + std::vector < unsigned int > cell_points_idx(indices_loc.size()); for (unsigned int i=0; i< indices_loc.size(); ++i) { // Adding the point to the cell points cell_points[i] = local_points[indices_loc[i]]; + // Storing the index: notice indices loc refer to the local points // vector, but we need to return the index with respect of // the points owned by the current process + cell_points_idx[i] = local_points_idx[indices_loc[i]]; classified_pts.emplace_back(local_points_idx[indices_loc[i]]); } output_unmap.emplace(std::make_pair(cell_loc, std::make_tuple(q_loc, - indices_loc, + cell_points_idx, cell_points, std::vector (indices_loc.size(),cell_loc->subdomain_id())))); @@ -4164,9 +4167,11 @@ next_cell: // Point inside ghost cell: storing all its information and preparing // it to be sent std::vector < Point > cell_points(indices_loc.size()); + std::vector < unsigned int > cell_points_idx(indices_loc.size()); for (unsigned int i=0; i< indices_loc.size(); ++i) { cell_points[i] = local_points[indices_loc[i]]; + cell_points_idx[i] = local_points_idx[indices_loc[i]]; classified_pts.emplace_back(local_points_idx[indices_loc[i]]); } // Each key of the following map represent a process, @@ -4176,7 +4181,7 @@ next_cell: // To identify the cell on the other process we use the cell id std::get<0>(map_tuple_owner).emplace_back(cell_loc->id()); std::get<1>(map_tuple_owner).emplace_back(q_loc); - std::get<2>(map_tuple_owner).emplace_back(indices_loc); + std::get<2>(map_tuple_owner).emplace_back(cell_points_idx); std::get<3>(map_tuple_owner).emplace_back(cell_points); } // else: the cell is artificial, nothing to do @@ -4218,7 +4223,7 @@ next_cell: // Rewriting the contents of the map in human readable format const auto &received_process = rank_and_points.first; const auto &received_points = rank_and_points.second.first; - const auto &received_ranks = rank_and_points.second.second; + const auto &received_map = rank_and_points.second.second; // Initializing the vectors needed to store the result of compute point location std::vector< typename Triangulation::active_cell_iterator > in_cell; @@ -4246,7 +4251,7 @@ next_cell: std::vector< Point > cell_points(loc_size); for (unsigned int pt=0; pt >, - std::vector > > + std::vector< unsigned int > > > other_check_pts; - const auto &other_check_idx = std::get<2>(guessed_points); + // This map goes from the point index to a vector of + // ranks probable owners + const std::map< unsigned int, std::vector< unsigned int > > + &other_check_idx = std::get<2>(guessed_points); // Points in classified pts need not to be communicated; // sorting the array classified pts in order to use @@ -4416,15 +4427,20 @@ next_cell: for (const auto &pt_to_guesses: other_check_idx) { + const auto &point_idx = pt_to_guesses.first; + const auto &probable_owners_rks = pt_to_guesses.second; if ( !std::binary_search( - classified_pts.begin(), classified_pts.end(),pt_to_guesses.first) ) + classified_pts.begin(), classified_pts.end(), point_idx) ) // The point wasn't found in ghost or locally owned cells: adding it to the map - for (unsigned int rank=0; rank +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + + +using namespace dealii; + + + +template +void test_distributed_cpt(unsigned int ref_cube) +{ + MPI_Comm mpi_communicator = MPI_COMM_WORLD; + unsigned int n_procs = Utilities::MPI::n_mpi_processes(mpi_communicator); + unsigned int my_rank = Utilities::MPI::this_mpi_process(mpi_communicator); + + deallog << "Testing for dim = " << dim << " on " << n_procs << " processes" << std::endl; + deallog << "Cube refinements: " << ref_cube << std::endl; + + // Creeating the cube on which to run distributed cpt loc + parallel::distributed::Triangulation cube_d(mpi_communicator); + GridGenerator::hyper_cube(cube_d); + cube_d.refine_global(ref_cube); + + // We shall use the points from a shared grid so that each index is known + std::vector > test_points; + Triangulation cube; + GridGenerator::hyper_cube(cube); + cube.refine_global(ref_cube); + for (auto cell: cube.active_cell_iterators()) + test_points.emplace_back(cell->center()); + + deallog << " Testing on " << test_points.size() << " points" << std::endl; + + // Computing bounding boxes describing the locally owned part of the mesh + IteratorFilters::LocallyOwnedCell locally_owned_cell_predicate; + std::vector< BoundingBox > local_bbox = GridTools::compute_mesh_predicate_bounding_box + (cube_d, locally_owned_cell_predicate, + 1, false, 4); + + // Obtaining the global mesh description through an all to all communication + std::vector< std::vector< BoundingBox > > global_bboxes; + global_bboxes = Utilities::MPI::all_gather(mpi_communicator,local_bbox); + + // Initializing the cache + GridTools::Cache cache_d(cube_d); + auto output_tuple = distributed_compute_point_locations + (cache_d,test_points,global_bboxes); + const auto &maps = std::get<2>(output_tuple); + const auto &points = std::get<3>(output_tuple); + const auto &ranks = std::get<4>(output_tuple); + + // Testing the results: if the map in maps is correct test_points[maps[i][j]] == points[i][j] + bool test_passed = true; + + for (unsigned int i=0; i< points.size(); ++i) + { + for (unsigned int j=0; j< maps[i].size(); ++j) + if ( (test_points[maps[i][j]] - points[i][j]).norm() > 1e-10 ) + { + deallog << " Error in cell " << i << " with position " << j << std::endl; + deallog << " Received map was: " << maps[i][j] << std::endl; + deallog << " From rank: " << ranks[i][j] << std::endl; + test_passed = false; + } + } + + if (test_passed) + deallog << "Test passed" << std::endl; + else + deallog << "Test FAILED" << std::endl; +} + +int main (int argc, char *argv[]) +{ + Utilities::MPI::MPI_InitFinalize mpi_initialization (argc, argv, 1); + MPILogInitAll log; + + deallog << "Deal.II GridTools::distributed_compute_point_locations" << std::endl; + deallog << "Test 3: maps values" << std::endl; + deallog << "2D tests:" << std::endl; + test_distributed_cpt<2>(3); + deallog << "3D tests" << std::endl; + test_distributed_cpt<3>(3); +} diff --git a/tests/grid/distributed_compute_point_locations_03.with_mpi=true.with_p4est=true.mpirun=2.output b/tests/grid/distributed_compute_point_locations_03.with_mpi=true.with_p4est=true.mpirun=2.output new file mode 100644 index 0000000000..46a98bd6a9 --- /dev/null +++ b/tests/grid/distributed_compute_point_locations_03.with_mpi=true.with_p4est=true.mpirun=2.output @@ -0,0 +1,27 @@ + +DEAL:0::Deal.II GridTools::distributed_compute_point_locations +DEAL:0::Test 3: maps values +DEAL:0::2D tests: +DEAL:0::Testing for dim = 2 on 2 processes +DEAL:0::Cube refinements: 3 +DEAL:0:: Testing on 64 points +DEAL:0::Test passed +DEAL:0::3D tests +DEAL:0::Testing for dim = 3 on 2 processes +DEAL:0::Cube refinements: 3 +DEAL:0:: Testing on 512 points +DEAL:0::Test passed + +DEAL:1::Deal.II GridTools::distributed_compute_point_locations +DEAL:1::Test 3: maps values +DEAL:1::2D tests: +DEAL:1::Testing for dim = 2 on 2 processes +DEAL:1::Cube refinements: 3 +DEAL:1:: Testing on 64 points +DEAL:1::Test passed +DEAL:1::3D tests +DEAL:1::Testing for dim = 3 on 2 processes +DEAL:1::Cube refinements: 3 +DEAL:1:: Testing on 512 points +DEAL:1::Test passed + diff --git a/tests/grid/distributed_compute_point_locations_03.with_mpi=true.with_p4est=true.mpirun=3.output b/tests/grid/distributed_compute_point_locations_03.with_mpi=true.with_p4est=true.mpirun=3.output new file mode 100644 index 0000000000..08cc873451 --- /dev/null +++ b/tests/grid/distributed_compute_point_locations_03.with_mpi=true.with_p4est=true.mpirun=3.output @@ -0,0 +1,41 @@ + +DEAL:0::Deal.II GridTools::distributed_compute_point_locations +DEAL:0::Test 3: maps values +DEAL:0::2D tests: +DEAL:0::Testing for dim = 2 on 3 processes +DEAL:0::Cube refinements: 3 +DEAL:0:: Testing on 64 points +DEAL:0::Test passed +DEAL:0::3D tests +DEAL:0::Testing for dim = 3 on 3 processes +DEAL:0::Cube refinements: 3 +DEAL:0:: Testing on 512 points +DEAL:0::Test passed + +DEAL:1::Deal.II GridTools::distributed_compute_point_locations +DEAL:1::Test 3: maps values +DEAL:1::2D tests: +DEAL:1::Testing for dim = 2 on 3 processes +DEAL:1::Cube refinements: 3 +DEAL:1:: Testing on 64 points +DEAL:1::Test passed +DEAL:1::3D tests +DEAL:1::Testing for dim = 3 on 3 processes +DEAL:1::Cube refinements: 3 +DEAL:1:: Testing on 512 points +DEAL:1::Test passed + + +DEAL:2::Deal.II GridTools::distributed_compute_point_locations +DEAL:2::Test 3: maps values +DEAL:2::2D tests: +DEAL:2::Testing for dim = 2 on 3 processes +DEAL:2::Cube refinements: 3 +DEAL:2:: Testing on 64 points +DEAL:2::Test passed +DEAL:2::3D tests +DEAL:2::Testing for dim = 3 on 3 processes +DEAL:2::Cube refinements: 3 +DEAL:2:: Testing on 512 points +DEAL:2::Test passed + -- 2.39.5