MPI_Bcast segmentation fault

c, mpi, parallel-processing

Solution

If you want to receive the data in a vector other than the one used by root process, then you should do something like this (pseudocode):

if (THIS PROCESS IS ROOT) {
    MPI_Bcast(xd_sim_send, Nooflines_Sim, MPI_FLOAT, root, MPI_COMM_WORLD);
} else {
    MPI_Bcast(xd_sim_recv, Numlines_Sim, MPI_FLOAT, root, MPI_COMM_WORLD);
}

without the `&`, because the variables `xd_sim_send` `xd_sim_recv` are already pointers, that is what `MPI_Bcast` needs.

Problem

I am broadcasting a pointer to an array ``` MPI_Bcast(&xd_sim_send, Nooflines_Sim, MPI_FLOAT, root, MPI_COMM_WORLD); ``` from process 0 and receiving this broadcast from processes other than 0 ``` MPI_Bcast(&xd_sim_recv, Nooflines_Sim, MPI_FLOAT, root, MPI_COMM_WORLD); ``` I get segmentation fault 11 when I try to read the received value. Like this ``` for(i=0; i<Numlines_Sim; i++) printf("%f\n",xd_sim_recv[i]);fflush(stdout); ``` What is wrong here, Could you please help me fix it?

Original source