为什么我的OpenMP实现比单线程执行慢? [英] Why is my OpenMP implementation slower than a single threaded implementation?

查看:1290
本文介绍了为什么我的OpenMP实现比单线程执行慢?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在学习有关OpenMP的并发性,并试图在我的手一些现有code我有。在这个code,我试图让所有的for循环并行。然而,这似乎使程序慢得多,至少慢10倍,涨幅比单线程版本还要多。

I am learning about OpenMP concurrency, and tried my hand at some existing code I have. In this code, I tried to make all the for loops parallel. However, this seems to make the program MUCH slower, at least 10x slower, or even more than the single threaded version.

下面是code: http://pastebin.com/zyLzuWU2

我也用pthreads的,它原来是比单线程版本快。

I also used pthreads, which turns out to be faster than the single threaded version.

现在的问题是,我在做什么错在我,是造成这种放缓OpenMP实现?

Now the question is, what am I doing wrong in my OpenMP implementation that is causing this slowdown?

谢谢!

编辑:单线程版本只是没有所有的编译指示一

edit: the single threaded version is just the one without all the #pragmas

推荐答案

一个问题我与你code看到的是,你正在使用OpenMP跨都很小环(8或64次迭代,例如)。这不会是有效的,由于开销。如果你想使用的OpenMP的N皇后问题,看的OpenMP 3.0任务和线程并行分支定界问题。

One problem I see with your code is that you are using OpenMP across loops that are very small (8 or 64 iterations, for example). This will not be efficient due to overheads. If you want to use OpenMP for the n-queens problem, look at OpenMP 3.0 tasks and thread parallelism for branch-and-bound problems.

这篇关于为什么我的OpenMP实现比单线程执行慢?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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