0

I writed simple MPI programm using MPI_Bcast function, but I can't understand why my programm doesn't finish.

Here's code

#include "mpi.h"

int main(int argc, char* argv[]) {
    int ProcNum, ProcRank, RecvRank;
    MPI_Status Status;

    MPI_Init(&argc, &argv);
    MPI_Comm_size(MPI_COMM_WORLD, &ProcNum);
    MPI_Comm_rank(MPI_COMM_WORLD, &ProcRank);

    RecvRank = ProcRank;
    MPI_Bcast(&RecvRank, 1, MPI_INT, 0, MPI_COMM_WORLD);
    MPI_Recv(&RecvRank, 1, MPI_INT, MPI_ANY_SOURCE, MPI_ANY_TAG, MPI_COMM_WORLD, &Status);

    MPI_Finalize();
    return 0;
}
Mike_Device
  • 634
  • 2
  • 8
  • 25

1 Answers1

4

Your code has a deadlock. After your MPI_Bcast, you have an MPI_Recv with no matching MPI_Send, which causes your code to hang. I assume from the way you've asked your question that you think you need an MPI_Recv to receive information sent via MPI_Bcast, but that is not correct. The MPI_Bcast command by itself (without the MPI_Recv afterwards) will achieve what you want.

wolfPack88
  • 4,163
  • 4
  • 32
  • 47