来自未知来源的MPI接收 [英] MPI recv from an unknown source

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

问题描述

我正在MPI中实现一个程序,在该程序中,主进程(rank = 0)应该能够接收来自其他进程的请求,这些进程请求仅由根知道的变量的值. 如果我使MPI_Recv(...)的等级为0,则必须指定将请求发送到根目录的进程的等级,但是由于进程未按1,2,3的顺序运行,所以我无法控制它的等级. ,.... 如何从任何级别接收请求,并使用发送过程的编号向它发送必要的信息?

I am implementing in MPI a program in which the main process (with rank=0) should be able to receive requests from the other processes who ask for values of variables that are only known by the root. If I make MPI_Recv(...) by the rank 0, I have to specify the rank of the process which sends request to the root, but i cannot control that since the processes don't run in the order 1,2,3,.... How can I receive the request from any rank and use the number of the emitting process to send it the necessary information?

推荐答案

这假定您正在使用C.C++和Fortran中有类似的概念.您只需将MPI_ANY_SOURCE指定为MPI_recv()中的源.状态结构包含消息的实际来源.

This assumes you are using C. There are similar concepts in C++ and Fortran. You would just specify MPI_ANY_SOURCE as the source in the MPI_recv(). The status struct contains the actual source of the message.

int buf[32];
MPI_Status status;
// receive message from any source
MPI_recv(buf, 32, MPI_INT, MPI_ANY_SOURCE, MPI_ANY_TAG, MPI_COMM_WORLD, &status);
int replybuf[];
// send reply back to sender of the message received above
MPI_send(buf, 32, MPI_INT, status.MPI_SOURCE, tag, MPI_COMM_WORLD);

这篇关于来自未知来源的MPI接收的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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