32int main(
int argc,
char* argv[])
35 "Partition a mesh for parallel computing."
36 "The tasks of this tool are in twofold:\n"
37 "1. Convert mesh file to the input file of the partitioning tool,\n"
38 "2. Partition a mesh using the partitioning tool,\n"
39 "\tcreate the mesh data of each partition,\n"
40 "\trenumber the node indices of each partition,\n"
41 "\tand output the results for parallel computing.\n"
42 "Note: If this tool is installed as a system command,\n"
43 "\tthe command must be run with its full path.\n\n"
44 "OpenGeoSys-6 software, version " +
47 "Copyright (c) 2012-2024, OpenGeoSys Community "
48 "(http://www.opengeosys.org)",
50 TCLAP::ValueArg<std::string> mesh_input(
51 "i",
"mesh-input-file",
52 "the name of the file containing the input mesh",
true,
"",
53 "file name of input mesh");
56 TCLAP::ValueArg<std::string> metis_mesh_input(
57 "x",
"metis-mesh-input-file",
58 "base name (without .mesh extension) of the file containing the metis "
61 "base name (without .mesh extension) of the file containing the metis "
63 cmd.add(metis_mesh_input);
65 TCLAP::ValueArg<std::string> output_directory_arg(
66 "o",
"output",
"directory name for the output files",
false,
"",
68 cmd.add(output_directory_arg);
70 TCLAP::ValueArg<int> nparts(
"n",
"np",
"the number of partitions",
false, 2,
74 TCLAP::SwitchArg ogs2metis_flag(
76 "Indicator to convert the ogs mesh file to METIS input file", cmd,
79 TCLAP::SwitchArg exe_metis_flag(
80 "m",
"exe_metis",
"Call mpmetis inside the programme via system().",
82 cmd.add(exe_metis_flag);
84 TCLAP::ValueArg<std::string> log_level_arg(
86 "the verbosity of logging messages: none, error, warn, info, debug, "
95 cmd.add(log_level_arg);
99 TCLAP::UnlabeledMultiArg<std::string> other_meshes_filenames_arg(
100 "other_meshes_filenames",
"mesh file names.",
false,
"file");
101 cmd.add(other_meshes_filenames_arg);
103 cmd.parse(argc, argv);
106 MPI_Init(&argc, &argv);
110 spdlog::set_pattern(
"%^%l:%$ %v");
111 spdlog::set_error_handler(
112 [](
const std::string& msg)
114 std::cerr <<
"spdlog error: " << msg << std::endl;
115 OGS_FATAL(
"spdlog logger error occurred.");
123 const std::string input_file_name_wo_extension =
125 std::unique_ptr<MeshLib::Mesh> mesh_ptr(
127 INFO(
"Mesh '{:s}' read: {:d} nodes, {:d} elements.",
129 mesh_ptr->getNumberOfNodes(),
130 mesh_ptr->getNumberOfElements());
133 output_directory_arg.getValue(),
136 if (ogs2metis_flag.getValue())
138 INFO(
"Write the mesh into METIS input file.");
140 output_file_name_wo_extension +
".mesh");
141 INFO(
"Total runtime: {:g} s.", run_timer.elapsed());
142 INFO(
"Total CPU time: {:g} s.", CPU_timer.
elapsed());
151 nparts.getValue(), std::move(mesh_ptr));
153 const int num_partitions = nparts.getValue();
155 if (num_partitions < 1)
157 OGS_FATAL(
"Number of partitions must be positive.");
160 if (num_partitions == 1)
163 "Partitioning the mesh into one domain is unnecessary because OGS "
164 "reads vtu mesh data directly when called with 'mpirun bin/ogs "
168 auto metis_mesh = output_file_name_wo_extension;
169 if (metis_mesh_input.getValue() !=
"")
171 metis_mesh = metis_mesh_input.getValue();
175 if (exe_metis_flag.getValue())
177 INFO(
"METIS is running ...");
178 const std::string exe_name = argv[0];
180 INFO(
"Path to mpmetis is: \n\t{:s}", exe_path);
182 const std::string mpmetis_com =
184 metis_mesh +
".mesh" +
"' " + std::to_string(nparts.getValue());
186 INFO(
"Running: {:s}", mpmetis_com);
187 const int status = system(mpmetis_com.c_str());
190 INFO(
"Failed in system calling.");
191 INFO(
"Return value of system call {:d} ", status);
203 if (exe_metis_flag.getValue())
208 INFO(
"Partitioning the mesh in the node wise way ...");
211 INFO(
"Partitioning other meshes according to the main mesh partitions.");
212 for (
auto const& filename : other_meshes_filenames_arg.getValue())
214 std::unique_ptr<MeshLib::Mesh> mesh(
216 INFO(
"Mesh '{:s}' from file '{:s}' read: {:d} nodes, {:d} elements.",
217 mesh->getName(), filename, mesh->getNumberOfNodes(),
218 mesh->getNumberOfElements());
220 std::string
const other_mesh_output_file_name_wo_extension =
222 output_directory_arg.getValue(),
228 partitioned_properties);
231 other_mesh_output_file_name_wo_extension, partitions,
232 partitioned_properties);
236 io_run_timer.
start();
237 mesh_partitioner.
write(output_file_name_wo_extension);
238 INFO(
"Writing the partitions data into binary files took {:g} s",
241 INFO(
"Total runtime: {:g} s.", run_timer.elapsed());
242 INFO(
"Total CPU time: {:g} s.", CPU_timer.
elapsed());