【问题标题】:How to wait till all process receive particular data using MPI blocking fucntions?如何使用 MPI 阻塞函数等到所有进程接收到特定数据?
【发布时间】:2015-11-22 19:33:14
【问题描述】:

我正在使用MPI_SendMPI_Recv 函数将邻接矩阵逐行分配给进程。我使用了MPI_Barrier,但程序卡住了!我如何等到所有进程都获得矩阵的一部分?

/* Distribute the adjacency matrix */
if( my_rank == 0) {
    int row_start_l, row_end_l, dest_l;

    for(dest_l=1; dest_l < comm_size; dest_l++) {

        row_start_l = dest_l*(num_nodes/comm_size);
        if( dest_l != (comm_size - 1) ) {
            row_end_l = (dest_l + 1)*(num_nodes/comm_size) - 1;
        }
        else {
            row_end_l = num_nodes - 1;
        }

        for(i = row_start_l; i <= row_end_l; i++) {
            MPI_Send(&g.matrix[i][1], 1, MPI_INT, dest_l, TAG_AM_DATA, MPI_COMM_WORLD);
            // Send Adjacency matrix to appropriate destinations. You can first send the appropriate size
            MPI_Send(&g.matrix[i], (g.matrix[i][1])+2, MPI_INT, dest_l, TAG_AM_DATA, MPI_COMM_WORLD);
        }
    }
    for(j=0; j < num_nodes; ) {
        for(k=0; k < 120; k++) {
            if(j >= num_nodes) {
                break;
            }
            sendrecv_buffer_double[k] = g.column_denominator[j];
            j++;
        }
        MPI_Bcast(&k, 1, MPI_DOUBLE, 0, MPI_COMM_WORLD);
        MPI_Bcast(&sendrecv_buffer_double[0], k, MPI_DOUBLE, 0, MPI_COMM_WORLD);
    } cnt++;
}
else {

    int recv_count;
    int recvd;
    cnt++;
    adj_matrix = (int **)malloc(my_num_rows*sizeof(int*));
    for(i=0; i < my_num_rows; i++) {

        MPI_Recv(&recv_count, 1, MPI_INT, 0, TAG_AM_DATA, MPI_COMM_WORLD, &status);

        adj_matrix[i] = (int *)malloc((2 + recv_count)*sizeof(int));

        // Receive adjacency matrix from root.
        MPI_Recv(&adj_matrix[i], 2+recv_count, MPI_INT, 0, TAG_AM_DATA, MPI_COMM_WORLD, &status);
    }

    recvd = 0;
    while(recvd < num_nodes) {
        MPI_Bcast(&recv_count, 1, MPI_DOUBLE, 0, MPI_COMM_WORLD);
        MPI_Bcast(&g.column_denominator[recvd], recv_count, MPI_DOUBLE, 0, MPI_COMM_WORLD);
        recvd += recv_count;
    }
}

// Wait till all the processes have their assigned parts of the matrix.
MPI_Barrier(MPI_COMM_WORLD);//I am getting error here

错误信息:

进程 0 正在读取输入文件。节点数 = 100 进程 0
完成阅读.. PMPI_Barrier 中的致命错误:消息被截断,错误
堆栈:PMPI_Barrier(426).......:
MPI_Barrier(MPI_COMM_WORLD) 失败
MPIR_Barrier_impl(308).......................:
MPIR_Bcast_impl(1369)................:
MPIR_Bcast_intra(1199).......:
MPIR_Bcast_binomial(149)............:
MPIC_Recv(109).......................:
MPIDI_CH3U_Request_unpack_uebuf(605):消息被截断; 8 个字节
收到但缓冲区大小为 1

【问题讨论】:

标签: mpi openmpi


【解决方案1】:

我不太确定您的“邻接矩阵”是什么样的以及必须如何分配,但我想这是MPI_Scatter() 的工作,而不是一系列MPI_Bcast()...

【讨论】:

  • 代码给了我,我只需要填写缺失的地方。在这里,我被困在缺少的地方
  • // 等到所有进程都有分配的矩阵部分。
猜你喜欢
  • 1970-01-01
  • 2017-09-10
  • 2012-02-26
  • 2012-08-24
  • 1970-01-01
  • 2011-05-03
  • 2017-04-15
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多