Mixing OpenMP with pthreads

My question is whether it is worth mixing OpenMP with pthreads. Are there any applications that combine the two. Is it good practice to mix the two? Or typical applications usually use one of two.

+6
source share
6 answers

It is usually better to use one or the other. But for me, at least I mix them regularly, and it's safe if it is done correctly.

The most common case when I do this is where I have a lower level library that has threaded using pthreads, but I call it in a user application using OpenMP.

There are times when it is unsafe. If, for example, you kill pthread before you exit all areas of OpenMP in this thread.

+7
source

I do not think so..

This is not a good idea. See what OpenMP is mainly made for portability. Now, if u uses pthread, then you lose the essence of it!

pthread can only be supported by POSIX compatible operating systems. Although OpenMP can be used on almost any OS, if they have support.

In any case, OpenMP gives you an abstraction much higher than what pthead provides.

+1
source

No problems.

The purpose of OpenMP and pthreads is different. OpenMP is ideal for recording parallelism loop level. However, OpenMP is not suitable for expressing complex streams and thread synchronization. OpenMP does not support all kinds of synchronization, such as condition variables.

A caveat would, as Mystic pointed out, be to process and access native threads in parallel OpenMP constructs.

FYI, Intel TBB and Cilk Plus are also often used in a mixed way.

0
source

On Windows and Linux, this works fine. However, OpenMP does not work on a Mac if it starts in a new thread. It only works in the main thread.

It appears that the behavior associated with mixing the two streams is undefined. Some platforms / compilers support it, others do not.

0
source

Of course. I do this all the time. You must be careful. Why do this? Because there are some cases in which you must! In complex tasks, such as pipelined functions in which you want to save the channel, this may be the only way to use all available power.

0
source

It is very hard for me that you will need to use pthreads if you are already using OpenMP. You can use the pragma section to start procedures with various functions. I personally used it to implement the parallelism pipeline.

OpenMP currently does a lot more than pthreads, so if you're using OpenMP, you're covered. For example, GCC 5.0 forward implements OpenMP extensions that export code to a GPU .: D

0
source

Source: https://habr.com/ru/post/897398/


All Articles