17 #ifndef QMCPLUSPLUS_PARALLELEXECUTOR_OPENMP_HPP 18 #define QMCPLUSPLUS_PARALLELEXECUTOR_OPENMP_HPP 36 template<
typename F,
typename... Args>
39 const std::string nesting_error{
"ParallelExecutor should not be used for nested openmp threading\n"};
41 throw std::runtime_error(nesting_error);
42 int nested_throw_count = 0;
44 #pragma omp parallel for reduction(+ : nested_throw_count, throw_count) 45 for (
int task_id = 0; task_id < num_tasks; ++task_id)
49 f(task_id, std::forward<Args>(args)...);
51 catch (
const std::runtime_error& re)
53 if (nesting_error == re.what())
57 std::cerr << re.what() << std::flush;
67 throw std::runtime_error(
"Unexpected exception thrown in threaded section");
68 else if (nested_throw_count > 0)
69 throw std::runtime_error(nesting_error);
helper functions for EinsplineSetBuilder
void operator()(int num_tasks, F &&f, Args &&... args)
Concurrently execute an arbitrary function/kernel with task id and arbitrary args.
omp_int_t omp_get_level()