2
0
Fork 0
mirror of https://github.com/MartinThoma/LaTeX-examples.git synced 2025-04-25 14:28:05 +02:00
LaTeX-examples/documents/Programmierparadigmen/scripts/mpi/mpi-mybroadcast.c

19 lines
607 B
C
Raw Normal View History

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