3
votes

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?

2
How are you allocating the variable xd_sim_recv in the processes other than root?Nicolás Ozimica
float *xd_sim_send, *xd_sim_recv; xd_sim_send = (float *)calloc( Nooflines_Sim, sizeof(float) ); xd_sim_recv = (float *)calloc( Numlines_Sim, sizeof(float));rkrara
Sorry typo, i meant xd_sim_recvrkrara
You don't need to give the address of the vectors, because those variables are already pointers. Just give them without &. See my answer below.Nicolás Ozimica

2 Answers

4
votes

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.

5
votes

It doesn't make sence to send a pointer, since that pointer will be invalid in the other parallel process, send the buffer instead:

MPI_Bcast(xd_sim_send, Nooflines_Sim, MPI_FLOAT, root, MPI_COMM_WORLD);