Skip to content

Commit 3b79adc

Browse files
Update argparse.cpp
1 parent 17f2883 commit 3b79adc

1 file changed

Lines changed: 36 additions & 10 deletions

File tree

argparse/argparse.cpp

Lines changed: 36 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,59 @@
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+
112
#include "argparse.hpp"
213
#include <iostream>
314
#include <stdexcept>
15+
#ifdef NEXT_MPI
16+
#include <mpi.h>
17+
#endif
418

519
namespace next {
620

7-
Arguments parse_arguments(int argc, char** argv)
21+
Arguments parse_arguments(int argc, char** argv, int rank)
822
{
923
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
1132
std::exit(1);
1233
}
1334

1435
Arguments args;
1536

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]);
1940
args.dump_interval = std::stod(argv[4]);
2041

2142
std::string fmt = argv[5];
2243

23-
if (fmt == "vtk")
44+
if (fmt == "vtk") {
2445
args.format = OutputFormat::VTK;
25-
else if (fmt == "vtu")
46+
} else if (fmt == "vtu") {
2647
args.format = OutputFormat::VTU;
27-
else if (fmt == "hdf5")
48+
} else if (fmt == "hdf5") {
2849
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
3157
std::exit(1);
3258
}
3359

0 commit comments

Comments
 (0)