-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbcast.c
More file actions
34 lines (29 loc) · 819 Bytes
/
Copy pathbcast.c
File metadata and controls
34 lines (29 loc) · 819 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include <mpi.h>
#include <stdio.h>
#define DEBUG
#include <mpi_samples.h>
static void bcast(int _) {
int rank, world;
int el = 0;
int els[] = {3,1,4,7,1,5,1,8};
MPI_Init(NULL, NULL);
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
MPI_Comm_size(MPI_COMM_WORLD, &world);
if (rank == 0) {
el = 8;
}
LOG_WITH_RANK("before: %d\n", el);
MPI_Bcast(&el, 1, MPI_INT, 0, MPI_COMM_WORLD);
LOG_WITH_RANK("after: %d\n", el);
MPI_Barrier(MPI_COMM_WORLD);
if (rank == 0) {
printf("sync'd");
}
el = 0;
LOG_WITH_RANK("before: %d\n", el);
MPI_Scatter(els, 1, MPI_INT, &el, 1, MPI_INT, 0, MPI_COMM_WORLD);
MPI_Barrier(MPI_COMM_WORLD);
LOG_WITH_RANK("after: %d\n", el);
MPI_Finalize();
}
SAMPLE(bcast, 0)