Pthreads vs. OpenMP

user191776 picture user191776 · Oct 16, 2010 · Viewed 48.9k times · Source

I'm creating a multi-threaded application in C using Linux.

I'm unsure whether I should use the POSIX thread API or the OpenMP API.

What are the pros & cons of using either?

Edit:

Could someone clarify whether both APIs create kernel-level or user-level threads?

Answer

Matt Ball picture Matt Ball · Oct 16, 2010

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.