From a0b229f845c4894d433c330a364e7a9c525d3aec Mon Sep 17 00:00:00 2001 From: Timo Heister Date: Sun, 13 Aug 2017 16:33:02 -0600 Subject: [PATCH] add parallel mesh_loop test --- tests/meshworker/mesh_loop_mpi_01.cc | 192 ++++++++++++++++++ ...oop_mpi_01.with_p4est=true.mpirun=3.output | 165 +++++++++++++++ 2 files changed, 357 insertions(+) create mode 100644 tests/meshworker/mesh_loop_mpi_01.cc create mode 100644 tests/meshworker/mesh_loop_mpi_01.with_p4est=true.mpirun=3.output diff --git a/tests/meshworker/mesh_loop_mpi_01.cc b/tests/meshworker/mesh_loop_mpi_01.cc new file mode 100644 index 0000000000..1bae3090fb --- /dev/null +++ b/tests/meshworker/mesh_loop_mpi_01.cc @@ -0,0 +1,192 @@ +// --------------------------------------------------------------------- +// +// Copyright (C) 2007 - 2016 by the deal.II authors +// +// This file is part of the deal.II library. +// +// The deal.II library is free software; you can use it, redistribute +// it, and/or modify it under the terms of the GNU Lesser General +// Public License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// The full text of the license can be found in the file LICENSE at +// the top level of the deal.II distribution. +// +// --------------------------------------------------------------------- + + + + +// test mesh_loop in parallel + +#include "../tests.h" +#include +#include +#include +#include +#include + +struct ScratchData {}; +struct CopyData +{ + unsigned n_cells; + unsigned int n_own_cells; + unsigned int n_ghost_cells; + + CopyData(): n_cells(0), n_own_cells(0), n_ghost_cells(0) + {} + + void reset() + { + n_cells = n_own_cells = n_ghost_cells = 0; + } +}; + +using namespace MeshWorker; + +template +void test() +{ + parallel::distributed::Triangulation tria(MPI_COMM_WORLD); + GridGenerator::hyper_cube(tria); + tria.refine_global(1); + tria.begin_active()->set_refine_flag(); + tria.execute_coarsening_and_refinement(); + + ScratchData scratch; + CopyData copy; + + auto cell=tria.begin_active(); + auto endc=tria.end(); + + typedef decltype(cell) Iterator; + + auto cell_worker = [] (const Iterator &cell, ScratchData &s, CopyData &c) + { + deallog << "Cell worker on : " << cell + << " ghost? " << cell->is_ghost() << std::endl; + ++c.n_cells; + if (cell->is_ghost()) + ++c.n_ghost_cells; + else + ++c.n_own_cells; + + }; + + auto boundary_worker = [] (const Iterator &cell, const unsigned int &f, ScratchData &, CopyData &) + { + deallog << "Boundary worker on : " << cell << ", Face : "<< f << std::endl; + }; + + auto face_worker = [] + (const Iterator &cell, const unsigned int &f, const unsigned int &sf, + const Iterator &ncell, const unsigned int &nf, const unsigned int &nsf, + ScratchData &s, CopyData &c) + { + deallog << "Face worker on : " << cell << ", Neighbor cell : " << ncell + << ", Face : "<< f << ", Neighbor Face : " << nf + << ", Subface: " << sf + << ", Neighbor Subface: " << nsf + << ", cell->is_ghost(): " << cell->is_ghost() + << ", neighbor->is_ghost(): " << ncell->is_ghost() + << std::endl; + }; + + CopyData data; + auto copier = [&](const CopyData &c) + { + data.n_cells += c.n_cells; + data.n_own_cells += c.n_own_cells; + data.n_ghost_cells += c.n_ghost_cells; + }; + + std::function + empty_cell_worker; + std::function + empty_boundary_worker; + + auto print_summary = [&]() + { + deallog << "n_cells: " << data.n_cells + << " n_own_cells: " << data.n_own_cells + << " n_ghost_cells: " << data.n_ghost_cells << std::endl; + }; + + + { + MPILogInitAll log; + deallog << "OWN CELLS:" << std::endl << std::endl; + + data.reset(); + mesh_loop(cell, endc, cell_worker, copier, scratch, copy, assemble_own_cells); + print_summary(); + } + + { + MPILogInitAll log; + deallog << "GHOST and OWN CELLS" << std::endl << std::endl; + + data.reset(); + mesh_loop(cell, endc, cell_worker, copier, scratch, copy, assemble_own_cells | assemble_ghost_cells); + print_summary(); + } + + { + MPILogInitAll log; + deallog << "GHOST CELLS:" << std::endl << std::endl; + + data.reset(); + mesh_loop(cell, endc, cell_worker, copier, scratch, copy, assemble_ghost_cells); + print_summary(); + } + + { + MPILogInitAll log; + deallog << "CELLS and FACES" << std::endl << std::endl; + + data.reset(); + mesh_loop(cell, endc, cell_worker, copier, scratch, copy, assemble_own_cells | assemble_own_interior_faces_once | assemble_ghost_faces_once, + empty_boundary_worker, face_worker); + print_summary(); + } + + { + MPILogInitAll log; + deallog << "OWN CELLS AND GHOST FACES ONCE" << std::endl << std::endl; + + data.reset(); + mesh_loop(cell, endc, cell_worker, copier, scratch, copy, assemble_own_cells | assemble_ghost_faces_once, + empty_boundary_worker, face_worker); + print_summary(); + } + + { + MPILogInitAll log; + deallog << "GHOST FACES BOTH" << std::endl << std::endl; + + data.reset(); + mesh_loop(cell, endc, empty_cell_worker, copier, scratch, copy, assemble_ghost_faces_both, + empty_boundary_worker, face_worker); + print_summary(); + } + + { + MPILogInitAll log; + deallog << "BOUNDARY FACES" << std::endl << std::endl; + + data.reset(); + mesh_loop(cell, endc, empty_cell_worker, copier, scratch, copy, assemble_boundary_faces, + boundary_worker); + print_summary(); + } + + deallog << "OK" << std::endl; +} + + +int main(int argc, char *argv[]) +{ + Utilities::MPI::MPI_InitFinalize mpi_initialization(argc, argv, 1); + + + test<2,2>(); +} diff --git a/tests/meshworker/mesh_loop_mpi_01.with_p4est=true.mpirun=3.output b/tests/meshworker/mesh_loop_mpi_01.with_p4est=true.mpirun=3.output new file mode 100644 index 0000000000..48faa945d9 --- /dev/null +++ b/tests/meshworker/mesh_loop_mpi_01.with_p4est=true.mpirun=3.output @@ -0,0 +1,165 @@ + +DEAL:0::OWN CELLS: +DEAL:0:: +DEAL:0::Cell worker on : 2.0 ghost? 0 +DEAL:0::Cell worker on : 2.1 ghost? 0 +DEAL:0::Cell worker on : 2.2 ghost? 0 +DEAL:0::Cell worker on : 2.3 ghost? 0 +DEAL:0::n_cells: 4 n_own_cells: 4 n_ghost_cells: 0 + +DEAL:1::OWN CELLS: +DEAL:1:: +DEAL:1::n_cells: 0 n_own_cells: 0 n_ghost_cells: 0 + + +DEAL:2::OWN CELLS: +DEAL:2:: +DEAL:2::Cell worker on : 1.1 ghost? 0 +DEAL:2::Cell worker on : 1.2 ghost? 0 +DEAL:2::Cell worker on : 1.3 ghost? 0 +DEAL:2::n_cells: 3 n_own_cells: 3 n_ghost_cells: 0 + +DEAL:0::GHOST and OWN CELLS +DEAL:0:: +DEAL:0::Cell worker on : 1.1 ghost? 1 +DEAL:0::Cell worker on : 1.2 ghost? 1 +DEAL:0::Cell worker on : 1.3 ghost? 1 +DEAL:0::Cell worker on : 2.0 ghost? 0 +DEAL:0::Cell worker on : 2.1 ghost? 0 +DEAL:0::Cell worker on : 2.2 ghost? 0 +DEAL:0::Cell worker on : 2.3 ghost? 0 +DEAL:0::n_cells: 7 n_own_cells: 4 n_ghost_cells: 3 + +DEAL:1::GHOST and OWN CELLS +DEAL:1:: +DEAL:1::n_cells: 0 n_own_cells: 0 n_ghost_cells: 0 + + +DEAL:2::GHOST and OWN CELLS +DEAL:2:: +DEAL:2::Cell worker on : 1.1 ghost? 0 +DEAL:2::Cell worker on : 1.2 ghost? 0 +DEAL:2::Cell worker on : 1.3 ghost? 0 +DEAL:2::Cell worker on : 2.1 ghost? 1 +DEAL:2::Cell worker on : 2.2 ghost? 1 +DEAL:2::Cell worker on : 2.3 ghost? 1 +DEAL:2::n_cells: 6 n_own_cells: 3 n_ghost_cells: 3 + +DEAL:0::GHOST CELLS: +DEAL:0:: +DEAL:0::Cell worker on : 1.1 ghost? 1 +DEAL:0::Cell worker on : 1.2 ghost? 1 +DEAL:0::Cell worker on : 1.3 ghost? 1 +DEAL:0::n_cells: 3 n_own_cells: 0 n_ghost_cells: 3 + +DEAL:1::GHOST CELLS: +DEAL:1:: +DEAL:1::n_cells: 0 n_own_cells: 0 n_ghost_cells: 0 + + +DEAL:2::GHOST CELLS: +DEAL:2:: +DEAL:2::Cell worker on : 2.1 ghost? 1 +DEAL:2::Cell worker on : 2.2 ghost? 1 +DEAL:2::Cell worker on : 2.3 ghost? 1 +DEAL:2::n_cells: 3 n_own_cells: 0 n_ghost_cells: 3 + +DEAL:0::CELLS and FACES +DEAL:0:: +DEAL:0::Face worker on : 2.0, Neighbor cell : 2.1, Face : 1, Neighbor Face : 0, Subface: 4294967295, Neighbor Subface: 4294967295, cell->is_ghost(): 0, neighbor->is_ghost(): 0 +DEAL:0::Face worker on : 2.0, Neighbor cell : 2.2, Face : 3, Neighbor Face : 2, Subface: 4294967295, Neighbor Subface: 4294967295, cell->is_ghost(): 0, neighbor->is_ghost(): 0 +DEAL:0::Cell worker on : 2.0 ghost? 0 +DEAL:0::Face worker on : 2.1, Neighbor cell : 1.1, Face : 1, Neighbor Face : 0, Subface: 4294967295, Neighbor Subface: 0, cell->is_ghost(): 0, neighbor->is_ghost(): 1 +DEAL:0::Face worker on : 2.1, Neighbor cell : 2.3, Face : 3, Neighbor Face : 2, Subface: 4294967295, Neighbor Subface: 4294967295, cell->is_ghost(): 0, neighbor->is_ghost(): 0 +DEAL:0::Cell worker on : 2.1 ghost? 0 +DEAL:0::Face worker on : 2.2, Neighbor cell : 2.3, Face : 1, Neighbor Face : 0, Subface: 4294967295, Neighbor Subface: 4294967295, cell->is_ghost(): 0, neighbor->is_ghost(): 0 +DEAL:0::Face worker on : 2.2, Neighbor cell : 1.2, Face : 3, Neighbor Face : 2, Subface: 4294967295, Neighbor Subface: 0, cell->is_ghost(): 0, neighbor->is_ghost(): 1 +DEAL:0::Cell worker on : 2.2 ghost? 0 +DEAL:0::Face worker on : 2.3, Neighbor cell : 1.1, Face : 1, Neighbor Face : 0, Subface: 4294967295, Neighbor Subface: 1, cell->is_ghost(): 0, neighbor->is_ghost(): 1 +DEAL:0::Face worker on : 2.3, Neighbor cell : 1.2, Face : 3, Neighbor Face : 2, Subface: 4294967295, Neighbor Subface: 1, cell->is_ghost(): 0, neighbor->is_ghost(): 1 +DEAL:0::Cell worker on : 2.3 ghost? 0 +DEAL:0::n_cells: 4 n_own_cells: 4 n_ghost_cells: 0 + +DEAL:1::CELLS and FACES +DEAL:1:: +DEAL:1::n_cells: 0 n_own_cells: 0 n_ghost_cells: 0 + + +DEAL:2::CELLS and FACES +DEAL:2:: +DEAL:2::Face worker on : 1.1, Neighbor cell : 1.3, Face : 3, Neighbor Face : 2, Subface: 4294967295, Neighbor Subface: 4294967295, cell->is_ghost(): 0, neighbor->is_ghost(): 0 +DEAL:2::Cell worker on : 1.1 ghost? 0 +DEAL:2::Face worker on : 1.2, Neighbor cell : 1.3, Face : 1, Neighbor Face : 0, Subface: 4294967295, Neighbor Subface: 4294967295, cell->is_ghost(): 0, neighbor->is_ghost(): 0 +DEAL:2::Cell worker on : 1.2 ghost? 0 +DEAL:2::Cell worker on : 1.3 ghost? 0 +DEAL:2::n_cells: 3 n_own_cells: 3 n_ghost_cells: 0 + +DEAL:0::OWN CELLS AND GHOST FACES ONCE +DEAL:0:: +DEAL:0::Cell worker on : 2.0 ghost? 0 +DEAL:0::Face worker on : 2.1, Neighbor cell : 1.1, Face : 1, Neighbor Face : 0, Subface: 4294967295, Neighbor Subface: 0, cell->is_ghost(): 0, neighbor->is_ghost(): 1 +DEAL:0::Cell worker on : 2.1 ghost? 0 +DEAL:0::Face worker on : 2.2, Neighbor cell : 1.2, Face : 3, Neighbor Face : 2, Subface: 4294967295, Neighbor Subface: 0, cell->is_ghost(): 0, neighbor->is_ghost(): 1 +DEAL:0::Cell worker on : 2.2 ghost? 0 +DEAL:0::Face worker on : 2.3, Neighbor cell : 1.1, Face : 1, Neighbor Face : 0, Subface: 4294967295, Neighbor Subface: 1, cell->is_ghost(): 0, neighbor->is_ghost(): 1 +DEAL:0::Face worker on : 2.3, Neighbor cell : 1.2, Face : 3, Neighbor Face : 2, Subface: 4294967295, Neighbor Subface: 1, cell->is_ghost(): 0, neighbor->is_ghost(): 1 +DEAL:0::Cell worker on : 2.3 ghost? 0 +DEAL:0::n_cells: 4 n_own_cells: 4 n_ghost_cells: 0 + +DEAL:1::OWN CELLS AND GHOST FACES ONCE +DEAL:1:: +DEAL:1::n_cells: 0 n_own_cells: 0 n_ghost_cells: 0 + + +DEAL:2::OWN CELLS AND GHOST FACES ONCE +DEAL:2:: +DEAL:2::Cell worker on : 1.1 ghost? 0 +DEAL:2::Cell worker on : 1.2 ghost? 0 +DEAL:2::Cell worker on : 1.3 ghost? 0 +DEAL:2::n_cells: 3 n_own_cells: 3 n_ghost_cells: 0 + +DEAL:0::GHOST FACES BOTH +DEAL:0:: +DEAL:0::Face worker on : 2.1, Neighbor cell : 1.1, Face : 1, Neighbor Face : 0, Subface: 4294967295, Neighbor Subface: 0, cell->is_ghost(): 0, neighbor->is_ghost(): 1 +DEAL:0::Face worker on : 2.2, Neighbor cell : 1.2, Face : 3, Neighbor Face : 2, Subface: 4294967295, Neighbor Subface: 0, cell->is_ghost(): 0, neighbor->is_ghost(): 1 +DEAL:0::Face worker on : 2.3, Neighbor cell : 1.1, Face : 1, Neighbor Face : 0, Subface: 4294967295, Neighbor Subface: 1, cell->is_ghost(): 0, neighbor->is_ghost(): 1 +DEAL:0::Face worker on : 2.3, Neighbor cell : 1.2, Face : 3, Neighbor Face : 2, Subface: 4294967295, Neighbor Subface: 1, cell->is_ghost(): 0, neighbor->is_ghost(): 1 +DEAL:0::n_cells: 0 n_own_cells: 0 n_ghost_cells: 0 + +DEAL:1::GHOST FACES BOTH +DEAL:1:: +DEAL:1::n_cells: 0 n_own_cells: 0 n_ghost_cells: 0 + + +DEAL:2::GHOST FACES BOTH +DEAL:2:: +DEAL:2::Face worker on : 2.1, Neighbor cell : 1.1, Face : 1, Neighbor Face : 0, Subface: 4294967295, Neighbor Subface: 0, cell->is_ghost(): 1, neighbor->is_ghost(): 0 +DEAL:2::Face worker on : 2.2, Neighbor cell : 1.2, Face : 3, Neighbor Face : 2, Subface: 4294967295, Neighbor Subface: 0, cell->is_ghost(): 1, neighbor->is_ghost(): 0 +DEAL:2::Face worker on : 2.3, Neighbor cell : 1.1, Face : 1, Neighbor Face : 0, Subface: 4294967295, Neighbor Subface: 1, cell->is_ghost(): 1, neighbor->is_ghost(): 0 +DEAL:2::Face worker on : 2.3, Neighbor cell : 1.2, Face : 3, Neighbor Face : 2, Subface: 4294967295, Neighbor Subface: 1, cell->is_ghost(): 1, neighbor->is_ghost(): 0 +DEAL:2::n_cells: 0 n_own_cells: 0 n_ghost_cells: 0 + +DEAL:0::BOUNDARY FACES +DEAL:0:: +DEAL:0::Boundary worker on : 2.0, Face : 0 +DEAL:0::Boundary worker on : 2.0, Face : 2 +DEAL:0::Boundary worker on : 2.1, Face : 2 +DEAL:0::Boundary worker on : 2.2, Face : 0 +DEAL:0::n_cells: 0 n_own_cells: 0 n_ghost_cells: 0 + +DEAL:1::BOUNDARY FACES +DEAL:1:: +DEAL:1::n_cells: 0 n_own_cells: 0 n_ghost_cells: 0 + + +DEAL:2::BOUNDARY FACES +DEAL:2:: +DEAL:2::Boundary worker on : 1.1, Face : 1 +DEAL:2::Boundary worker on : 1.1, Face : 2 +DEAL:2::Boundary worker on : 1.2, Face : 0 +DEAL:2::Boundary worker on : 1.2, Face : 3 +DEAL:2::Boundary worker on : 1.3, Face : 1 +DEAL:2::Boundary worker on : 1.3, Face : 3 +DEAL:2::n_cells: 0 n_own_cells: 0 n_ghost_cells: 0 + +DEAL::OK -- 2.39.5