if (id != 0) { MPI_Send(& pi, 1, MPI_DOUBLE, 0,0 MPI_COMM_WORLD); } else { double tmp; for(int i=1; i < world_rank; ++i) { MPI_RECV(& tmp; 1, MPI_DOUBLE, i,0, MPI_COMM_WORLD); } pi += tmp; }
if (2*id+2 < world_size) { MPI_RECV(tmp1,,2*id+2, ) ; MPI_RECV(tmp2,,2*id+1, ) ; snd = tmp1+tmp2+myvalue; else if (2*id+1 < world_size) { MPI_RECV(tmp1,,2*id+1, ) ; snd = tmp1+myvalue; } else { snd = myvalue } if (id != 0) { MPI_Send(snd, ... (id-1)/2); }
int MPI_Bcast(void *buffer, int count, MPI_Datatype datatype, int root, MPI_Comm comm)
int MPI_Reduce(const void *sendbuf, void *recvbuf, int count,
MPI_Datatype datatype, MPI_Op op, int root, MPI_Comm comm)
int MPI_Scatter(const void *sendbuf, int sendcount, MPI_Datatype sendtype,
void *recvbuf, int recvcount, MPI_Datatype recvtype, int root,
MPI_Comm comm)
int MPI_Gather(const void *sendbuf, int sendcount, MPI_Datatype sendtype,
void *recvbuf, int recvcount, MPI_Datatype recvtype, int root,
MPI_Comm comm)
and ALL_GATHER , along with SCATTER