Newer
Older
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
#include "Configuration.hpp"
#include <iostream>
#include <stdexcept>
#include "MpiEnvironment.hpp"
#include <boost/format.hpp>
#include <boost/program_options.hpp>
auto Configuration::parseArgs(int argc, char* argv[], const MpiEnvironment& env)
-> Configuration {
namespace po = boost::program_options;
Configuration cfg;
po::options_description desc{"Allowed options"};
desc.add_options()("help,h", "produce help message") //
("gridrows,r", po::value<std::size_t>(&cfg.GridRows)->required(),
"number of rows in the grid") //
("gridcols,c", po::value<std::size_t>(&cfg.GridColumns)->required(),
"number of columns in the grid") //
("file,f", po::value<std::string>(&cfg.InputFilePath)->required(),
"path to wireworld file"); //
po::variables_map vm;
po::store(po::parse_command_line(argc, argv, desc), vm);
if (vm.count("help") > 0 && env.isMaster()) { std::cout << desc << "\n"; }
po::notify(vm);
const auto& totalCellCount = cfg.GridColumns * cfg.GridRows;
const auto& worldSize = env.worldSize();
if (totalCellCount != worldSize) {
throw std::invalid_argument(
boost::str(boost::format("Total number of cells (%d) does not "
"match the MPI World size (%d)") %
totalCellCount % worldSize));
}
return cfg;
}