c - MPI_Init() VS MPI_Init_thread()

标签 c multithreading parallel-processing mpi distributed-computing

有什么区别,应该实际使用哪一个?我找到了这个 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_FUNNELEDMPI_SERIALIZED 也可以工作。

关于c - MPI_Init() VS MPI_Init_thread(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34851903/

相关文章:

c++ - 我使用统一内存运行内核函数后无法访问它

C 中的命令行参数整数错误检查

c++ - C/C++ 用一个值填充结构数组

c - 在 C 中验证整数

c - 如何使用 OpenMP 在一段时间内并行化代码

parallel-processing - Redis 实例到底是什么?

从 mongoose begin_request_handler 回调调用函数

重复非锁定条件信号的 Java 抽象

python - 在python上并行执行和文件写入

c++ - g++中的线程?