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)
25namespace std::execution {
26 using namespace oneapi::dpl::execution;
31#define MAYBE_UNUSED [[maybe_unused]]
93 throw std::runtime_error(
"Cannot fetch core logger!");
118 if (
const YAML::Node&
cfg_par = cfg[
"parallel_execution"])
140 std::string
msg = fmt::format(
"Parallel execution {}",
143#ifdef UTOPIA_PARALLEL
146 msg +=
", but settings do NOT apply";
169#ifdef UTOPIA_PARALLEL
209#ifdef UTOPIA_PARALLEL
213 return f(std::forward_as_tuple(std::execution::unseq,
args...));
215 return f(std::forward_as_tuple(std::execution::par,
args...));
217 return f(std::forward_as_tuple(std::execution::par_unseq,
args...));
222 return f(std::forward_as_tuple(std::execution::seq,
args...));
224 return f(std::forward_as_tuple(
args...));
322template<
class InputIt,
class OutputIt>
331 [](
auto&& args_tpl) {
332 auto copy = [](
auto&&... args){
return std::copy(args...); };
333 return std::apply(
copy, args_tpl);
344template<
class InputIt,
class UnaryFunction>
353 [](
auto&& args_tpl) {
366template<
class InputIt,
class OutputIt,
class UnaryOperation>
372 UnaryOperation unary_op)
376 [](
auto&& args_tpl) {
392template<
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 bool _enabled
Runtime setting for parallel execution.
Definition parallel.hh:81
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
@ disabled
Disable parallel execution.
Definition parallel.hh:104
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
Container select_entities(const Manager &mngr, const DataIO::Config &sel_cfg)
Select entities according to parameters specified in a configuration.
Definition select.hh:213
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