Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Parallel STL algorithms in OS X

I working on converting an existing program to take advantage of some parallel functionality of the STL.

Specifically, I've re-written a big loop to work with std::accumulate. It runs, nicely.

Now, I want to have that accumulate operation run in parallel.

The documentation I've seen for GCC outline two specific steps.

  1. Include the compiler flag -D_GLIBCXX_PARALLEL
  2. Possibly add the header <parallel/algorithm>

Adding the compiler flag doesn't seem to change anything. The execution time is the same, and I don't see any indication of multiple core usage when monitoring the system.

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

So, a few questions:

  1. Is there some way to definitively determine if code is actually running in parallel?
  2. Is there a "best practices" way of doing this on OS X? (Ideal compiler flags, header, etc?)

Any and all suggestions are welcome.

Thanks!

like image 537
Noah Avatar asked Nov 17 '11 19:11

Noah


1 Answers

See http://threadingbuildingblocks.org/

If you only ever parallelize STL algorithms, you are going to disappointed in the results in general. Those algorithms generally only begin to show a scalability advantage when working over very large datasets (e.g. N > 10 million).

TBB (and others like it) work at a higher level, focusing on the overall algorithm design, not just the leaf functions (like std::accumulate()).

like image 176
mcmcc Avatar answered Nov 14 '22 06:11

mcmcc