Which is the difference and which one should one practically use? I have found this IBM link and this question MPI - one function for MPI_Init and MPI_Init_thread. I am interesting only in C, if that matters.
The description is the same for both functions:
MPI_Init_thread Initialize the MPI execution environment
as you see in their refs: MPI_Init() and MPI_Init_thread(), but the arguments differ.
Return value The function returns an error if it is unsuccessful. By default, the error aborts the MPI job. In case of success, it returns MPI_SUCCESS - the value returned upon successful termination of any MPI routine. It returns MPI_ERR_OTHER if MPI_Init is used again in the program.
MPI and Threads. • MPI describes parallelism between processes. (with separate address spaces) • Thread parallelism provides a shared-memory. model within a process.
Whenever your program uses threading, you should use MPI_Init_thread()
.
It depends on your usage of the threads which value of required
you will pass.
Reference from the OpenMPI manual:
MPI_THREAD_SINGLE Only one thread will execute.
MPI_THREAD_FUNNELED If the process is multithreaded, only the thread that called MPI_Init_thread will make MPI calls.
MPI_THREAD_SERIALIZED If the process is multithreaded, only one thread will make MPI library calls at one time.
MPI_THREAD_MULTIPLE If the process is multithreaded, multiple threads may call MPI at once with no restrictions.
Usually, the only value of required
that is treated differently is MPI_THREAD_MULTIPLE
. You pass this value if more threads can call MPI functions at the same time. Unfortunately, the performance of the MPI library is usually bad in this case.
The others are often treated equally in the MPI libraries. Nevertheless, if the support of threads was disabled when you built OpenMPI, it will still complain, that the only provided
value is MPI_THREAD_SINGLE
, even if MPI_FUNNELED
and MPI_SERIALIZED
will work too.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With