更新时间:2023-11-10 15:37:28
MPI提供了四个不同级别的线程支持:MPI_THREAD_SINGLE
,MPI_THREAD_SERIALIZED
,MPI_THREAD_FUNNELED
和MPI_THREAD_MULTIPLE
.为了能够同时从不同的线程进行MPI调用,您必须使用MPI_THREAD_MULTIPLE
线程支持级别初始化MPI,并确保该库实际上提供了该级别:
MPI provides four different levels of thread support: MPI_THREAD_SINGLE
, MPI_THREAD_SERIALIZED
, MPI_THREAD_FUNNELED
, and MPI_THREAD_MULTIPLE
. In order to be able to make MPI calls from different threads concurrently, you have to initialise MPI with the MPI_THREAD_MULTIPLE
level of thread support and make sure that the library actually provides that level:
int provided;
MPI_Init_thread(&argc, &argv, MPI_THREAD_MULTIPLE, &provided);
if (provided < MPI_THREAD_MULTIPLE)
{
printf("Error: the MPI library doesn't provide the required thread level\n");
MPI_Abort(MPI_COMM_WORLD, 0);
}
如果您调用MPI_Init
而不是MPI_Init_thread
,则库可以***选择其创建者认为***的默认线程支持级别.对于MPI_THREAD_SINGLE
的Open MPI,即不支持线程.您可以通过设置环境变量OMPI_MPI_THREAD_LEVEL
来控制默认级别,但是不建议这样做-应该使用MPI_Init_thread
.
If you call MPI_Init
instead of MPI_Init_thread
, the library is free to chose whatever default thread support level its creators deemed best. For Open MPI that is MPI_THREAD_SINGLE
, i.e. no support for threads. You can control the default level by setting the environment variable OMPI_MPI_THREAD_LEVEL
but that is not recommended - MPI_Init_thread
should be used instead.