Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Do STL algorithms use multiple cores?

Do the C++ STL algorithms use multiple-cores of the CPU under the hood for faster performance? If not, are there any recommended libraries to do what does STL does but with multiple cores, say using OpenMP? Or are there any switches one can specify during compilation with gcc instructing STL to use multiple cores

EDIT: I am using Intel Core i7 960 processors, on Ubuntu 10.10 with gcc 4.4

like image 809
smilingbuddha Avatar asked Jan 31 '12 16:01

smilingbuddha


2 Answers

GNU libstdc++ seems to have a parallel mode that supports several parallelization features for STL:

http://gcc.gnu.org/onlinedocs/libstdc++/manual/parallel_mode.html

like image 161
Sedat Kapanoglu Avatar answered Oct 12 '22 22:10

Sedat Kapanoglu


I know of no STL implementation that leverages multiple cores. Even if one does exist, you need to ensure that the added complexity ends up as a net benefit. The types of algorithms STL provides (sort, accumulate, etc.) benefit from parallelism only in fairly extreme circumstances (e.g. > 10 million elements). If you only leverage parallelism at the STL level, you are probably going to be disappointed in the results.

I would look at Intel's TBB (http://threadingbuildingblocks.org/) which provides a task-based parallelism framework. It encourages algorithm design that is amenable to task-based scheduling and not just a bunch of leaf functions (e.g. parallel_sort() although TBB does provide one).

like image 28
mcmcc Avatar answered Oct 12 '22 22:10

mcmcc