C ++并行库:OpenMP与线程构建块 [英] C++ Parallelization Libraries: OpenMP vs. Thread Building Blocks

查看:117
本文介绍了C ++并行库:OpenMP与线程构建块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要改造我的自定义图形引擎,以便利用多核CPU。更确切地说,我正在寻找一个库来并行化循环。

I'm going to retrofit my custom graphics engine so that it takes advantage of multicore CPUs. More exactly, I am looking for a library to parallelize loops.

在我看来,OpenMP和Intel的Thread Building Block都非常适合这项工作。此外,两者都支持Visual Studio的C ++编译器和大多数其他流行的编译器。这两个图书馆似乎都很直接使用。

It seems to me that both OpenMP and Intel's Thread Building Blocks are very well suited for the job. Also, both are supported by Visual Studio's C++ compiler and most other popular compilers. And both libraries seem quite straight-forward to use.

那么,我应该选择哪一个?有没有人试过这两个图书馆,可以给我一些利弊和使用任何图书馆的专家?此外,你选择与谁合作到底是什么?

So, which one should I choose? Has anyone tried both libraries and can give me some cons and pros of using either library? Also, what did you choose to work with in the end?

感谢,

Adrian

推荐答案

我没有广泛使用TBB,但我的印象是,他们互补比竞争。 TBB提供线程安全的容器和一些并行算法,而OpenMP更多是并行化现有代码的方式。

I haven't used TBB extensively, but my impression is that they complement each other more than competing. TBB provides threadsafe containers and some parallel algorithms, whereas OpenMP is more of a way to parallelise existing code.

我个人认为OpenMP很容易放入现有代码您有一个可并行运行的循环或一系列段。然而,它不能帮助你特别是一个情况下,你需要修改一些共享数据 - TBB的并发容器可能正是你想要的。

Personally I've found OpenMP very easy to drop into existing code where you have a parallelisable loop or bunch of sections that can be run in parallel. However it doesn't help you particularly for a case where you need to modify some shared data - where TBB's concurrent containers might be exactly what you want.

如果你想要的是并行循环,其中迭代是独立的(或者可以很容易做到),我去OpenMP。如果你需要更多的线程之间的互动,我认为TBB可能会提供一点点在这方面。

If all you want is to parallelise loops where the iterations are independent (or can be fairly easily made so), I'd go for OpenMP. If you're going to need more interaction between the threads, I think TBB may offer a little more in that regard.

这篇关于C ++并行库:OpenMP与线程构建块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆