c++ - Difficulty with MPI_Bcast: how to ensure that "correct" root is broadcasting -


i relatively new mpi (with c), , having trouble using mpi_bcast send int processes.

in code, decide rank root within loop, different processes responsible different element of loop. then, want bcast result root processes, except non-root processes not know expect bcast from, not receive it.

the code block looks this:

for (ix=start; ix<end; ix++) //start , end starting row , ending row each processes, defined earlier    (int iy=1; iy<nn; iy++)      // calculations      if (some condition)        int bcastroot = rank;  // initialized above       int x = 111;   // initialized above      else       //do other calculations    end end  mpi_bcast(&x, 1, mpi_int, bcastroot, comm);  // remainder of code , mpi_finalize 

when execute code, whatever bcastroot default (value non-root processes) competes root, x not broadcast correctly. not know value of x nor can predict root beforehand, cannot define in advance.

i have tried initializing bcastroot = -1, setting rank, not work. there way can bcast value without setting root processes?

thanks, jonzor

there no way mpi_bcast receivers don't know root is. if know there 1 root, can first mpi_allreduce agree on it:

int root, maybe_root; int i_am_root = ...; maybe_root = (i_am_root ? rank : 0); mpi_allreduce(&maybe_root, &root, 1, mpi_int, mpi_max, mpi_comm_world); 

then every rank know same root , can broadcast.


Comments

Popular posts from this blog

jasper reports - Fixed header in Excel using JasperReports -

media player - Android: mediaplayer went away with unhandled events -

python - ('The SQL contains 0 parameter markers, but 50 parameters were supplied', 'HY000') or TypeError: 'tuple' object is not callable -