有什么区别,应该实际使用哪一个?我找到了这个 IBM链接和这个问题 MPI - one function for MPI_Init and MPI_Init_thread .如果重要的话,我只对 C 语言感兴趣。
两个函数的描述是一样的:
MPI_Init_thread Initialize the MPI execution environment
如您在他们的引用文献中所见:MPI_Init()和 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_FUNNELED
和 MPI_SERIALIZED
也可以工作。
关于c - MPI_Init() VS MPI_Init_thread(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34851903/