Visual Computing Library  devel
Loading...
Searching...
No Matches
parallel.h
1/*****************************************************************************
2 * VCLib *
3 * Visual Computing Library *
4 * *
5 * Copyright(C) 2021-2025 *
6 * Visual Computing Lab *
7 * ISTI - Italian National Research Council *
8 * *
9 * All rights reserved. *
10 * *
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the Mozilla Public License Version 2.0 as published *
13 * by the Mozilla Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
15 * *
16 * This program is distributed in the hope that it will be useful, *
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
19 * Mozilla Public License Version 2.0 *
20 * (https://www.mozilla.org/en-US/MPL/2.0/) for more details. *
21 ****************************************************************************/
22
23#ifndef VCL_BASE_PARALLEL_H
24#define VCL_BASE_PARALLEL_H
25
26#include <vclib/base/concepts/range.h>
27
28// tbb and qt conflicts: if both are linked, we need to first undef Qt's
29// emit - see: https://github.com/oneapi-src/oneTBB/issues/547
30#if defined(emit)
31#undef emit
32#define VCLIB_EMIT_REDEFINED
33#endif // emit
34
35// Hack to compensate lack of support for c++17 parallel algorithms by
36// several compilers. We use poolSTL.
37#define POOLSTL_STD_SUPPLEMENT
38#if __has_include(<poolstl/poolstl.hpp>)
39#include <poolstl/poolstl.hpp>
40#else
41#include "../../../external/poolSTL-0.3.5/include/poolstl/poolstl.hpp"
42#endif
43
44// Restore the definition of "emit" if it was defined before
45#ifdef VCLIB_EMIT_REDEFINED
46#undef VCLIB_EMIT_REDEFINED
47#define emit // restore the macro definition of "emit", as it was
48 // defined in gtmetamacros.h
49#endif // VCLIB_EMIT_REDEFINED
50
51#include <algorithm>
52
53namespace vcl {
54
73template<typename Iterator, typename Lambda>
74void parallelFor(Iterator&& begin, Iterator&& end, Lambda&& F)
75{
76 std::for_each(std::execution::par, begin, end, F);
77}
78
94template<Range Rng, typename Lambda>
95void parallelFor(Rng&& r, Lambda&& F)
96{
97 parallelFor(std::ranges::begin(r), std::ranges::end(r), F);
98}
99
100} // namespace vcl
101
102#endif // VCL_BASE_PARALLEL_H