Home  >  Article  >  Backend Development  >  How Can I Get C 17 Parallel Algorithms Working?

How Can I Get C 17 Parallel Algorithms Working?

DDD
DDDOriginal
2024-10-26 10:07:03898browse

 How Can I Get C  17 Parallel Algorithms Working?

Are C 17 Parallel Algorithms Implemented Yet?

Question:

Despite attempting to implement the new parallel library features introduced in the C 17 standard, the author encountered compilation errors. They questioned whether these algorithms had been implemented yet.

Answer:

GCC 9 and TBB 2018 are the first to support the C 17 parallel algorithms. However, TBB must be installed separately.

Installation Instructions:

Ubuntu 19.10:

sudo apt install gcc libtbb-dev
g++ -ggdb3 -O3 -std=c++17 -Wall -Wextra -pedantic -o main.out main.cpp -ltbb
./main.out

Ubuntu 18.04:

# Install GCC 9
sudo add-apt-repository ppa:ubuntu-toolchain-r/test
sudo apt-get update
sudo apt-get install gcc-9 g++-9

# Compile libtbb from source.
sudo apt-get build-dep libtbb-dev
git clone https://github.com/intel/tbb
cd tbb
git checkout 2019_U9
make -j `nproc`
TBB="$(pwd)"
TBB_RELEASE="${TBB}/build/linux_intel64_gcc_cc7.4.0_libc2.27_kernel4.15.0_release"

# Use them to compile our test program.
g++-9 -ggdb3 -O3 -std=c++17 -Wall -Wextra -pedantic -I "${TBB}/include" -L 
"${TBB_RELEASE}" -Wl,-rpath,"${TBB_RELEASE}" -o main.out main.cpp -ltbb
./main.out

Performance Analysis:

Testing on a Lenovo ThinkPad P51 laptop with 4 cores/8 threads and 2x 16GiB RAM, the parallel sort was about 4.5 times faster than the serial version for input sizes of 100 million numbers.

Error Messages:

  • If TBB is not installed:

    fatal error: tbb/blocked_range.h: No such file or directory
  • If TBB version is too old:

    #error Intel(R) Threading Building Blocks 2018 is required; older versions are not supported.

The above is the detailed content of How Can I Get C 17 Parallel Algorithms Working?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn