1#ifndef FREE_TENSOR_OMP_UTILS_H
2#define FREE_TENSOR_OMP_UTILS_H
16template <std::
integral T>
18 const std::function<
void(T)> &body,
19 omp_sched_t schedKind,
20 int schedChunkSize = 0 ) {
21 std::atomic_flag hasExcept_ = ATOMIC_FLAG_INIT;
25 std::exception_ptr except_;
27 omp_set_schedule(schedKind, schedChunkSize);
33#pragma omp for schedule(runtime)
34 for (
auto i = begin; i < end; i += step) {
38 if (!hasExcept_.test_and_set()) {
39 except_ = std::current_exception();
43#pragma omp cancellation point for
47 std::rethrow_exception(except_);
Definition: allocator.h:9
void exceptSafeParallelFor(T begin, T end, T step, const std::function< void(T)> &body, omp_sched_t schedKind, int schedChunkSize=0)
Definition: omp_utils.h:17