Skip to content

Commit a624b9d

Browse files
committed
Merge branch 'BaseLibMPI' into 'master'
Small MPI wrappers for gather and reduce operations See merge request ogs/ogs!5149
2 parents b2817c6 + ff9e84a commit a624b9d

File tree

93 files changed

+637
-1458
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

93 files changed

+637
-1458
lines changed

Applications/ApplicationsLib/LinearSolverLibrarySetup.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
/// The default implementation is empty providing polymorphic behaviour when
2020
/// using this class.
2121

22+
#include "BaseLib/MPI.h"
2223
#include "NumLib/DOF/GlobalMatrixProviders.h"
2324

2425
#if defined(USE_PETSC)
@@ -28,9 +29,8 @@ namespace ApplicationsLib
2829
{
2930
struct LinearSolverLibrarySetup final
3031
{
31-
LinearSolverLibrarySetup(int argc, char* argv[])
32+
LinearSolverLibrarySetup(int argc, char* argv[]) : mpi_setup(argc, argv)
3233
{
33-
MPI_Init(&argc, &argv);
3434
char help[] = "ogs6 with PETSc \n";
3535
PetscInitialize(&argc, &argv, nullptr, help);
3636
MPI_Comm_set_errhandler(PETSC_COMM_WORLD, MPI_ERRORS_RETURN);
@@ -40,8 +40,9 @@ struct LinearSolverLibrarySetup final
4040
{
4141
NumLib::cleanupGlobalMatrixProviders();
4242
PetscFinalize();
43-
MPI_Finalize();
4443
}
44+
45+
BaseLib::MPI::Setup mpi_setup;
4546
};
4647
} // ApplicationsLib
4748
#elif defined(USE_LIS)

Applications/ApplicationsLib/TestDefinition.cpp

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@
2020
#include "BaseLib/ConfigTree.h"
2121
#include "BaseLib/Error.h"
2222
#include "BaseLib/FileTools.h"
23-
#ifdef USE_PETSC
24-
#include <petsc.h>
23+
#include "BaseLib/MPI.h"
2524

25+
#ifdef USE_PETSC
2626
#include "MeshLib/IO/VtkIO/VtuInterface.h" // For petsc file name conversion.
2727
#endif
2828

@@ -197,16 +197,13 @@ TestDefinition::TestDefinition(BaseLib::ConfigTree const& config_tree,
197197
//! \ogs_file_param{prj__test_definition__vtkdiff__file}
198198
vtkdiff_config.getConfigParameter<std::string>("file");
199199
#ifdef USE_PETSC
200-
int mpi_size;
201-
MPI_Comm_size(PETSC_COMM_WORLD, &mpi_size);
202-
if (mpi_size > 1)
200+
BaseLib::MPI::Mpi mpi;
201+
if (mpi.size > 1)
203202
{
204-
int rank;
205-
MPI_Comm_rank(PETSC_COMM_WORLD, &rank);
206203
filename =
207204
MeshLib::IO::getVtuFileNameForPetscOutputWithoutExtension(
208205
filename) +
209-
"_" + std::to_string(rank) + ".vtu";
206+
"_" + std::to_string(mpi.rank) + ".vtu";
210207
}
211208
#endif // OGS_USE_PETSC
212209
filenames.push_back(filename);

Applications/Utils/FileConverter/ConvertSHPToGLI.cpp

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,14 @@
1414

1515
#include <tclap/CmdLine.h>
1616

17-
#ifdef USE_PETSC
18-
#include <mpi.h>
19-
#endif
20-
2117
// STL
2218
#include <fstream>
2319
#include <vector>
2420

2521
// ShapeLib
2622
#include <shapefil.h>
2723

24+
#include "BaseLib/MPI.h"
2825
#include "GeoLib/GEOObjects.h"
2926
#include "GeoLib/IO/XmlIO/Qt/XmlGmlInterface.h"
3027
#include "GeoLib/IO/XmlIO/Qt/XmlStnInterface.h"
@@ -185,9 +182,7 @@ int main(int argc, char* argv[])
185182

186183
cmd.parse(argc, argv);
187184

188-
#ifdef USE_PETSC
189-
MPI_Init(&argc, &argv);
190-
#endif
185+
BaseLib::MPI::Setup mpi_setup(argc, argv);
191186

192187
std::string fname(shapefile_arg.getValue());
193188

@@ -207,9 +202,6 @@ int main(int argc, char* argv[])
207202
ERR("Shape file contains {:d} polylines.", number_of_elements);
208203
ERR("This programme only handles only files containing points.");
209204
SHPClose(hSHP);
210-
#ifdef USE_PETSC
211-
MPI_Finalize();
212-
#endif
213205
return EXIT_SUCCESS;
214206
}
215207
SHPClose(hSHP);
@@ -304,8 +296,5 @@ int main(int argc, char* argv[])
304296
ERR("Could not open the database file.");
305297
}
306298

307-
#ifdef USE_PETSC
308-
MPI_Finalize();
309-
#endif
310299
return EXIT_SUCCESS;
311300
}

Applications/Utils/FileConverter/FEFLOW2OGS.cpp

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,8 @@
1414
// ThirdParty
1515
#include <tclap/CmdLine.h>
1616

17-
#ifdef USE_PETSC
18-
#include <mpi.h>
19-
#endif
20-
21-
// BaseLib
2217
#include "BaseLib/FileTools.h"
18+
#include "BaseLib/MPI.h"
2319
#include "BaseLib/RunTime.h"
2420
#include "InfoLib/GitInfo.h"
2521
#ifndef WIN32
@@ -62,9 +58,7 @@ int main(int argc, char* argv[])
6258

6359
cmd.parse(argc, argv);
6460

65-
#ifdef USE_PETSC
66-
MPI_Init(&argc, &argv);
67-
#endif
61+
BaseLib::MPI::Setup mpi_setup(argc, argv);
6862

6963
// *** read mesh
7064
INFO("Reading {:s}.", feflow_mesh_arg.getValue());
@@ -81,9 +75,6 @@ int main(int argc, char* argv[])
8175
if (mesh == nullptr)
8276
{
8377
INFO("Could not read mesh from {:s}.", feflow_mesh_arg.getValue());
84-
#ifdef USE_PETSC
85-
MPI_Finalize();
86-
#endif
8778
return EXIT_FAILURE;
8879
}
8980
#ifndef WIN32
@@ -99,8 +90,5 @@ int main(int argc, char* argv[])
9990
INFO("Writing {:s}.", ogs_mesh_fname);
10091
MeshLib::IO::writeMeshToFile(*mesh, ogs_mesh_fname);
10192
INFO("\tDone.");
102-
#ifdef USE_PETSC
103-
MPI_Finalize();
104-
#endif
10593
return EXIT_SUCCESS;
10694
}

Applications/Utils/FileConverter/GMSH2OGS.cpp

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,8 @@
1919
// ThirdParty
2020
#include <tclap/CmdLine.h>
2121

22-
#ifdef USE_PETSC
23-
#include <mpi.h>
24-
#endif
25-
26-
// BaseLib
2722
#include "BaseLib/FileTools.h"
23+
#include "BaseLib/MPI.h"
2824
#include "BaseLib/RunTime.h"
2925
#include "InfoLib/GitInfo.h"
3026
#ifndef WIN32
@@ -176,9 +172,7 @@ int main(int argc, char* argv[])
176172

177173
cmd.parse(argc, argv);
178174

179-
#ifdef USE_PETSC
180-
MPI_Init(&argc, &argv);
181-
#endif
175+
BaseLib::MPI::Setup mpi_setup(argc, argv);
182176

183177
// *** read mesh
184178
INFO("Reading {:s}.", gmsh_mesh_arg.getValue());
@@ -194,9 +188,6 @@ int main(int argc, char* argv[])
194188
if (mesh == nullptr)
195189
{
196190
INFO("Could not read mesh from {:s}.", gmsh_mesh_arg.getValue());
197-
#ifdef USE_PETSC
198-
MPI_Finalize();
199-
#endif
200191
return -1;
201192
}
202193
#ifndef WIN32
@@ -279,8 +270,5 @@ int main(int argc, char* argv[])
279270
MeshLib::IO::writeMeshToFile(*mesh, ogs_mesh_arg.getValue());
280271

281272
delete mesh;
282-
#ifdef USE_PETSC
283-
MPI_Finalize();
284-
#endif
285273
return EXIT_SUCCESS;
286274
}

Applications/Utils/FileConverter/GocadSGridReader.cpp

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,13 @@
1212
#include <spdlog/spdlog.h>
1313
#include <tclap/CmdLine.h>
1414

15-
#ifdef USE_PETSC
16-
#include <mpi.h>
17-
#endif
18-
1915
#include <fstream>
2016
#include <sstream>
2117
#include <string>
2218

2319
#include "Applications/FileIO/GocadIO/GenerateFaceSetMeshes.h"
2420
#include "BaseLib/FileTools.h"
21+
#include "BaseLib/MPI.h"
2522
#include "InfoLib/GitInfo.h"
2623
#include "MeshLib/Elements/Element.h"
2724
#include "MeshLib/IO/writeMeshToFile.h"
@@ -61,9 +58,7 @@ int main(int argc, char* argv[])
6158

6259
cmd.parse(argc, argv);
6360

64-
#ifdef USE_PETSC
65-
MPI_Init(&argc, &argv);
66-
#endif
61+
BaseLib::MPI::Setup mpi_setup(argc, argv);
6762

6863
// read the Gocad SGrid
6964
INFO("Start reading Gocad SGrid.");
@@ -82,8 +77,5 @@ int main(int argc, char* argv[])
8277

8378
INFO("Writing mesh to '{:s}'.", mesh_output_arg.getValue());
8479
MeshLib::IO::writeMeshToFile(*mesh, mesh_output_arg.getValue());
85-
#ifdef USE_PETSC
86-
MPI_Finalize();
87-
#endif
8880
return EXIT_SUCCESS;
8981
}

Applications/Utils/FileConverter/GocadTSurfaceReader.cpp

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,8 @@
99

1010
#include <tclap/CmdLine.h>
1111

12-
#ifdef USE_PETSC
13-
#include <mpi.h>
14-
#endif
15-
1612
#include "Applications/FileIO/GocadIO/GocadAsciiReader.h"
13+
#include "BaseLib/MPI.h"
1714
#include "InfoLib/GitInfo.h"
1815
#include "MeshLib/IO/VtkIO/VtuInterface.h"
1916
#include "MeshLib/Mesh.h"
@@ -65,17 +62,12 @@ int main(int argc, char* argv[])
6562

6663
cmd.parse(argc, argv);
6764

68-
#ifdef USE_PETSC
69-
MPI_Init(&argc, &argv);
70-
#endif
65+
BaseLib::MPI::Setup mpi_setup(argc, argv);
7166

7267
if (export_lines_arg.isSet() && export_surfaces_arg.isSet())
7368
{
7469
ERR("Both the 'lines-only'-flag and 'surfaces-only'-flag are set. Only "
7570
"one is allowed at a time.");
76-
#ifdef USE_PETSC
77-
MPI_Finalize();
78-
#endif
7971
return 2;
8072
}
8173

@@ -94,9 +86,6 @@ int main(int argc, char* argv[])
9486
if (!FileIO::Gocad::GocadAsciiReader::readFile(file_name, meshes, t))
9587
{
9688
ERR("Error reading file.");
97-
#ifdef USE_PETSC
98-
MPI_Finalize();
99-
#endif
10089
return 1;
10190
}
10291
INFO("{:d} meshes found.", meshes.size());
@@ -115,8 +104,5 @@ int main(int argc, char* argv[])
115104
MeshLib::IO::VtuInterface vtu(mesh.get(), data_mode, compressed);
116105
vtu.writeToFile(dir + delim + mesh->getName() + ".vtu");
117106
}
118-
#ifdef USE_PETSC
119-
MPI_Finalize();
120-
#endif
121107
return 0;
122108
}

Applications/Utils/FileConverter/Mesh2Raster.cpp

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,12 @@
99

1010
#include <tclap/CmdLine.h>
1111

12-
#ifdef USE_PETSC
13-
#include <mpi.h>
14-
#endif
15-
1612
#include <filesystem>
1713
#include <fstream>
1814
#include <memory>
1915
#include <string>
2016

17+
#include "BaseLib/MPI.h"
2118
#include "GeoLib/AABB.h"
2219
#include "InfoLib/GitInfo.h"
2320
#include "MeshLib/IO/readMeshFromFile.h"
@@ -52,28 +49,20 @@ int main(int argc, char* argv[])
5249
cmd.add(input_arg);
5350
cmd.parse(argc, argv);
5451

55-
#ifdef USE_PETSC
56-
MPI_Init(&argc, &argv);
57-
#endif
52+
BaseLib::MPI::Setup mpi_setup(argc, argv);
5853

5954
INFO("Rasterising mesh...");
6055
std::unique_ptr<MeshLib::Mesh> const mesh(
6156
MeshLib::IO::readMeshFromFile(input_arg.getValue()));
6257
if (mesh == nullptr)
6358
{
6459
ERR("Error reading mesh file.");
65-
#ifdef USE_PETSC
66-
MPI_Finalize();
67-
#endif
6860
return 1;
6961
}
7062
if (mesh->getDimension() != 2)
7163
{
7264
ERR("The programme requires a mesh containing two-dimensional elements "
7365
"(i.e. triangles or quadrilaterals.");
74-
#ifdef USE_PETSC
75-
MPI_Finalize();
76-
#endif
7766
return 2;
7867
}
7968

@@ -178,8 +167,5 @@ int main(int argc, char* argv[])
178167
}
179168
out.close();
180169
INFO("Result written to {:s}", output_name);
181-
#ifdef USE_PETSC
182-
MPI_Finalize();
183-
#endif
184170
return 0;
185171
}

Applications/Utils/FileConverter/Mesh2Shape.cpp

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,8 @@
99

1010
#include <tclap/CmdLine.h>
1111

12-
#ifdef USE_PETSC
13-
#include <mpi.h>
14-
#endif
15-
1612
#include "Applications/FileIO/SHPInterface.h"
13+
#include "BaseLib/MPI.h"
1714
#include "InfoLib/GitInfo.h"
1815
#include "MeshLib/IO/readMeshFromFile.h"
1916
#include "MeshLib/Mesh.h"
@@ -43,22 +40,14 @@ int main(int argc, char* argv[])
4340

4441
cmd.parse(argc, argv);
4542

46-
#ifdef USE_PETSC
47-
MPI_Init(&argc, &argv);
48-
#endif
43+
BaseLib::MPI::Setup mpi_setup(argc, argv);
4944

5045
std::string const file_name(input_arg.getValue());
5146
std::unique_ptr<MeshLib::Mesh> const mesh(
5247
MeshLib::IO::readMeshFromFile(file_name));
5348
if (FileIO::SHPInterface::write2dMeshToSHP(output_arg.getValue(), *mesh))
5449
{
55-
#ifdef USE_PETSC
56-
MPI_Finalize();
57-
#endif
5850
return EXIT_SUCCESS;
5951
}
60-
#ifdef USE_PETSC
61-
MPI_Finalize();
62-
#endif
6352
return EXIT_FAILURE;
6453
}

0 commit comments

Comments
 (0)