29int main(
int argc,
char* argv[])
32 "Partition a mesh for parallel computing."
33 "The tasks of this tool are in twofold:\n"
34 "1. Convert mesh file to the input file of the partitioning tool,\n"
35 "2. Partition a mesh using the partitioning tool,\n"
36 "\tcreate the mesh data of each partition,\n"
37 "\trenumber the node indices of each partition,\n"
38 "\tand output the results for parallel computing.\n"
39 "Note: If this tool is installed as a system command,\n"
40 "\tthe command must be run with its full path.\n\n"
41 "OpenGeoSys-6 software, version " +
44 "Copyright (c) 2012-2024, OpenGeoSys Community "
45 "(http://www.opengeosys.org)",
47 TCLAP::ValueArg<std::string> mesh_input(
48 "i",
"mesh-input-file",
49 "the name of the file containing the input mesh",
true,
"",
50 "file name of input mesh");
53 TCLAP::ValueArg<std::string> metis_mesh_input(
54 "x",
"metis-mesh-input-file",
55 "base name (without .mesh extension) of the file containing the metis "
58 "base name (without .mesh extension) of the file containing the metis "
60 cmd.add(metis_mesh_input);
62 TCLAP::ValueArg<std::string> output_directory_arg(
63 "o",
"output",
"directory name for the output files",
false,
"",
65 cmd.add(output_directory_arg);
67 TCLAP::ValueArg<int> nparts(
"n",
"np",
"the number of partitions",
false, 2,
71 TCLAP::SwitchArg ogs2metis_flag(
73 "Indicator to convert the ogs mesh file to METIS input file", cmd,
76 TCLAP::SwitchArg exe_metis_flag(
77 "m",
"exe_metis",
"Call mpmetis inside the programme via system().",
79 cmd.add(exe_metis_flag);
81 TCLAP::ValueArg<std::string> log_level_arg(
83 "the verbosity of logging messages: none, error, warn, info, debug, "
92 cmd.add(log_level_arg);
96 TCLAP::UnlabeledMultiArg<std::string> other_meshes_filenames_arg(
97 "other_meshes_filenames",
"mesh file names.",
false,
"file");
98 cmd.add(other_meshes_filenames_arg);
100 cmd.parse(argc, argv);
105 spdlog::set_pattern(
"%^%l:%$ %v");
106 spdlog::set_error_handler(
107 [](
const std::string& msg)
109 std::cerr <<
"spdlog error: " << msg << std::endl;
110 OGS_FATAL(
"spdlog logger error occurred.");
113 const auto output_directory = output_directory_arg.getValue();
121 const std::string input_file_name_wo_extension =
123 std::unique_ptr<MeshLib::Mesh> mesh_ptr(
125 INFO(
"Mesh '{:s}' read: {:d} nodes, {:d} elements.",
127 mesh_ptr->getNumberOfNodes(),
128 mesh_ptr->getNumberOfElements());
134 if (ogs2metis_flag.getValue())
136 INFO(
"Write the mesh into METIS input file.");
138 output_file_name_wo_extension +
".mesh");
139 INFO(
"Total runtime: {:g} s.", run_timer.
elapsed());
140 INFO(
"Total CPU time: {:g} s.", CPU_timer.
elapsed());
146 nparts.getValue(), std::move(mesh_ptr));
148 const int num_partitions = nparts.getValue();
150 if (num_partitions < 1)
152 OGS_FATAL(
"Number of partitions must be positive.");
155 if (num_partitions == 1)
158 "Partitioning the mesh into one domain is unnecessary because OGS "
159 "reads vtu mesh data directly when called with 'mpirun bin/ogs "
163 auto metis_mesh = output_file_name_wo_extension;
164 if (metis_mesh_input.getValue() !=
"")
166 metis_mesh = metis_mesh_input.getValue();
170 if (exe_metis_flag.getValue())
172 INFO(
"METIS is running ...");
173 const std::string exe_name = argv[0];
175 INFO(
"Path to mpmetis is: \n\t{:s}", exe_path);
177 const std::string mpmetis_com =
179 metis_mesh +
".mesh" +
"\" " + std::to_string(nparts.getValue());
181 INFO(
"Running: {:s}", mpmetis_com);
182 const int status = system(mpmetis_com.c_str());
185 INFO(
"Failed in system calling.");
186 INFO(
"Return value of system call {:d} ", status);
195 if (exe_metis_flag.getValue())
200 INFO(
"Partitioning the mesh in the node wise way ...");
203 INFO(
"Partitioning other meshes according to the main mesh partitions.");
204 for (
auto const& filename : other_meshes_filenames_arg.getValue())
206 std::unique_ptr<MeshLib::Mesh> mesh(
208 INFO(
"Mesh '{:s}' from file '{:s}' read: {:d} nodes, {:d} elements.",
209 mesh->getName(), filename, mesh->getNumberOfNodes(),
210 mesh->getNumberOfElements());
212 std::string
const other_mesh_output_file_name_wo_extension =
220 partitioned_properties);
223 other_mesh_output_file_name_wo_extension, partitions,
224 partitioned_properties);
228 io_run_timer.
start();
229 mesh_partitioner.
write(output_file_name_wo_extension);
230 INFO(
"Writing the partitions data into binary files took {:g} s",
233 INFO(
"Total runtime: {:g} s.", run_timer.
elapsed());
234 INFO(
"Total CPU time: {:g} s.", CPU_timer.
elapsed());