Serialized MPI and OpenMP
Here is an example requiring MPI_THREAD_SERIALIZED
support or higher. At this level of thread support, any thread may make MPI calls, but never concurrently with other threads. Therefore, MPI calls must be prevented from overlapping with the MPI calls from other threads. This "serialization" of threads can be achieved with OpenMP constructs such as omp critical
and omp single
.
The above example shows the simplest scenario: any thread (not necessarily the main
thread) executes an MPI call within the omp single
construct, while the other threads are idle. Notes on the program:
- An
omp barrier
may be needed before theomp single
construct that has the MPI call(s) - A barrier is not needed afterward, as there is an implicit barrier at the end of the
omp single
worksharing construct
As discussed on the previous page for MPI_THREAD_FUNNELED
, a barrier should only be necessary if it is important
that MPI wait on the results of other threads.