Question: Can I safely assume that most implementations of MPI don't choke up on this piece of code?
In practice - yes, if you add synchronisation (which your code is lacking); in theory - no. While it is possible that some implementations allow for serialised calls from different threads at the MPI_THREAD_SINGLE
level (with Open MPI being such one - see here), the MPI standard requires that the library must be initialised at the MPI_THREAD_SERIALIZED
level. If you intent for your software to be portable and to be able to compile and run correctly with other MPI implementations, you should not rely on some particular Open MPI behaviour.
That said, Open MPI can be configured to support multithreading (MPI_THREAD_MULTIPLE
) when the library is built. The default is that MT support is not enabled for performance reasons. You can check the state of your particular installation using ompi_info
:
$ ompi_info | grep MPI_THREAD_MULTIPLE
Thread support: poxis (MPI_THREAD_MULTIPLE: no, progress: no)
^^^^^^^^^^^^^^^^^^^^^^^
That particular build does not support multithreading and will always return MPI_THREAD_SINGLE
in the provided
output argument of MPI_Init_thread
.