在MPI中订购输出 [英] Ordering Output in MPI

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

问题描述

在一个简单的MPI程序中,我使用了大矩阵的按列划分. 如何排序输出,以便每个矩阵紧挨另一个排序出现? 我已经尝试过这个简单的代码,其效果与想要的效果完全不同:

in a simple MPI program I have used a column wise division of a large matrix. How can I order the output so that each matrix appears next to the other ordered ? I have tried this simple code the effect is quite different from the wanted:

for(int i=0;i<10;i++)
{
    for(int k=0;k<numprocs;k++)
    {
        if (my_id==k){
            for(int j=1;j<10;j++)
                printf("%d",data[i][j]);
        }
        MPI_Barrier(com);
    }
    if(my_id==0)
        printf("\n");
}

似乎每个进程都有自己的标准输出,因此如果不将所有数据发送到一个要打印的主机,就不可能输出有序行.我的猜测是真的吗?还是我做错了什么?

Seems that each process has his own stdout and so is impossible to have ordered lines output without sending all the data to one master which will print out. Is my guess true ? Or what I'm doing wrong ?

推荐答案

您猜对了. MPI标准指定在原始过程中应如何收集来自不同节点的stdout以进行打印.通常,当多个进程正在执行打印时,输出将以未指定的方式合并. fflush没有帮助.

You guessed right. The MPI standard does not specify how stdout from different nodes should be collected for printing at the originating process. It is often the case that when multiple processes are doing prints the output will get merged in an unspecified way. fflush doesn't help.

如果您希望以某种方式对输出进行排序,则最便于移植的方法将是将数据发送到主流程进行打印.

If you want the output ordered in a certain way, the most portable method would be to send the data to the master process for printing.

例如,使用伪代码:

if (rank == 0) {
    print_col(0);
    for (i = 1; i < comm_size; i++) {
        MPI_Recv(buffer, .... i, ...);
        print_col(i);
    }
} else {
    MPI_Send(data, ..., 0, ...);
}

有时可以工作的另一种方法是使用障碍物锁定步骤过程,以便每个过程依次打印.当然,这取决于MPI实施及其如何处理stdout.

Another method which can sometimes work would be to use barries to lock step processes so that each process prints in turn. This of course depends on the MPI Implementation and how it handles stdout.

for(i = 0; i < comm_size; i++) {
    MPI_Barrier(MPI_COMM_WORLD);
    if (i == rank) {
         printf(...);
    }
}

当然,在生产代码中,数据太大而无法进行明智的打印,最终通过将每个进程写入单独的文件并单独合并或使用MPI I/O (

Of course, in production code where the data is too large to print sensibly anyway, data is eventually combine by having each process writing to a separate file and merged separately, or using MPI I/O (defined in the MPI2 standards) to coordinate parallel writes.

这篇关于在MPI中订购输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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