为什么POSIX线程比OpenMP慢 [英] Why POSIX Threads are Slower Than OpenMP

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

问题描述

我正在使用Xeon处理器的Mac Pro上运行完全并行的矩阵乘法程序.我创建了8个线程(与内核一样多的线程),并且没有共享的写入问题(没有写入相同的位置).由于某些原因,我使用pthread_createpthread_join的速度大约是使用#pragma openmp的两倍.

I'm running a completely parallel matrix multiplication program on a Mac Pro with a Xeon processor. I create 8 threads (as many threads as cores), and there are no shared writing issues (no writing to the same locations). For some reason, my use of pthread_create and pthread_join is about twice as slow as using #pragma openmp.

在其他方面没有其他区别……相同的编译选项,两种情况下的线程数量,相同的代码(显然是pragma/pthread部分除外),等等.

There are no other differences in anything... same compile options, same number of threads in both cases, same code (except the pragma/pthread portions obviously), etc.

而且循环很大 -我不是并行处理小的循环.

And the loops are very big -- I'm not parallelizing small loops.

(因为它是学校的工作,所以我无法真正发布代码.)

(I can't really post the code because it's school work.)

为什么会发生这种情况? OpenMP本身不使用POSIX线程吗?怎么会更快?

Why might this be happening? Doesn't OpenMP use POSIX threads itself? How can it be faster?

推荐答案

(已编辑) 您的主线程在做什么?在没有看到您的代码的情况下,我猜测主线程实际上几乎没有在运行,但是在pthread完成时仍然占用了时钟周期,然后再次启动并继续.每次给定周期时,都有暂停/继续其他线程的开销.

(edited) What is your main thread doing? Without seeing your code, I was guessing that the main thread is actually barely running, but still eating up clock-cycles while the pthreads finish, then it starts again and continues. Each time its given cycles there is overhead to pausing/continuing the other threads.

在OpenMP中,主线程可能进入睡眠状态,并在并行区域完成时等待唤醒事件.

In OpenMP, the main thread probably goes to sleep, and waits for a wake-up event when the parallel regions finish.

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

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