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
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
/**
* @file MpiUncertainty_main.cc
* @brief The MpiUncertainty BarbequeRTRM application
*
* Description: to be done...
*
* @author Radim Vavrik, radim.vavrik@vsb.cz
*
* Company VSB-TUO
* Copyright Copyright (c) 2015, VSB-TUO
*
* This source code is released for free distribution under the terms of the
* GNU General Public License as published by the Free Software Foundation.
* =====================================================================================
*/
#include <cstdio>
#include <iostream>
#include <random>
#include <cstring>
#include <memory>
#include <libgen.h>
#include <boost/program_options/options_description.hpp>
#include <boost/program_options/parsers.hpp>
#include <boost/program_options/variables_map.hpp>
#include "version.h"
#include "MpiUncertainty_exc.h"
#include <bbque/utils/utility.h>
#include <bbque/utils/logging/logger.h>
// Setup logging
#undef BBQUE_LOG_MODULE
#define BBQUE_LOG_MODULE "MpiUncertainty"
namespace bu = bbque::utils;
namespace po = boost::program_options;
/**
* @brief A pointer to an EXC
*/
std::unique_ptr<bu::Logger> logger;
/**
* @brief A pointer to an EXC
*/
typedef std::shared_ptr<BbqueEXC> pBbqueEXC_t;
/**
* The decription of each MpiUncertainty parameters
*/
po::options_description opts_desc("MpiUncertainty Configuration Options");
/**
* The map of all MpiUncertainty parameters values
*/
po::variables_map opts_vm;
/**
* The services exported by the RTLib
*/
RTLIB_Services_t *rtlib;
/**
* @brief The application configuration file
*/
std::string conf_file = BBQUE_PATH_PREFIX "/" BBQUE_PATH_CONF "/MpiUncertainty.conf" ;
/**
* @brief The recipe to use for all the EXCs
*/
std::string recipe;
/**
* @brief The EXecution Context (EXC) registered
*/
pBbqueEXC_t pexc;
std::string uncertainty_config_xml_path = BBQUE_PATH_PREFIX "/../contrib/user/MpiUncertainty/data/config.xml";
void ParseCommandLine(int argc, char *argv[]) {
// Parse command line params
try {
po::store(po::parse_command_line(argc, argv, opts_desc), opts_vm);
} catch(...) {
std::cout << "Usage: " << argv[0] << " [options]\n";
std::cout << opts_desc << std::endl;
::exit(EXIT_FAILURE);
}
po::notify(opts_vm);
// Check for help request
if (opts_vm.count("help")) {
std::cout << "Usage: " << argv[0] << " [options]\n";
std::cout << opts_desc << std::endl;
::exit(EXIT_SUCCESS);
}
// Check for version request
if (opts_vm.count("version")) {
std::cout << "MpiUncertainty (ver. " << g_git_version << ")\n";
std::cout << "Copyright (C) 2011 Politecnico di Milano\n";
std::cout << "\n";
std::cout << "Built on " <<
__DATE__ << " " <<
__TIME__ << "\n";
std::cout << "\n";
std::cout << "This is free software; see the source for "
"copying conditions. There is NO\n";
std::cout << "warranty; not even for MERCHANTABILITY or "
"FITNESS FOR A PARTICULAR PURPOSE.";
std::cout << "\n" << std::endl;
::exit(EXIT_SUCCESS);
}
}
int main(int argc, char *argv[]) {
opts_desc.add_options()
("help,h", "print this help message")
("version,v", "print program version")
("conf,C", po::value<std::string>(&conf_file)->
default_value(conf_file),
"MpiUncertainty BBQUE configuration file")
("unconf,u", po::value<std::string>(&uncertainty_config_xml_path)->
default_value(uncertainty_config_xml_path),
"Uncertainty configuration file")
("recipe,r", po::value<std::string>(&recipe)->
default_value("MpiUncertainty"),
"recipe name (for all EXCs)")
;
// Setup a logger
bu::Logger::SetConfigurationFile(conf_file);
logger = bu::Logger::GetLogger("mpiuncertainty");
ParseCommandLine(argc, argv);
// Welcome screen
logger->Info(".:: MpiUncertainty (ver. %s) ::.", g_git_version);
logger->Info("Built: " __DATE__ " " __TIME__);
// Initializing the RTLib library and setup the communication channel
// with the Barbeque RTRM
logger->Info("STEP 0. Initializing RTLib, application [%s]...",
::basename(argv[0]));
RTLIB_Init(::basename(argv[0]), &rtlib);
assert(rtlib);
logger->Info("STEP 1. Registering EXC using [%s] recipe...",
recipe.c_str());
pexc = pBbqueEXC_t(new MpiUncertainty("MpiUncertainty", uncertainty_config_xml_path, recipe, rtlib));
if (!pexc->isRegistered())
return RTLIB_ERROR;
logger->Info("STEP 2. Starting EXC control thread...");
pexc->Start();
logger->Info("STEP 3. Waiting for EXC completion...");
pexc->WaitCompletion();
logger->Info("STEP 4. Disabling EXC...");
pexc = NULL;
logger->Info("===== MpiUncertainty DONE! =====");
return EXIT_SUCCESS;
}