【问题标题】:MPI_Bcast all processes sends to all the rest of processMPI_Bcast 所有进程发送到所有其余进程
【发布时间】:2018-11-18 21:35:05
【问题描述】:

我试图让每个进程都以这种方式广播到所有其他进程

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

int main(argc,argv)
int argc;
char **argv;
{

  int MyProc, size,tag=1;
  int msg_recpt;
  MPI_Status status;

  MPI_Init(&argc, &argv);
  MPI_Comm_rank(MPI_COMM_WORLD, &MyProc);
  MPI_Comm_size(MPI_COMM_WORLD, &size);

  printf("Process # %d started \n", MyProc);
  MPI_Barrier(MPI_COMM_WORLD);


    MPI_Bcast( &MyProc, 1, MPI_INT, MyProc, MPI_COMM_WORLD);
    MPI_Recv(&msg_recpt, 1, MPI_CHAR, MyProc, tag, MPI_COMM_WORLD, &status);
    printf("Proc #%d recv'd message from Proc #%d \n", MyProc, msg_recpt) ;


  printf("Finishing proc %d\n", MyProc);

  MPI_Barrier(MPI_COMM_WORLD);
  MPI_Finalize();
}

我需要在MPI_Recv 之后的消息上显示发件人进程,但我认为它被阻止执行未到达printf("Finishing proc %d\n", MyProc);

【问题讨论】:

    标签: c mpi


    【解决方案1】:

    MPI_Bcast() 是一个集体操作。通信器中的所有 MPI 任务都必须使用匹配的签名(例如计数和数据类型)调用它,并且它们都必须使用相同的 root 任务。

    您的代码可能会在MPI_Bcast() 中阻塞(因为消息非常小,这有点不太可能,尽管您不应该认为这是理所当然的)。如果没有,它肯定会阻塞在MPI_Recv(),因为没有匹配的发送操作。

    集体操作和点对点操作在 MPI 中是独立的。

    你要么需要MPI_Bcast()的循环,要么如果你有足够的内存来接收所有等级的消息,你可以使用MPI_Alltoallv()一次。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-12-04
      • 1970-01-01
      • 2016-08-21
      • 2021-09-27
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多