|
| 1 | +// This program is free software: you can redistribute it and/or modify |
| 2 | +// it under the terms of the GNU General Public License as published by |
| 3 | +// the Free Software Foundation, either version 3 of the License, or |
| 4 | +// (at your option) any later version. |
| 5 | +// This program is distributed in the hope that it will be useful, |
| 6 | +// but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 7 | +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 8 | +// GNU General Public License for more details. |
| 9 | +// You should have received a copy of the GNU General Public License |
| 10 | +// along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 11 | + |
1 | 12 | #include "argparse.hpp" |
2 | 13 | #include <iostream> |
3 | 14 | #include <stdexcept> |
| 15 | +#ifdef NEXT_MPI |
| 16 | + #include <mpi.h> |
| 17 | +#endif |
4 | 18 |
|
5 | 19 | namespace next { |
6 | 20 |
|
7 | | -Arguments parse_arguments(int argc, char** argv) |
| 21 | +Arguments parse_arguments(int argc, char** argv, int rank) |
8 | 22 | { |
9 | 23 | if (argc != 6) { |
10 | | - std::cerr << "Usage: next <input.txt> <threads> <dt> <dump_interval> <vtk|vtu|hdf5>\n"; |
| 24 | + // Only rank 0 prints usage |
| 25 | + if (rank == 0) { |
| 26 | + std::cerr << "Usage: next <input.txt> <threads> <dt> <dump_interval> <vtk|vtu|hdf5>\n"; |
| 27 | + } |
| 28 | + |
| 29 | +#ifdef NEXT_MPI |
| 30 | + MPI_Finalize(); |
| 31 | +#endif |
11 | 32 | std::exit(1); |
12 | 33 | } |
13 | 34 |
|
14 | 35 | Arguments args; |
15 | 36 |
|
16 | | - args.input_file = argv[1]; |
17 | | - args.threads = std::stoi(argv[2]); |
18 | | - args.dt = std::stod(argv[3]); |
| 37 | + args.input_file = argv[1]; |
| 38 | + args.threads = std::stoi(argv[2]); |
| 39 | + args.dt = std::stod(argv[3]); |
19 | 40 | args.dump_interval = std::stod(argv[4]); |
20 | 41 |
|
21 | 42 | std::string fmt = argv[5]; |
22 | 43 |
|
23 | | - if (fmt == "vtk") |
| 44 | + if (fmt == "vtk") { |
24 | 45 | args.format = OutputFormat::VTK; |
25 | | - else if (fmt == "vtu") |
| 46 | + } else if (fmt == "vtu") { |
26 | 47 | args.format = OutputFormat::VTU; |
27 | | - else if (fmt == "hdf5") |
| 48 | + } else if (fmt == "hdf5") { |
28 | 49 | args.format = OutputFormat::HDF5; |
29 | | - else { |
30 | | - std::cerr << "Choose a file format: vtk, vtu, or hdf5\n"; |
| 50 | + } else { |
| 51 | + if (rank == 0) { |
| 52 | + std::cerr << "Choose a file format: vtk, vtu, or hdf5\n"; |
| 53 | + } |
| 54 | +#ifdef NEXT_MPI |
| 55 | + MPI_Finalize(); |
| 56 | +#endif |
31 | 57 | std::exit(1); |
32 | 58 | } |
33 | 59 |
|
|
0 commit comments