1 #ifndef UTOPIA_CORE_PARALLEL_HH
2 #define UTOPIA_CORE_PARALLEL_HH
5 #if defined(HAVE_ONEDPL)
6 #include <oneapi/dpl/execution>
7 #include <oneapi/dpl/algorithm>
8 #elif defined(USE_INTERNAL_PSTL)
13 #if defined(HAVE_ONEDPL) || defined(USE_INTERNAL_PSTL)
18 #if defined(HAVE_PSTL) && defined(ENABLE_PARALLEL_STL)
19 #define UTOPIA_PARALLEL
24 #if defined(HAVE_ONEDPL)
25 namespace std::execution {
26 using namespace oneapi::dpl::execution;
31 #define MAYBE_UNUSED [[maybe_unused]]
81 inline static bool _enabled =
false;
93 throw std::runtime_error(
"Cannot fetch core logger!");
115 bool setting =
false;
118 if (
const YAML::Node& cfg_par = cfg[
"parallel_execution"])
120 setting = get_as<bool>(
"enabled", cfg_par);
124 set(Setting::enabled);
126 set(Setting::disabled);
137 _enabled = (value == Setting::enabled);
139 const auto log = get_logger();
140 std::string msg = fmt::format(
"Parallel execution {}",
141 _enabled ?
"enabled" :
"disabled");
143 #ifdef UTOPIA_PARALLEL
146 msg +=
", but settings do NOT apply";
169 #ifdef UTOPIA_PARALLEL
203 template<
class Func,
class... Args>
209 #ifdef UTOPIA_PARALLEL
224 return f(std::forward_as_tuple(args...));
322 template<
class InputIt,
class OutputIt>
331 [](
auto&& args_tpl) {
332 auto copy = [](
auto&&... args){
return std::copy(args...); };
333 return std::apply(
copy, args_tpl);
344 template<
class InputIt,
class UnaryFunction>
353 [](
auto&& args_tpl) {
366 template<
class InputIt,
class OutputIt,
class UnaryOperation>
372 UnaryOperation unary_op)
376 [](
auto&& args_tpl) {
392 template<
class InputIt1,
class InputIt2,
class OutputIt,
class BinaryOperation>
399 BinaryOperation binary_op)
403 [](
auto&& args_tpl) {
Static information on the status of parallel execution.
Definition: parallel.hh:78
static bool is_enabled()
Query if parallel execution is currently enabled.
Definition: parallel.hh:160
static std::shared_ptr< spdlog::logger > get_logger()
Fetch the core logger.
Definition: parallel.hh:88
static bool is_applied()
Actually check if parallel features are applied at runtime.
Definition: parallel.hh:167
static void init(const DataIO::Config &cfg)
Initialize parallel features based on configuration setting.
Definition: parallel.hh:113
static void set(const Setting value)
Choose a setting for parallel execution at runtime.
Definition: parallel.hh:135
Setting
Possible settings for parallel execution.
Definition: parallel.hh:102
@ enabled
Enable parallel execution.
Definition: parallel.hh:103
OutputIt copy(const Utopia::ExecPolicy policy, InputIt first, InputIt last, OutputIt d_first)
Copy the input range to a new range.
Definition: parallel.hh:324
OutputIt transform(const Utopia::ExecPolicy policy, InputIt first1, InputIt last1, OutputIt d_first, UnaryOperation unary_op)
Apply a unary operator to a range and store the result in a new range.
Definition: parallel.hh:368
void for_each(const Utopia::ExecPolicy policy, InputIt first, InputIt last, UnaryFunction f)
Apply a function to a range.
Definition: parallel.hh:346
YAML::Node Config
Type of a variadic dictionary-like data structure used throughout Utopia.
Definition: types.hh:71
const std::string log_core
Definition: logging.hh:18
auto exec_parallel(MAYBE_UNUSED const Utopia::ExecPolicy policy, Func &&f, Args &&... args)
Call a function with an STL execution policy and arguments.
Definition: parallel.hh:205
ExecPolicy
Runtime execution policies.
Definition: parallel.hh:60
@ seq
Sequential (i.e., regular) execution.
Definition: parallel.hh:66
@ unseq
SIMD execution on single thread.
Definition: parallel.hh:67
@ par_unseq
SIMD execution on multiple threads.
Definition: parallel.hh:69
@ par
Parallel/multithreaded execution.
Definition: parallel.hh:68
Definition: parallel.hh:235
#define MAYBE_UNUSED
Definition: parallel.hh:31