MPI菌种:根进程不沟通,子进程 [英] MPI Spawn: root process does not communicate to child processes

查看:134
本文介绍了MPI菌种:根进程不沟通,子进程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

(初级问题)我试图产卵动态使用MPI_Comm_Spawn进程,然后广播消息的子进程,但程序从根进程给孩子广播站。我从以下 http://www.mpi-forum.org/docs/docs.html,但我不能使它发挥作用。任何人可以帮助我吗?

(Beginner question) I'm trying to spawn processes dynamically using MPI_Comm_Spawn and then broadcast a message to the child processes, but the program stops in the broadcast from the root process to the children. I'm following the documentation from http://www.mpi-forum.org/docs/docs.html but i can't make it work. Can anybody help me please?

#include <stdio.h>
#include <mpi.h>

int main(int argc, char *argv[])
{
    MPI_Init(&argc, &argv);
    MPI_Comm parentcomm;

    MPI_Comm_get_parent( &parentcomm );

    if (parentcomm == MPI_COMM_NULL) {
        MPI_Comm intercomm;
        MPI_Status status;
        char msg_rec[1024];
        char msg_send[1024];
        int size, i;

        int np = (argc > 0) ? atoi(argv[1]) : 3;

        printf("Spawner will spawn %d processes\n", np);
        MPI_Comm_spawn( argv[0], MPI_ARGV_NULL, np, MPI_INFO_NULL, 0, MPI_COMM_SELF, &intercomm, MPI_ERRCODES_IGNORE );
        MPI_Comm_size(intercomm, &size);

        sprintf(msg_send, "Hello!");
        printf("Spawner will broadcast '%s'\n", msg_send);
        MPI_Bcast( (void*)msg_send, 1024, MPI_CHAR, 0, intercomm);

        printf("Spawner will receive answers\n");
        for (i=0; i < size; i++) {
            MPI_Recv( (void*)msg_rec, 1024, MPI_CHAR, i, MPI_ANY_TAG, intercomm, &status);
            printf("Spawner received '%s' from rank %d\n", msg_rec, i);
        };       

    } else {
        int rank, size;
        char msg_rec[1024];
        char msg_send[1024];

        MPI_Comm_rank(parentcomm, &rank);
        MPI_Comm_size(parentcomm, &size);

        printf("  Rank %d ready\n", rank);

        MPI_Bcast( (void*)msg_rec, 1024, MPI_CHAR, 0, parentcomm);

        printf("  Rank %d received '%s' from broadcast!\n", rank, msg_rec);
        sprintf(msg_send, "Hi there from rank %d!\n", rank);
        MPI_Send( (void*)msg_send, 1024, MPI_CHAR, 0, rank, parentcomm);
    };
    MPI_Finalize();
    return 0;
};

我不知道它的问题,但我使用Ubuntu 11.10和Hidra流程管理器。

I don't know if it matters, but I'm using ubuntu 11.10 and Hidra Process Manager.

推荐答案

由于@suszterpatt指出的那样,你都带有Intercommunicator(不是Intracommunicator)的工作。知道了这一点,看着 MPI_Bcast ,我们看到:

As @suszterpatt pointed out, your are working with an "Intercommunicator" (not a "Intracommunicator"). Knowing this and looking at MPI_Bcast, we see:

如果COMM是一个intercommunicator的话,则涉及到intercommunicator所有进程,但有一组(A组)定义根进程。另一组(B组)中的所有进程传递参数的根,这是根的A组根通过根值MPI_ROOT等级相同的值。 A组所有其他进程传递值MPI_PROC_NULL根。数据从根到B组的所有进程广播接收B组进程的缓冲参数必须与根的发送缓冲区的说法是一致的。

If comm is an intercommunicator, then the call involves all processes in the intercommunicator, but with one group (group A) defining the root process. All processes in the other group (group B) pass the same value in argument root, which is the rank of the root in group A. The root passes the value MPI_ROOT in root. All other processes in group A pass the value MPI_PROC_NULL in root. Data is broadcast from the root to all processes in group B. The receive buffer arguments of the processes in group B must be consistent with the send buffer argument of the root.

这意味着你只需要替换与广播呼叫父:

This means that you need only replace the broadcast call in the parent with:

MPI_Bcast( (void*)msg_send, 1024, MPI_CHAR, MPI_ROOT, intercomm);

一些其他错误:


  • 在参数的数量的检查应 ARGC&GT; 1

  • MPI_Comm_size(的InterComm,&安培;大小)将返回 1 。您将要使用 MPI_Comm_remote_size(的InterComm,&安培;大小)。而不是

  • The check on the number of arguments should be argc > 1.
  • MPI_Comm_size(intercomm, &size) will return 1. You'll want to use MPI_Comm_remote_size(intercomm, &size) instead.

这篇关于MPI菌种:根进程不沟通,子进程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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