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.

Example of MPI_THREAD_SERIALIZED: thread selected by omp single calls MPI_Send and MPI_Recv
With the MPI_THREAD_SERIALIZED level of thread support,
one thread at a time is able to call MPI

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 the omp 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.

 
©  |   Cornell University    |   Center for Advanced Computing    |   Copyright Statement    |   Inclusivity Statement