MPI_Init() VS MPI_Init_thread()
Asked Answered
D

1

9

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.

Dune answered 18/1, 2016 at 10:1 Comment(0)
P
13

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.

Pannonia answered 18/1, 2016 at 10:17 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.