【发布时间】:2019-07-27 20:26:07
【问题描述】:
我使用 C 编写 MPI 程序。假设我使用 10 个内核。我想将glob 传递给所有其他内核,但以下代码中的glob 由其中一个内核执行,这是非法的,代码将失效。
for ( i = 0; i < n_loc; i++ ) { /*n_loc is the local number based on each core*/
if ( a_loc[i] == glob ) { /*a_loc is a local array based on each core*/
glob += 1;
MPI_Bcast ( &glob, 1, MPI_INT, MYID, MPI_COMM_WORLD );
}
}
那么我该怎么做才能解决这个问题,全局变量被 10 个核心之一更改但我想通知其他 9 个核心?
【问题讨论】:
-
在 MPI 中不存在单方面的集体。我不知道您要实现什么目标,但您的程序似乎有一个未定义的并行行为。请发布minimal reproducible example,以便您了解如何最好地前进。