-
Notifications
You must be signed in to change notification settings - Fork 1
/
ProgramOptions.cpp
235 lines (207 loc) · 5.46 KB
/
ProgramOptions.cpp
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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
/**
* @file ProgramOptions.cpp
* @brief Implementation of functionality for parsing command line options.
* @author Ankit Srivastava <[email protected]>
*
* Copyright 2020 Georgia Institute of Technology
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "ProgramOptions.hpp"
#include <boost/filesystem.hpp>
#include <iostream>
namespace fs = boost::filesystem;
ProgramOptions::ProgramOptions(
) : m_desc("Parallel Construction of Module Networks"),
m_logLevel(),
m_logFile(),
m_dataFile(),
m_algoName(),
m_outputDir(),
m_configFile(),
m_numVars(),
m_numObs(),
m_separator(),
m_parallelRead(),
m_colObs(),
m_varNames(),
m_obsIndices(),
m_learnNetwork(),
m_forceParallel(),
m_hostNames(),
m_warmupMPI()
{
po::options_description basic("Basic options");
basic.add_options()
("help,h", "Print this message")
("nvars,n", po::value<uint32_t>(&m_numVars), "Number of variables in the dataset")
("nobs,m", po::value<uint32_t>(&m_numObs), "Number of observations in the dataset")
("file,f", po::value<std::string>(&m_dataFile), "Name of the file from which dataset is to be read")
("readpar,r", po::bool_switch(&m_parallelRead)->default_value(false), "Read from the file in parallel")
("colobs,c", po::bool_switch(&m_colObs)->default_value(false), "The file contains observations in columns")
("separator,s", po::value<char>(&m_separator)->default_value(','), "Delimiting character in the file")
("varnames,v", po::bool_switch(&m_varNames)->default_value(false), "The file contains variable names")
("indices,i", po::bool_switch(&m_obsIndices)->default_value(false), "The file contains observation indices")
("algorithm,a", po::value<std::string>(&m_algoName)->default_value("lemontree"), "Name of the algorithm to be used")
("outdir,o", po::value<std::string>(&m_outputDir)->default_value("."), "Name of the directory to which the output files should be written")
;
po::options_description advanced("Advanced options");
advanced.add_options()
("config,g", po::value<std::string>(&m_configFile)->default_value(""), "JSON file with algorithm specific configurations")
("warmup,w", po::bool_switch(&m_warmupMPI)->default_value(false), "Warmup the MPI_Alltoall(v) functions before starting execution")
;
po::options_description developer("Developer options");
developer.add_options()
("parallel", po::bool_switch(&m_forceParallel)->default_value(false), "Use the parallel implementation even for p=1")
("hostnames", po::bool_switch(&m_hostNames)->default_value(false), "Print out the hostname for every process")
#ifdef LOGGING
("loglevel", po::value<std::string>(&m_logLevel)->default_value("error"), "Level of logging")
("logfile", po::value<std::string>(&m_logFile)->default_value(""), "File to which logs should be written")
#endif
;
m_desc.add(basic).add(advanced).add(developer);
}
void
ProgramOptions::parse(
int argc,
char** argv
)
{
po::variables_map vm;
po::store(po::parse_command_line(argc, argv, m_desc), vm);
po::notify(vm);
if ((argc == 1) || (vm.count("help") > 0)) {
std::stringstream ss;
ss << m_desc;
throw po::error(ss.str());
}
if (!fs::exists(fs::path(m_dataFile))) {
throw po::error("Couldn't find the data file");
}
if ((vm.count("nvars") == 0) || (vm.count("nobs") == 0)) {
throw po::error("Dimensions of the data file should be provided using -n and -m");
}
if (m_configFile.empty()) {
m_configFile = m_algoName + "_configs.json";
std::cerr << "Using the default configuration file for the algorithm: " << m_configFile << std::endl;
}
if (!fs::exists(fs::path(m_configFile))) {
throw po::error("Couldn't find the algorithm configuration file");
}
}
uint32_t
ProgramOptions::numVars(
) const
{
return m_numVars;
}
uint32_t
ProgramOptions::numObs(
) const
{
return m_numObs;
}
const std::string&
ProgramOptions::dataFile(
) const
{
return m_dataFile;
}
bool
ProgramOptions::parallelRead(
) const
{
return m_parallelRead;
}
bool
ProgramOptions::colObs(
) const
{
return m_colObs;
}
bool
ProgramOptions::varNames(
) const
{
return m_varNames;
}
bool
ProgramOptions::obsIndices(
) const
{
return m_obsIndices;
}
char
ProgramOptions::separator(
) const
{
return m_separator;
}
const std::string&
ProgramOptions::algoName(
) const
{
return m_algoName;
}
bool
ProgramOptions::learnNetwork(
) const
{
return m_learnNetwork;
}
const std::string&
ProgramOptions::outputDir(
) const
{
return m_outputDir;
}
const std::string&
ProgramOptions::configFile(
) const
{
return m_configFile;
}
bool
ProgramOptions::forceParallel(
) const
{
return m_forceParallel;
}
bool
ProgramOptions::hostNames(
) const
{
return m_hostNames;
}
bool
ProgramOptions::warmupMPI(
) const
{
return m_warmupMPI;
}
const std::string&
ProgramOptions::logLevel(
) const
{
return m_logLevel;
}
const std::string&
ProgramOptions::logFile(
) const
{
return m_logFile;
}
ProgramOptions::~ProgramOptions(
)
{
}