Parallel STL Algorithms in OS X

I am working on converting an existing program to use some parallel STL functions.

In particular, I rewrote a large loop to work with std :: accumulate. It works beautifully.

Now I want this accumulation operation to be performed in parallel.

The documentation I saw for GCC describes two specific steps.

  • Enable compiler flag -D_GLIBCXX_PARALLEL
  • It is possible to add the header <parallel/algorithm>

Adding a compiler flag does not change anything. The runtime is the same, and I see no signs of using multiple cores in monitoring the system.

I get an error when adding the parallel / algorithm header. I thought it would be included in the latest version of gcc (4.7).

So a few questions:

  • Is there any way to finally determine if the code works in parallel?
  • Is there a โ€œbest practiceโ€ way to do this on OS X? (Ideal compiler flags, header, etc.?)

Any suggestions are welcome.

Thanks!

+7
source share
2 answers

See http://threadingbuildingblocks.org/

If you only parallelize the STL algorithms, you will be disappointed in the overall results. These algorithms usually begin to demonstrate the advantage of scalability when working with very large data sets (for example, N> 10 million).

TBB (and others like it) work at a higher level, focusing on the general construction of the algorithm, and not just on the sheet functions (for example, std :: accumulate ()).

+2
source
  • The second alternative is to use OpenMP, which is supported by both GCC and Clang, although not STL, but is cross-platform.
  • A third alternative is to use Grand Central Dispatch, the official multi-core API in OSX, again unlikely to be STL.
  • The second option is to wait for C ++ 17, it will have a Parallelism module.
0
source

All Articles