Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Document Stephane's last change (implement MPI_Wtime())
[simgrid.git] / examples / smpi / bcast.c
1 #include <stdio.h>
2 #include <mpi.h>
3
4 #define INIT_VALUE 3
5 #define TARGET_VALUE 42
6
7 int main (int argc, char **argv) {
8   int size, rank;
9   int value = INIT_VALUE;
10   MPI_Init(&argc, &argv);
11   MPI_Comm_size(MPI_COMM_WORLD, &size);
12   MPI_Comm_rank(MPI_COMM_WORLD, &rank);
13   if (0 == rank) {
14     value = TARGET_VALUE;
15   }
16   fprintf(stderr,"node %d has value %d before broadcast\n", rank, value);
17   MPI_Bcast(&value, 1, MPI_INT, 0, MPI_COMM_WORLD);
18   fprintf(stderr,"node %d has value %d after broadcast\n", rank, value);
19   if (value != TARGET_VALUE) {
20           fprintf(stderr,"node %d don't have the target value after broadcast!!\n", rank);
21           exit(1);
22   }
23   MPI_Finalize();
24   return 0;
25 }