MPI - 打印的顺序 [英] MPI - Printing in an order

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

问题描述

我想用C每个处理器打印它自己的数据编写一个函数。
这里是我有:

I'm trying to write a function in C where every processor prints it's own data. Here is what i have:

void print_mesh(int p,int myid,int** U0,int X,int Y){
    int i,m,n;
    for(i=0;i<p;i++){
        if(myid==i){
            printf("myid=%d\n",myid);
            for(n=0;n<X;n++){
                for(m=0;m<Y;m++){
                    printf("%d ",U0[n][m]);
                }
                printf("\n");
            }
        }
        else MPI_Barrier(MPI_COMM_WORLD);
    }
}

它不会出于某种原因。该阵列打印的所有混合起来。
你有什么见解,为什么这不起作用?任何其他的想法这项工作?
如果可能的话,我不想整个阵列发送一个主进程。此外,我不希望使用precompiled功能。

It doesn't work for some reason. The arrays are printed all mixed up. Do you have any insight as to why this doesn't work? Any other ideas that work? If possible, I don't want to send the whole array in a master process. Also I don't want to use precompiled functions.

推荐答案

有没有办法保证,从许多不同的进程消息将在正确的顺序,当他们到达另一个进程到达。实际上,这就是这里发生的一切。

There is no way to guarantee that messages from many different processes will arrive in the "correct" order when they arrive to another process. This is essentially what is happening here.

即使你没有明确发送消息,当你打印的东西到屏幕上,它必须被发送到进程本地系统( mpiexec的的mpirun ),在那里可以打印到屏幕。有没有办法为MPI知道这些消息的正确顺序,因此只是打印他们,因为他们到达。

Even though you aren't explicitly sending messages, when you print something to the screen, it has to be sent to the process on your local system (mpiexec or mpirun) where it can be printed to the screen. There is no way for MPI to know what the correct order for these messages is so it just prints them as they arrive.

如果您需要您的邮件以特定的顺序打印,您必须将它们全部发送到一个等级,可以在任何你喜欢的顺序打印出来。只要一个等级做了所有的印刷,所有的消息都将被正确排序。

If you require that your messages are printed in a specific order, you must send them all to one rank which can print them in whatever order you like. As long as one rank does all of the printing, all of the messages will be ordered correctly.

应该说,有可能会是,你可以找到在那里它说,你可以在你的字符串的结尾放一个新行或使用冲水(),以确保缓冲被刷新的答案,但不会保证订货关于上述原因远端

It should be said that there will probably be answers that you can find out there which say you can put a newline at the end of your string or use flush() to ensure that the buffers are flushed, but that won't guarantee ordering on the remote end for the reasons mentioned above.

这篇关于MPI - 打印的顺序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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