Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download

📚 The CoCalc Library - books, templates and other resources

132937 views
License: OTHER
1
void my_bcast(void* data, int count,
2
MPI_Datatype type,
3
int root, MPI_Comm comm) {
4
5
int my_rank, comm_size;
6
MPI_Comm_rank(comm, &my_rank);
7
MPI_Comm_size(comm, &comm_size);
8
9
if (my_rank == root) {
10
// If we are the root process, send our
11
// data to every one
12
for (int i = 0; i < comm_size; i++) {
13
if (i != my_rank) {
14
MPI_Send(data, count,
15
type, i, 0, comm);
16
}
17
}
18
} else {
19
// If we are a receiver process,
20
// receive the data from root
21
MPI_Recv(data, count, type, root, 0,
22
comm, MPI_STATUS_IGNORE);
23
}
24
}
25
26