How do streams of OpenMP, MPI, POSIX, std :: thread, boost :: thread correlate?

There are several ways to implement multithreading. std::thread was eventually introduced by the C ++ 11 standard, but instead, boost::thread could be used efficiently. Each technology has a specific syntax and so on, but - roughly - is used for parallel programming of the processor. But they have a different effect. I know that, for example, MPI and OpenMP are used for different memory models.

I also know that the choice of technology is not really exclusive, so you can use another one (again, MPI and OpenMP). Why are they used for different effects, but still work with the same source (CPU)?

What difference would it be (from the operating system and hardware point of view) if I compile a C ++ program using parallelism based on each of these technologies? Does OpenMP or std::thread , for example, use POSIX threads? If so, how do C ++ 11 threads work on Windows? Or does each of these technologies work directly with the processor through assembly language or something like that?

+6
source share
1 answer

OS provides threads (syscalls for creating new threads, scheduling services).

Unix libc has a wrapper around OS threads with many useful features (such as mutexes, cond vars, etc.). Usually the external interface of such system libraries is "POSIX threads" (functions called pthread_* ): http://en.wikipedia.org/wiki/POSIX_Threads

Windows has its own tough API for threading (WINAPI CreateThread , etc.). But there are shells around the Windows API to get something like POSIX api streams (for example, there are such libraries for mingw32 and cygwin, check the wikipedia section )

C ++ 11 std::thread , boost boost::thread are just modern OS-independent wrappers around the streaming API. They are used to create portable programs that can be compiled on any supported platform, without creating an #ifdef hell and / or writing your own custom wrappers around the stream stream library. If you are creating a new program, think about it.

There are several other streaming wrappers, for example. included in graphics libraries such as QT or GTK +.

OpenMP implementations have an internal support library (for example, gcc has libgomp) that uses the system / libc streaming APIs, for example, libgomp uses POSIX streams. Some implementations may also include switching user-space flows through the assembly (model with M: N thread).

MPI does not have a stream library. MPI is used to create several processes and establish communication between them. But when MPI is used in multi-threaded programs, it will use some streaming API for synchronization. For example, MPICH will use pthreads on unix.

+9
source

All Articles