MSVC article

Using C++17 Parallel Algorithms for Better Performance Microsoft announced support for C++17 Parallel Algorithms in a blog post published in September 2018. It is used in the same way as the C++17 standard and does not require much change.

Since multicore would accumulate clock_t multiple times, timing would have to be replaced with the time function provided by chrono. It doesn’t matter whether to use high_resolution_clock or system_clock, because our test takes longer because of the large amount of data.

The most striking sentence was:

#include <execution>
Copy the code

With it, you can play the performance of multi-core computing. Since there is no higher machine configuration in Windows, only a small amount of data was tested and passed successfully.

The ICC article

In order to experience the new parallelism features of C++17 on Mac, I applied for the education edition package Intel® Parallel Studio XE 2019, which includes the Intel® C++ Compiler 19.0 for macOS. There are a lot of twists and turns, but it feels like it could be made better in the future.

The compiler is easy to use, just refer to this help in the installation path:

opt/intel/documentation_2019/en/compiler_c/ps2019/get_started_mc.htm
Copy the code

Using the C++ compiler:

icpc source.cpp
Copy the code

To experience parallelism, follow the instructions in Get Started with Parallel STL. Use basically follow the C++17 standard, but include header files must add PSTL. For example, to use a parallel algorithm, we need to append to the original header file:

#include <pstl/execution>
#include <pstl/algorithm>
Copy the code

That’s not quite up to standard.

We consider sorting a billion random double numbers using uniform distribution. One line of code:

std::sort(std::execution::par, V.begin(), V.end());
Copy the code

The measured speed is amazing: 11 seconds!

Since parallel sorting is used, the actual memory footprint is larger and different each time, but not more than twice the original vector, which is 15GB. This shows that memory is important.

other

Clang and GCC: Go, go, go.