【问题标题】:MPI_Barrier() gets blocked at the begginingMPI_Barrier() 在开始时被阻塞
【发布时间】:2020-01-30 09:33:48
【问题描述】:

我试图在执行开始时通过 MPI_Barrier 同步我的进程,但我的程序被阻止了。尽管如此,我看到所有进程都通过在上一条指令中的屏幕上打印来到达该行。

    int num_processes, packet_size, partner_rank; 
    double start_comm_time, end_comm_time, comm_time;
    comm_time = 0;
    if(argc==3) { 
        if (sscanf (argv[1], "%i", &num_processes) != 1) {
            fprintf(stderr, "error - parameter 1 not an integer");
        } else;
        if (sscanf (argv[2], "%i", &packet_size) != 1) {
            fprintf(stderr, "error - parameter 2 not an integer");
        } else;
     }
    else {
            printf("\n Usage: broadcast $count $packet_size");
            return 0; 
    }

    char buf_send[packet_size], buf_recv[packet_size];
    buf_send[0] = 0;

    // Initialize
    MPI_Init(NULL, NULL);

    int world_rank;

    MPI_Comm_rank(MPI_COMM_WORLD, &world_rank);
    int world_size;
    MPI_Comm_size(MPI_COMM_WORLD, &world_size);

    printf("\n Comm size %d \n", world_size);
    printf("\n Process %d before barrier \n", world_rank);
    // Time MPI_Bcast
    MPI_Barrier(MPI_COMM_WORLD);
    printf("\n Process %d after barrier \n", world_rank);
    start_comm_time = MPI_Wtime();
    MPI_Bcast(buf_send, packet_size, MPI_CHAR, 0, MPI_COMM_WORLD);
    printf("\n Process %d before second barrier \n", world_rank);
    MPI_Barrier(MPI_COMM_WORLD);
    end_comm_time = MPI_Wtime();

这是我在打印输出中得到的:

 Comm size 6 

 Process 0 before barrier 

 Comm size 6 

 Process 2 before barrier 

 Comm size 6 

 Process 3 before barrier 
 Comm size 6 

 Process 1 before barrier 

 Comm size 6 

 Process 4 before barrier 

 Comm size 6 

 Process 5 before barrier

【问题讨论】:

  • 您的程序没有问题。罪魁祸首可能是您的 mpi 安装。

标签: mpi


【解决方案1】:

我删除了程序的计时和MPI_Bcast 部分(因为它不完整),它在我的机器上运行良好,没有被阻塞。所以你的代码的其他部分可能有问题。

根据您的整个程序,我认为您的代码没有问题。问题可能是您的 mpi 环境。我还在我的机器上使用mpirun -n 6 ./xxx 6 1 运行它,这就是我得到的:

 Comm size 6 

 Process 0 before barrier 

 Comm size 6 

 Process 5 before barrier 

 Comm size 6 

 Process 2 before barrier 

 Comm size 6 

 Comm size 6 

 Process 1 before barrier 

 Process 3 before barrier 

 Comm size 6 

 Process 4 before barrier 

 Process 0 after barrier 

 Process 0 before second barrier 

 Process 1 after barrier 

 Process 1 before second barrier 

 Process 4 after barrier 

 Process 4 before second barrier 

 Process 5 after barrier 

 Process 5 before second barrier 

 Process 2 after barrier 

 Process 2 before second barrier 

 Process 3 after barrier 

 Process 3 before second barrier 

【讨论】:

  • 感谢您的尝试。我不认为这是由于代码的其他部分,因为如输出所示,Barrier 之前的语句对所有进程都执行,但如果您不介意尝试一下,我正在添加初始化部分代码:
  • 我已经用我的输出更新了我的答案。我认为您的代码没有问题。
  • 感谢您的回复。我要再次检查我的环境。
猜你喜欢
  • 2012-06-08
  • 2013-11-16
  • 2016-10-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-04-20
相关资源
最近更新 更多