18 #if !defined(__FLECSI_PRIVATE__) 19 #define __FLECSI_PRIVATE__ 22 #include <boost/optional.hpp> 23 #include <boost/optional/optional_io.hpp> 24 #include <boost/program_options.hpp> 25 #include <boost/smart_ptr/make_shared.hpp> 55 initialize(
int argc,
char ** argv,
bool dependent =
true) {
56 return run::context::instance().initialize(argc, argv, dependent);
69 start(
const std::function<
int()> & action) {
70 return run::context::instance().start(action);
81 run::context::instance().finalize();
84 enum option_attribute :
size_t {
95 using any = boost::any;
103 template<
typename ValueType>
106 return boost::any_cast<boost::optional<ValueType>>(v).value();
116 template<
typename ValueType>
120 :
public std::pair<option_attribute, boost::optional<ValueType>> {
123 flog_assert(key == option_zero || key == option_multi,
124 "invalid constructor for initializer_value: " 125 << (key == option_default ?
"option_default" :
"option_implicit")
126 <<
" must take a value");
129 : initializer_value::pair(key, value) {
130 flog_assert(key == option_default || key == option_implicit,
131 "invalid constructor for initializer_value: " 132 << (key == option_zero ?
"option_zero" :
"option_multi")
133 <<
" does not take a value");
175 std::initializer_list<initializer_value> values = {},
176 std::function<bool(const any &)>
const & check = default_check) {
178 auto semantic_ = boost::program_options::value(&value_);
180 bool zero{
false}, implicit{
false};
181 for(
auto const & v : values) {
182 if(v.first == option_default) {
183 semantic_->default_value(v.second);
185 else if(v.first == option_implicit) {
186 semantic_->implicit_value(v.second);
189 else if(v.first == option_zero) {
190 semantic_->zero_tokens();
193 else if(v.first == option_multi) {
194 semantic_->multitoken();
202 flog_assert(implicit,
"option_zero specified without option_implicit");
206 boost::make_shared<boost::program_options::option_description>(
207 flag, semantic_, help);
209 run::context::instance()
211 .try_emplace(section, section)
212 .first->second.add(option);
214 std::string sflag(flag);
215 sflag = sflag.substr(0, sflag.find(
','));
217 run::context::instance().option_checks().try_emplace(sflag,
false, check);
235 std::function<
bool(
const any &)>
const & check = default_check) {
236 auto semantic_ = boost::program_options::value(&value_);
237 semantic_->required();
240 boost::make_shared<boost::program_options::option_description>(
241 name, semantic_, help);
243 auto & c = run::context::instance();
244 c.positional_description().add(name, count);
245 c.positional_help().try_emplace(name, help);
246 c.hidden_options().add(option);
247 c.option_checks().try_emplace(name,
true, check);
250 ValueType value()
const {
251 return value_.value();
254 operator ValueType()
const {
258 bool has_value()
const {
259 return value_.has_value();
263 static bool default_check(
const boost::any &) {
267 boost::optional<ValueType> value_{};
275 inline std::string
const &
277 return run::context::instance().program();
286 return run::context::instance().process();
295 return run::context::instance().processes();
304 return run::context::instance().threads_per_process();
317 return run::context::instance().threads();
327 return run::context::instance().color();
337 return run::context::instance().colors();
350 template<
auto & TASK,
352 class REDUCTION_OPERATION,
355 decltype(
auto)
reduce(ARGS &&... args);
377 template<
auto & TASK,
379 size_t ATTRIBUTES = flecsi::loc | flecsi::leaf,
383 return reduce<TASK, LAUNCH_DOMAIN, void, ATTRIBUTES>(
384 std::forward<ARGS>(args)...);
406 template<
auto & TASK,
408 size_t ATTRIBUTES = flecsi::loc | flecsi::leaf,
412 return reduce<TASK, LAUNCH_DOMAIN, exec::fold::sum<int>, ATTRIBUTES>(
413 std::forward<ARGS>(args)...)
int test(ARGS &&... args)
Definition: execution.hh:411
size_t threads_per_process()
Definition: execution.hh:303
program_option(const char *name, const char *help, size_t count, std::function< bool(const any &)> const &check=default_check)
Definition: execution.hh:232
ValueType option_value(any const &v)
Definition: execution.hh:105
std::string const & program()
Definition: execution.hh:276
decltype(auto) execute(ARGS &&... args)
Definition: execution.hh:382
decltype(auto) reduce(ARGS &&... args)
Definition: policy.hh:90
#define flog_assert(test, message)
Definition: flog.hh:411
int start(const std::function< int()> &action)
Definition: execution.hh:69
Definition: execution.hh:117
program_option(const char *section, const char *flag, const char *help, std::initializer_list< initializer_value > values={}, std::function< bool(const any &)> const &check=default_check)
Definition: execution.hh:172
#define flog_fatal(message)
Definition: flog.hh:358
size_t processes()
Definition: execution.hh:294
int initialize(int argc, char **argv, bool dependent=true)
Definition: execution.hh:55
size_t process()
Definition: execution.hh:285
void finalize()
Definition: execution.hh:80
A launch domain with a static identity but a runtime size.
Definition: launch.hh:62
size_t color()
Definition: execution.hh:326
size_t colors()
Definition: execution.hh:336
Definition: execution.hh:119
size_t threads()
Definition: execution.hh:316
Definition: control.hh:31