Skip to content

Commit

Permalink
Use mpi_comm in DelaunayMeshGenerator
Browse files Browse the repository at this point in the history
  • Loading branch information
wdeconinck committed Sep 12, 2023
1 parent 08734eb commit 37ec089
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
10 changes: 8 additions & 2 deletions src/atlas/meshgenerator/detail/DelaunayMeshGenerator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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);
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions src/atlas/meshgenerator/detail/DelaunayMeshGenerator.h
Original file line number Diff line number Diff line change
Expand Up @@ -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_;
Expand Down
14 changes: 13 additions & 1 deletion src/tests/mesh/test_meshgen_splitcomm.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -177,7 +190,6 @@ CASE("MatchingPartitioner") {
}



} // namespace test
} // namespace atlas

Expand Down

0 comments on commit 37ec089

Please sign in to comment.