-1

I am distributing adjacency matrix row by row to the processes using MPI_Send and MPI_Recv functions. I used MPI_Barrier but the program is getting stuck! How do I wait till all the processes get their part of a matrix?

/* 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

Error message:

Process 0 reading the input file.. Number of nodes = 100 Process 0
done reading.. Fatal error in PMPI_Barrier: Message truncated, error
stack: PMPI_Barrier(426)...................:
MPI_Barrier(MPI_COMM_WORLD) failed
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): Message truncated; 8 bytes
received but buffer size is 1

Wesley Bland
  • 8,816
  • 3
  • 44
  • 59
Dips
  • 11
  • 1

1 Answers1

0

I'm not too sure of what your "adjacency matrix" looks like and how is must be distributed, but I guess this is a job for MPI_Scatter() rather than a series of MPI_Bcast()...

Gilles
  • 9,269
  • 4
  • 34
  • 53
  • the code is given to me and I have to just fill in the missing places. Here I am stucked where there is a missing place – Dips Aug 28 '15 at 09:27
  • // Wait till all the processes have their assigned parts of the matrix. – Dips Aug 28 '15 at 09:27