2014-04-05 18:18:47 +02:00
|
|
|
void my_bcast(void* data, int count,
|
|
|
|
MPI_Datatype type,
|
2014-04-01 14:44:24 +02:00
|
|
|
int root, MPI_Comm comm) {
|
2014-04-05 18:18:47 +02:00
|
|
|
|
|
|
|
int my_rank, comm_size;
|
2014-04-01 14:44:24 +02:00
|
|
|
MPI_Comm_rank(comm, &my_rank);
|
|
|
|
MPI_Comm_size(comm, &comm_size);
|
2014-04-05 18:18:47 +02:00
|
|
|
|
2014-04-01 14:44:24 +02:00
|
|
|
if (my_rank == root) {
|
2014-04-05 18:18:47 +02:00
|
|
|
// If we are the root process, send our
|
|
|
|
// data to every one
|
2014-04-01 14:44:24 +02:00
|
|
|
for (int i = 0; i < comm_size; i++) {
|
|
|
|
if (i != my_rank) {
|
2014-04-05 18:18:47 +02:00
|
|
|
MPI_Send(data, count,
|
|
|
|
type, i, 0, comm);
|
2014-04-01 14:44:24 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
2014-04-05 18:18:47 +02:00
|
|
|
// If we are a receiver process,
|
|
|
|
// receive the data from root
|
|
|
|
MPI_Recv(data, count, type, root, 0,
|
|
|
|
comm, MPI_STATUS_IGNORE);
|
2014-04-01 14:44:24 +02:00
|
|
|
}
|
|
|
|
}
|