Pthreads vs. OpenMP Pthreads vs. OpenMP c c

Pthreads vs. OpenMP


Pthreads and OpenMP represent two totally different multiprocessing paradigms.

Pthreads is a very low-level API for working with threads. Thus, you have extremely fine-grained control over thread management (create/join/etc), mutexes, and so on. It's fairly bare-bones.

On the other hand, OpenMP is much higher level, is more portable and doesn't limit you to using C. It's also much more easily scaled than pthreads. One specific example of this is OpenMP's work-sharing constructs, which let you divide work across multiple threads with relative ease. (See also Wikipedia's pros and cons list.)

That said, you've really provided no detail about the specific program you're implementing, or how you plan on using it, so it's fairly impossible to recommend one API over the other.


If you use OpenMP, it can be as simple as adding a single pragma, and you'll be 90% of the way to properly multithreaded code with linear speedup. To get the same performance boost with pthreads takes a lot more work.

But as usual, you get more flexibility with pthreads.

Basically, it depends on what your application is. Do you have a trivially-parallelisable algorithm? Or do you just have lots of arbitrary tasks that you'd like to simultaneously? How much do the tasks need to talk to each other? How much synchronisation is required?


OpenMP has the advantages of being cross platform, and simpler for some operations. It handles threading in a different manner, in that it gives you higher level threading options, such as parallelization of loops, such as:

#pragma omp parallel forfor (i = 0; i < 500; i++)    arr[i] = 2 * i;

If this interests you, and if C++ is an option, I'd also recommend Threading Building Blocks.

Pthreads is a lower level API for generating threads and synchronization explicitly. In that respect, it provides more control.