代码之家  ›  专栏  ›  技术社区  ›  AFS

MPI_Bcast所有进程发送到进程的所有其余部分

mpi c
  •  0
  • AFS  · 技术社区  · 7 年前

    #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);

    1 回复  |  直到 7 年前
        1
  •  0
  •   Gilles Gouaillardet    7 年前

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

    MPI_Bcast() (由于消息非常小,这有点不太可能,尽管您不应该认为这是理所当然的)。如果它不这样做,它肯定会阻塞 MPI_Recv()

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

    你要么需要一个循环 MPI_Bcast() MPI_Alltoallv()