Take the 2-minute tour ×

I'm solving a problem in which one process do some calculation on a column and I'm saving that column in a temporary array and broadcasting it to all other processes using MPI_Bcast but always endings up in getting all zeros in the array in the receiving end.

Below is my code that I'm using:

//nProc = no of processors;
//helperA = 2D Array i.e. helperA[size][size]
// colK = 1D Array i.e. colK[size]

    if (k % nProc == rank) {
                    // One of the process will do this calculation
        int temp = 0;
        for (int j = k + 1; j < size; ++j) {
            helperA[j][k] = helperA[j][k]/helperA[k][k];
            colK[temp++] = helperA[j][k];

    MPI_Bcast(colK, size - k - 1, MPI_DOUBLE, rank, MPI_COMM_WORLD);    
    // After this other process should get the colK updated with the calculation

    for (int i = k + 1; i < size; ++i) {
        if (i % nProc == rank) {
            int temp = 0;
                                    // Here colK is always zero
                printf("%d %f \n", rank, colK[temp]);
                helperA[j][i] = helperA[j][i] - (colK[temp++] * helperA[k][i]);

I'm not sure what I am doing wrong here. Any help/suggestions please.

share|improve this question
add comment

1 Answer

up vote 1 down vote accepted

(I really don't love debugging code via text boxes, so I'll assume you've already done the basic checks to be sure that there's actually data in colK before you send it and that size-k-1 is the correct value on all ranks.)

The rank value you're passing into the MPI_BCAST call should be the rank of the "root" process. That is, the process which has all of the data to be broadcast. This argument must be the same for all calling processes. You code appears to pass the rank of each calling process, so everyone will be trying to communicate with a different root process.

share|improve this answer
Thanks. Yes, I've done the error checking and data is their but your point is valid I'll just check this and update you if this is the case. –  JackSparrow Oct 8 '13 at 15:10
This was the case :) Thank you so much for your help!! –  JackSparrow Oct 8 '13 at 15:15
add comment

Your Answer


