This repository has been archived by the owner on Feb 19, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
CmdLineParser.hpp
141 lines (123 loc) · 3.29 KB
/
CmdLineParser.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
#ifndef CMD_LINE_PARSER_H
#define CMD_LINE_PARSER_H
#include <cstdio>
#include <cstdlib>
#include <unistd.h>
class CmdLineParser {
public:
long ng1, ng2, ng3;
int np1, np2, np3;
int samples;
double tolerance;
int maxiter;
int solver_mode;
bool ignore_solver_errors;
bool dont_enable_fp_exceptions;
char *progname;
char *validate_solver_h5_file;
char *validate_estimator_h5_file;
CmdLineParser(int argc, char * argv[]) {
char *ng_buf;
char *np_buf;
char *samples_buf;
char *tol_buf;
char *maxiter_buf;
char *bcg_mode_buf;
ignore_solver_errors = false;
dont_enable_fp_exceptions = false;
progname = argv[0];
ng_buf = np_buf = samples_buf = tol_buf = maxiter_buf = bcg_mode_buf = 00;
validate_solver_h5_file = 00;
validate_estimator_h5_file = 00;
int c;
while ((c = getopt (argc, argv, "g:p:s:e:m:if:FV:E:")) != -1) {
switch (c)
{
case 'g':
ng_buf = optarg;
break;
case 'p':
np_buf = optarg;
break;
case 's':
samples_buf = optarg;
break;
case 'e':
tol_buf = optarg;
break;
case 'm':
maxiter_buf = optarg;
break;
case 'i':
ignore_solver_errors = true;
break;
case 'f':
bcg_mode_buf = optarg;
break;
case 'F':
dont_enable_fp_exceptions = true;
break;
case 'V':
validate_solver_h5_file = optarg;
break;
case 'E':
validate_estimator_h5_file = optarg;
break;
default:
usage();
}
}
if (ng_buf != 00) {
int nread = sscanf(ng_buf, "%ldx%ldx%ld", &ng1, &ng2, &ng3);
if (nread != 3) usage();
} else {
usage();
}
if (np_buf != 00) {
int nread = sscanf(np_buf, "%dx%dx%d", &np1, &np2, &np3);
if (nread != 3) usage();
} else {
usage();
}
if (samples_buf != 00) {
int nread = sscanf(samples_buf, "%d", &samples);
if (nread != 1) usage();
} else {
samples = 400;
}
if (tol_buf != 00) {
int nread = sscanf(tol_buf, "%lf", &tolerance);
if (nread != 1) usage();
} else {
tolerance = 1e-4;
}
if (maxiter_buf != 00) {
int nread = sscanf(maxiter_buf, "%d", &maxiter);
if (nread != 1) usage();
} else {
maxiter = 1000;
}
if (bcg_mode_buf != 00) {
int nread = sscanf(bcg_mode_buf, "%d", &solver_mode);
if (nread != 1) usage();
} else {
solver_mode = 0; // Default behavior for solver
}
}
private:
void usage() {
fprintf(stderr, "Usage: %s -g NxNxN -p NxNxN [-t NxNxN] [-s NSAMPLES] [-e TOL] [-m MAXITER] [-S]\n", progname);
fprintf(stderr, "\t-g NxNxN : size of the global 3D grid\n");
fprintf(stderr, "\t-p NxNxN : decomposition into ranks\n");
fprintf(stderr, "\t-s NSAMPLES : number of samples for stochastic estimation\n");
fprintf(stderr, "\t-e TOL : solver tolerance\n");
fprintf(stderr, "\t-m MAXITER : solver maximum iterations\n");
fprintf(stderr, "\t-i : ignore solver convergence errors and keep going\n");
fprintf(stderr, "\t-f : [advanced] flag for solver operation mode, see e.g. BiCgStab::mode_t\n");
fprintf(stderr, "\t-F : don't enable floating point exceptions (keep going if FPE occurs) [Linux only]\n");
fprintf(stderr, "\t-V HDF5_FILE : enable solver validation mode against HDF5 archive [requires HDF5]\n");
fprintf(stderr, "\t-E HDF5_FILE : enable estimator validation mode against HDF5 archive [requires HDF5]\n");
exit(1);
}
};
#endif