-
Notifications
You must be signed in to change notification settings - Fork 2
/
parse_commandline.cc
154 lines (145 loc) · 6.32 KB
/
parse_commandline.cc
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
142
143
144
145
146
147
148
149
150
151
152
153
154
// parse_commandline.cc
/**
* @file parse_commandline.cc
* @author Simone Romiti ([email protected])
* @brief definitions of parse_commandline.hh
* @version 0.1
* @date 2022-05-04
*
* @copyright Copyright (c) 2022
*
*/
#include<iostream>
#include<string>
#include<boost/program_options.hpp>
#include"parse_commandline.hh"
#include"print_program_options.hh"
namespace po = boost::program_options;
void add_general_options(po::options_description &desc, general_params ¶ms) {
desc.add_options()
("help,h", "produce this help message")
("spatialsizex,X", po::value<size_t>(¶ms.Lx), "spatial lattice size x > 0")
("spatialsizey,Y", po::value<size_t>(¶ms.Ly), "spatial lattice size y > 0")
("spatialsizez,Z", po::value<size_t>(¶ms.Lz), "spatial lattice size z > 0")
("temporalsize,T", po::value<size_t>(¶ms.Lt), "temporal lattice size > 0")
("ndims", po::value<size_t>(¶ms.ndims), "number of dimensions, 2 <= ndims <= 4")
("nsave", po::value<size_t>(¶ms.N_save)->default_value(1000), "N_save")
("n_meas,n", po::value<size_t>(¶ms.n_meas)->default_value(10), "total number of sweeps")
("counter", po::value<size_t>(¶ms.icounter)->default_value(0), "initial counter for updates")
("beta,b", po::value<double>(¶ms.beta), "beta value")
("mass,m", po::value<double>(¶ms.m0), "bare quark mass")
("seed,s", po::value<size_t>(¶ms.seed)->default_value(13526463), "PRNG seed")
("heat", po::value<double>(¶ms.heat)->default_value(1.), "randomness of the initial config, 1: hot, 0: cold")
("restart", "restart from an existing configuration")
("configname", po::value< std::string >(¶ms.configfilename), "configuration filename used in case of restart")
("xi", po::value<double>(¶ms.xi)->default_value(1.0), "xi, characteristic of anisotropy")
("anisotropic", po::value<bool>(¶ms.anisotropic)->default_value(false), "set whether the configurations are anisotropic")
;
return;
}
int parse_commandline(int ac, char * av[], po::options_description &desc, general_params ¶ms) {
try {
po::variables_map vm;
po::store(po::parse_command_line(ac, av, desc), vm);
po::notify(vm);
params.restart = false;
params.acceptreject = true;
if (vm.count("help")) {
std::cout << desc << std::endl;
return 1;
}
if (!vm.count("spatialsizex") && !vm.count("help")) {
std::cerr << "spatial lattice x-size must be given!" << std::endl;
std::cout << std::endl << desc << std::endl;
return 1;
}
if (!vm.count("spatialsizey") && !vm.count("help")) {
std::cerr << "spatial lattice y-size must be given!" << std::endl;
std::cout << std::endl << desc << std::endl;
return 1;
}
if (!vm.count("spatialsizez") && !vm.count("help")) {
std::cerr << "spatial lattice z-size must be given!" << std::endl;
std::cout << std::endl << desc << std::endl;
return 1;
}
if (!vm.count("temporalsize") && !vm.count("help")) {
std::cerr << "temporal lattice size must be given!" << std::endl;
std::cout << std::endl << desc << std::endl;
return 1;
}
if (!vm.count("beta") && !vm.count("help")) {
std::cerr << "beta value must be specified!" << std::endl;
std::cout << std::endl << desc << std::endl;
return 1;
}
if (vm.count("restart")) {
if(!vm.count("configname")) {
std::cerr << "for a restart the configuration filename must be specified!" << std::endl;
std::cout << std::endl << desc << std::endl;
return 1;
}
params.restart = true;
}
if (vm.count("no-accept-reject")) {
params.acceptreject = false;
}
if (!vm.count("ndims")) {
params.ndims = 4;
}
if (params.ndims > 4 || params.ndims < 2) {
std::cerr << "2 <= ndims <= 4!" << std::endl;
std::cout << std::endl << desc << std::endl;
return 1;
}
if (params.Lx < 1 || params.Ly < 1 || params.Lz < 1 || params.Lt < 1) {
std::cerr << "All box extends must be > 1!" << std::endl;
std::cout << std::endl << desc << std::endl;
return 1;
}
if (params.ndims == 2) {
params.Ly = 1;
params.Lz = 1;
}
if (params.ndims == 3) {
params.Lz = 1;
}
if (params.xi != 1.0 && params.anisotropic == false) {
std::cerr << "anisotropy parameter xi != 1, but flag anisotropic is set to false. Programm will continue without anisotropy." << std::endl;
}
PrintVariableMap(vm);
}
catch(std::exception& e) {
std::cerr << "error: " << e.what() << "\n";
return 1;
}
catch(...) {
std::cerr << "Exception of unknown type!\n";
}
return(0);
}
int parse_command_line_and_init(int ac, char *av[], general_params& gparams, hmc_u1_params& hparams) {
po::options_description desc("Allowed options");
add_general_options(desc, gparams);
// add HMC specific options
desc.add_options()("nrev", po::value<size_t>(&hparams.N_rev)->default_value(0),
"frequenz of reversibility tests N_rev, 0: not reversibility test")(
"nsteps", po::value<size_t>(&hparams.n_steps)->default_value(1000), "n_steps")(
"tau", po::value<double>(&hparams.tau)->default_value(1.), "trajectory length tau")(
"exponent", po::value<size_t>(&hparams.exponent)->default_value(0),
"exponent for rounding")("integrator", po::value<size_t>(&hparams.integs)->default_value(0),
"itegration scheme to be used: 0=leapfrog, 1=lp_leapfrog, "
"2=omf4, 3=lp_omf4, 4=Euler, 5=RUTH, 6=omf2")(
"no_fermions", po::value<bool>(&hparams.no_fermions)->default_value(0),
"Bool flag indicating if we're ignoring the fermionic action.")(
"solver", po::value<std::string>(&hparams.solver)->default_value("CG"),
"Type of solver: CG, BiCGStab")(
"tolerace_cg", po::value<double>(&hparams.tolerance_cg)->default_value(1e-10),
"Tolerance for the solver for the dirac operator")(
"solver_verbosity", po::value<size_t>(&hparams.solver_verbosity)->default_value(0),
"Verbosity for the solver for the dirac operator")(
"seed_pf", po::value<size_t>(&hparams.seed_pf)->default_value(97234719),
"Seed for the evaluation of the fermion determinant")(
"outdir", po::value<std::string>(&hparams.outdir)->default_value("."), "Output directory");
return parse_commandline(ac, av, desc, gparams);
}