My programming ramblings

Posted on May 9, 2019 by Paul

Thanks to Bartlomiej Filipek for the suggestion to try C++17 parallel algorithms with GCC 9 and Intel TBB on Linux.

GCC 9.1 has support for C++17 parallel algorithms by using the Intel TBB library. In this article, I will show you how to build Intel TBB from sources on your machine and how to sort a vector of random numbers in parallel using C++17 std::sort.

At the time of this writing, the latest stable version of Intel TBB is version 2019 Update 6. You can find the latest release of TBB on their GitHubrepo. If a newer version was released, change the version number from the next instructions accordingly.

At this point, you should be able to use the C++17 parallel algorithms.

Here is a small C++17 test program, that will fill a vector with 5 millions random doubles, with values from 0 to 1. Next, we sort the vector sequentially and in parallel. Each test is repeated 10 times and the elapsed time, in milliseconds, is printed on the screen:

I’ve seen similar results on a Linux machine. The parallel, optimized version, is 2 - 2.5x faster than the serial version. For the non optimized version the difference between the parallel and the sequential version is slightly larger.

Disclaimer:All data and information provided on this site is for informational purposes only. solarianprogrammer.com makes no representations as to accuracy, completeness, currentness, suitability, or validity of any information on this site and will not be liable for any errors, omissions, or delays in this information or any losses, injuries, or damages arising from its display or use. All information is provided on an as-is basis. solarianprogrammer.com does not collect any personal information about its visitors except that which they provide voluntarily when leaving comments. This information will never be disclosed to any third party for any purpose. Some of the links contained within this site have my referral id, which provides me with a small commission for each sale. Thank you for understanding.