并行化:pthreads还是OpenMP? [英] Parallelization: pthreads or OpenMP?

查看:417
本文介绍了并行化:pthreads还是OpenMP?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在共享内存并行化方面,科学计算中的大多数人都将OpenMP用作准标准.

Most people in scientific computing use OpenMP as a quasi-standard when it comes to shared memory parallelization.

是否有其他原因(除了可读性之外)在pthread上使用OpenMP?后者似乎更基础,我怀疑它可以更快,更容易地进行优化.

Is there any reason (other than readability) to use OpenMP over pthreads? The latter seems more basic and I suspect it could be faster and easier to optimize.

推荐答案

它基本上可以归结为您希望对并行化进行何种控制.如果您要做的就是添加一些#pragma语句,并很快获得并行版本的代码,那么OpenMP就是很棒的选择.如果您想使用MIMD编码或复杂的队列来做一些真正有趣的事情,您仍然可以使用OpenMP来完成所有这些工作,但是在这种情况下使用线程可能要简单得多. OpenMP在可移植性方面也具有类似的优势,因为与pthreads一样,现在许多用于不同平台的编译器都支持它.

It basically boils down to what level of control you want over your parallelization. OpenMP is great if all you want to do is add a few #pragma statements and have a parallel version of your code quite quickly. If you want to do really interesting things with MIMD coding or complex queueing, you can still do all this with OpenMP, but it is probably a lot more straightforward to use threading in that case. OpenMP also has similar advantages in portability in that a lot of compilers for different platforms support it now, as with pthreads.

因此,您绝对正确-如果您需要对并行化进行微调的控制,请使用pthreads.如果您希望尽可能少地并行化,请使用OpenMP.

So you're absolutely correct - if you need fine-tuned control over your parallelization, use pthreads. If you want to parallelize with as little work as possible, use OpenMP.

无论您决定走哪条路,祝你好运!

Whichever way you decide to go, good luck!

这篇关于并行化:pthreads还是OpenMP?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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