OpenMPI MPI_Barrier问题 [英] OpenMPI MPI_Barrier problems

查看:85
本文介绍了OpenMPI MPI_Barrier问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用MPI_Barrier的OpenMPI实现时出现一些同步问题:

I having some synchronization issues using the OpenMPI implementation of MPI_Barrier:

int rank;
int nprocs;

int rc = MPI_Init(&argc, &argv);

if(rc != MPI_SUCCESS) {
    fprintf(stderr, "Unable to set up MPI");
    MPI_Abort(MPI_COMM_WORLD, rc);
}

MPI_Comm_size(MPI_COMM_WORLD, &nprocs);
MPI_Comm_rank(MPI_COMM_WORLD, &rank);


printf("P%d\n", rank);
fflush(stdout);

MPI_Barrier(MPI_COMM_WORLD);

printf("P%d again\n", rank);

MPI_Finalize();

对于mpirun -n 2 ./a.out

for mpirun -n 2 ./a.out

输出应为: P0 P1 ...

output should be: P0 P1 ...

输出有时是 : P0 再次P0 P1 再次是P1

output is sometimes: P0 P0 again P1 P1 again

怎么回事?

推荐答案

打印输出行在终端上的显示顺序不一定是打印内容的顺序.为此,您正在使用共享资源(stdout),因此始终必须存在订购问题. (并且fflush在这里无济于事,无论如何stdout都是行缓冲的.)

The order in which your print out lines appear on your terminal is not necessarily the order in which things are printed. You are using a shared resource (stdout) for that so there always must be an ordering problem. (And fflush doesn't help here, stdout is line buffered anyhow.)

您可以尝试在输出的前面加上时间戳,并将所有这些保存到不同的文件中,每个MPI进程一个.

You could try to prefix your output with a timestamp and save all of this to different files, one per MPI process.

然后要检查您的日志,可以将两个文件合并在一起并根据时间戳进行排序.

Then to inspect your log you could merge the two files together and sort according to the timestamp.

那么您的问题应该消失了.

Your problem should disappear, then.

这篇关于OpenMPI MPI_Barrier问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆