From 37ec089dd91097b651033d615b1dfc508e8c2bc2 Mon Sep 17 00:00:00 2001 From: Willem Deconinck Date: Tue, 12 Sep 2023 19:20:45 +0200 Subject: [PATCH] Use mpi_comm in DelaunayMeshGenerator --- .../meshgenerator/detail/DelaunayMeshGenerator.cc | 10 ++++++++-- .../meshgenerator/detail/DelaunayMeshGenerator.h | 1 + src/tests/mesh/test_meshgen_splitcomm.cc | 14 +++++++++++++- 3 files changed, 22 insertions(+), 3 deletions(-) diff --git a/src/atlas/meshgenerator/detail/DelaunayMeshGenerator.cc b/src/atlas/meshgenerator/detail/DelaunayMeshGenerator.cc index f8a3b0a2e..4ab849ba0 100644 --- a/src/atlas/meshgenerator/detail/DelaunayMeshGenerator.cc +++ b/src/atlas/meshgenerator/detail/DelaunayMeshGenerator.cc @@ -42,7 +42,8 @@ namespace meshgenerator { DelaunayMeshGenerator::DelaunayMeshGenerator() = default; DelaunayMeshGenerator::DelaunayMeshGenerator(const eckit::Parametrisation& p) { - p.get("part",part_=mpi::rank()); + p.get("mpi_comm",mpi_comm_=mpi::comm().name()); + p.get("part",part_=mpi::comm(mpi_comm_).rank()); p.get("reshuffle",reshuffle_=true); p.get("remove_duplicate_points",remove_duplicate_points_=true); } @@ -57,6 +58,8 @@ void DelaunayMeshGenerator::hash(eckit::Hash& h) const { void DelaunayMeshGenerator::generate(const Grid& grid, const grid::Distribution& dist, Mesh& mesh) const { + mpi::Scope mpi_scope(mpi_comm_); + auto build_global_mesh = [&](Mesh& mesh) { idx_t nb_nodes = grid.size(); mesh.nodes().resize(nb_nodes); @@ -102,6 +105,7 @@ void DelaunayMeshGenerator::generate(const Grid& grid, const grid::Distribution& if( dist.nb_partitions() == 1 ) { build_global_mesh(mesh); setGrid(mesh, grid, dist.type()); + mesh.metadata().set("mpi_comm",mpi_comm_); return; } @@ -357,10 +361,12 @@ void DelaunayMeshGenerator::generate(const Grid& grid, const grid::Distribution& extract_mesh_partition(global_mesh, mesh); setGrid(mesh, grid, dist.type()); + mesh.metadata().set("mpi_comm",mpi_comm_); } void DelaunayMeshGenerator::generate(const Grid& g, Mesh& mesh) const { - generate( g, grid::Distribution{g}, mesh); + mpi::Scope mpi_scope(mpi_comm_); + generate( g, grid::Distribution{g,g.partitioner()}, mesh); } namespace { diff --git a/src/atlas/meshgenerator/detail/DelaunayMeshGenerator.h b/src/atlas/meshgenerator/detail/DelaunayMeshGenerator.h index f397e6408..ef9c981c6 100644 --- a/src/atlas/meshgenerator/detail/DelaunayMeshGenerator.h +++ b/src/atlas/meshgenerator/detail/DelaunayMeshGenerator.h @@ -39,6 +39,7 @@ class DelaunayMeshGenerator : public MeshGenerator::Implementation { virtual void generate(const Grid&, const grid::Distribution&, Mesh&) const override; virtual void generate(const Grid&, Mesh&) const override; + std::string mpi_comm_; int part_; bool remove_duplicate_points_; bool reshuffle_; diff --git a/src/tests/mesh/test_meshgen_splitcomm.cc b/src/tests/mesh/test_meshgen_splitcomm.cc index 544aafe2f..97b31771f 100644 --- a/src/tests/mesh/test_meshgen_splitcomm.cc +++ b/src/tests/mesh/test_meshgen_splitcomm.cc @@ -98,6 +98,19 @@ CASE("StructuredMeshGenerator") { mesh.polygon().outputPythonScript(grid().name()+"_polygons_1.py"); } +CASE("DelaunayMeshGenerator") { + Fixture fixture; + + MeshGenerator meshgen{"delaunay", option::mpi_comm("split")}; + Mesh mesh = meshgen.generate(grid_CS()); + EXPECT_EQUAL(mesh.nb_parts(),mpi::comm("split").size()); + EXPECT_EQUAL(mesh.part(),mpi::comm("split").rank()); + EXPECT_EQUAL(mesh.mpi_comm(),"split"); + EXPECT_EQUAL(mpi::comm().name(),"world"); + output::Gmsh gmsh(grid_CS().name()+"_delaunay.msh",util::Config("coordinates","xyz")); + gmsh.write(mesh); +} + CASE("CubedSphereDualMeshGenerator") { Fixture fixture; @@ -177,7 +190,6 @@ CASE("MatchingPartitioner") { } - } // namespace test } // namespace atlas