Skip to content

Commit 44142ad

Browse files
authored
Implemented parallel algorithms for C++17 on Windows and Linux (#17)
* fixed #ifdef INVOCABLE * for_each_parallel * map_parallel * added TBB (Intel Thread Building Blocks) for linux * added TBB linker flag for Linux * changed CMakeLists for tbb again * added filter_parallel * added all_of, any_of, none_of (parallel versions) * added sort and all variants in parallel * build error in Linux * fixed compiler flag for Windows, so that __cplusplus returns the correct value * fixed Windows compilation for parallel algorithms * replaced std::is_invocable_r<>::value with std::is_invocable_r_v * more occurences of std::is_invocable_r<>::value * documentation * suppressed warnings in test for Windows * fixed wrong preprocessor check for execution include
1 parent a6caaf1 commit 44142ad

File tree

7 files changed

+445
-15
lines changed

7 files changed

+445
-15
lines changed

.github/workflows/cmake.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ jobs:
9191
if: startsWith(matrix.config.name, 'Ubuntu Latest GCC')
9292
run: |
9393
sudo apt-get update
94-
sudo apt-get install ninja-build cmake
94+
sudo apt-get install ninja-build cmake libtbb-dev
9595
ninja --version
9696
cmake --version
9797
gcc --version
@@ -158,4 +158,4 @@ jobs:
158158
cmd="./build/tests/unit_tests"
159159
$cmd
160160
status=$?
161-
[ $status -eq 0 ] && exit 0 || exit 1
161+
[ $status -eq 0 ] && exit 0 || exit 1

CMakeLists.txt

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,13 @@ if(CMAKE_HOST_UNIX)
2626
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -w -Wshadow -Wunused -Woverloaded-virtual -Wnon-virtual-dtor -Werror")
2727
else()
2828
set(CMAKE_CONFIGURATION_TYPES "Debug;Release")
29-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /Ox /Ob2 /Oi /Ot /Oy /GT /GL /W4")
30-
set(CMAKE_SHARED_LINKER_FLAGS_RELEASE "${CMAKE_SHARED_LINKER_FLAGS_RELEASE} /OPT:REF /OPT:ICF /INCREMENTAL:NO" )
31-
set(CMAKE_SHARED_LINKER_FLAGS_DEBUG "${CMAKE_SHARED_LINKER_FLAGS_DEBUG} /INCREMENTAL:NO" )
29+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /Ox /Ob2 /Oi /Ot /Oy /GT /GL /W4 /Zc:__cplusplus")
30+
31+
set(CMAKE_SHARED_LINKER_FLAGS_RELEASE "${CMAKE_SHARED_LINKER_FLAGS_RELEASE} /OPT:REF /OPT:ICF /INCREMENTAL:NO /LTCG" )
32+
set(CMAKE_SHARED_LINKER_FLAGS_DEBUG "${CMAKE_SHARED_LINKER_FLAGS_DEBUG} /INCREMENTAL:NO /LTCG" )
33+
34+
set(CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG} /INCREMENTAL:NO /LTCG" )
35+
set(CMAKE_EXE_LINKER_FLAGS_RELEASE "${CMAKE_EXE_LINKER_FLAGS_RELEASE} /INCREMENTAL:NO /LTCG" )
3236

3337
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
3438
endif()

README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,3 +229,17 @@ numbers.none_of([](const auto &number) {
229229
return number > 7;
230230
});
231231
```
232+
233+
### Parallel algorithms
234+
Since C++17 several STL algorithms can be executed in parallel.
235+
236+
clang on macOS does not yet fully support the parallel execution model, however on Windows and Linux, a `functional_vector` supports the following parallel algorithms
237+
```c++
238+
for_each_parallel
239+
map_parallel
240+
filter_parallel
241+
sort_parallel
242+
all_of_parallel
243+
any_of_parallel
244+
none_of_parallel
245+
```

include/compatibility.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,7 @@
2525
#if __cplusplus >= 201703L
2626
#define CPP17_AVAILABLE
2727
#endif
28+
29+
#if defined(CPP17_AVAILABLE) && !defined(__clang__)
30+
#define PARALLEL_ALGORITHM_AVAILABLE
31+
#endif

0 commit comments

Comments
 (0)