Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MPI_Init() VS MPI_Init_thread()

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.

like image 649
gsamaras Avatar asked Jan 18 '16 10:01

gsamaras


People also ask

What does MPI_Init return?

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.

What are MPI and threads?

MPI and Threads. • MPI describes parallelism between processes. (with separate address spaces) • Thread parallelism provides a shared-memory. model within a process.


1 Answers

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.

like image 134
Vladimir F Героям слава Avatar answered Nov 20 '22 12:11

Vladimir F Героям слава