【发布时间】:2014-03-16 21:43:51
【问题描述】:
我有第一个进程 (test1),它动态生成第二个进程 (test2),然后等待从生成的组接收带有标签 1 的消息。 生成的进程执行一些计算,然后向父组(包含第一个进程)发送带有标签 1 的消息,表示它已经完成,最后调用 MPI_Finalize。 第一个进程正确接收消息并继续,但第二个进程在 MPI_Finalize 中挂起。 我不明白是什么阻止了第二个进程终止。
测试 1
#include <stdio.h>
#include "mpi.h"
int main() {
int flag_mpi, erc, err_mpi, ndr;
MPI_Comm comm;
MPI_Initialized (&flag_mpi);
if (!flag_mpi) MPI_Init (NULL,NULL);
err_mpi = MPI_Comm_spawn("test2", MPI_ARGV_NULL, 1, MPI_INFO_NULL,
0, MPI_COMM_WORLD, &comm, &erc);
MPI_Recv(&ndr, 1, MPI_INT, 0, 1, comm, MPI_STATUS_IGNORE);
printf(" Spawn_recv ok (ndr=%d)\n", ndr);
int i = 1;
while (i == 1) { /* just to simulate further computation */
printf(".");
sleep(5);
}
MPI_Initialized (&flag_mpi);
if (flag_mpi) MPI_Finalize();
return 0;
}
测试 2
#include <stdio.h>
#include "mpi.h"
int main() {
int ndr;
MPI_Comm comm;
MPI_Init (NULL,NULL);
/* some computation not involving MPI */
MPI_Comm_get_parent(&comm);
ndr = 1;
MPI_Send(&ndr, 1, MPI_INT, 0, 1, comm);
printf(" Spawn_sent ok (ndr=%d)\n", ndr);
MPI_Finalize();
return 0;
}
【问题讨论】: