MPI_Init() VS MPI_Init_thread()

MPI_Init() VS MPI_Init_thread()

有什么区别,应该实际使用哪一种?我找到了这个 IBM link and this question MPI - one function for MPI_Init and MPI_Init_thread。如果重要的话,我只对 C 语言感兴趣。


两个函数的描述相同:

MPI_Init_thread Initialize the MPI execution environment

如您在他们的参考文献中所见:MPI_Init() and MPI_Init_thread() 论据不同。

只要您的程序使用线程,就应该使用 MPI_Init_thread()

这取决于您对线程的使用情况,您将传递 required 的哪个值。 来自 OpenMPI 手册的参考:

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.

通常,required 唯一被区别对待的值是 MPI_THREAD_MULTIPLE。如果更多线程可以同时调用 MPI 函数,则传递此值。不幸的是,在这种情况下,MPI 库的性能通常很差。

其他人在 MPI 库中通常受到平等对待。然而,如果在构建 OpenMPI 时禁用了线程支持,它仍然会抱怨,唯一的 provided 值是 MPI_THREAD_SINGLE,即使 MPI_FUNNELEDMPI_SERIALIZED 可以工作也是。