简体   繁体   English

STL算法使用多核吗?

[英]Do STL algorithms use multiple cores?

Do the C++ STL algorithms use multiple-cores of the CPU under the hood for faster performance? C ++ STL算法是否在引擎盖下使用多核CPU以提高性能? If not, are there any recommended libraries to do what does STL does but with multiple cores, say using OpenMP? 如果没有,是否有任何推荐的库可以执行STL所做的事情,但使用多个内核,比如说使用OpenMP? Or are there any switches one can specify during compilation with gcc instructing STL to use multiple cores 或者是否有任何开关可以在编译期间指定gcc指示STL使用多个内核

EDIT: I am using Intel Core i7 960 processors, on Ubuntu 10.10 with gcc 4.4 编辑:我在Ubuntu 10.10和gcc 4.4上使用英特尔酷睿i7 960处理器

GNU libstdc++ seems to have a parallel mode that supports several parallelization features for STL: GNU libstdc ++似乎有一个并行模式,支持STL的几个并行化功能:

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

I know of no STL implementation that leverages multiple cores. 我知道没有利用多核的STL实现。 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 (eg > 10 million elements). STL提供的算法类型(排序,累积等)仅在相当极端的情况下(例如> 1000万个元素)从并行性中受益。 If you only leverage parallelism at the STL level, you are probably going to be disappointed in the results. 如果您只在STL级别利用并行性,那么您可能会对结果感到失望。

I would look at Intel's TBB (http://threadingbuildingblocks.org/) which provides a task-based parallelism framework. 我会看一下英特尔的TBB(http://threadingbuildingblocks.org/),它提供了一个基于任务的并行框架。 It encourages algorithm design that is amenable to task-based scheduling and not just a bunch of leaf functions (eg parallel_sort() although TBB does provide one). 它鼓励算法设计适合基于任务的调度,而不仅仅是一堆叶子函数(例如parallel_sort(),尽管TBB确实提供了一个)。

The C++ standard neither requires nor prohibits parallel execution of standard algorithms. C ++标准既不要求也不禁止并行执行标准算法。

There have been a number of parallel implementations. 已经有许多并行实现。 In addition to libstdc++ parallel mode (which was mostly based on MCSTL ) there are STAPL , and OMPTL (which is also included in CVMLCPP ). 除了libstdc ++并行模式(主要基于MCSTL )之外,还有STAPLOMPTL (也包含在CVMLCPP中 )。 There has been a fair amount of other work, but development of libstdc++ parallel mode seems to have killed quite a few other projects. 已经有相当多的其他工作,但libstdc ++并行模式的开发似乎已经杀死了其他一些项目。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM