Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why POSIX Threads are Slower Than OpenMP

Tags:

c

pthreads

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.

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.)

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

like image 791
user541686 Avatar asked Apr 13 '11 03:04

user541686


People also ask

Is pthreads or OpenMP faster?

That is not required, although generally true. If OpenMP were implemented to bare metal on a specialized architecture, it could be faster than Pthreads.

Is OpenMP a POSIX?

POSIX threads, being part of the POSIX standard, are cross-platform. OpenMP, not being present in any operating system or C language standard I know of, is not cross-platform, unless you have a really strange idea of what cross-platform means.

Are POSIX threads parallel?

POSIX Threads, commonly known as pthreads, is an execution model that exists independently from a language, as well as a parallel execution model.

How can POSIX threads be useful?

This saves a lot of CPU time, making thread creation ten to a hundred times faster than a new process creation. Because of this, you can use a whole bunch of threads and not worry about the CPU and memory overhead incurred. This means you can generally create threads whenever it makes sense in your program.


1 Answers

(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.

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

like image 54
Jess Avatar answered Sep 21 '22 21:09

Jess