Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Change the prototype of xbt_thread_create(), sorry.
[simgrid.git] / examples / smpi / bcast.c
1 #include <stdio.h>
2 #include <mpi.h>
3
4 int main(int argc, char **argv)
5 {
6   int size, rank;
7   int value = 3;
8   double start_timer;
9   int quiet = 0;
10
11   MPI_Init(&argc, &argv);
12   MPI_Comm_size(MPI_COMM_WORLD, &size);
13   MPI_Comm_rank(MPI_COMM_WORLD, &rank);
14
15   if (argc > 1 && !strcmp(argv[1], "-q"))
16     quiet = 1;
17
18   start_timer = MPI_Wtime();
19
20   if (0 == rank) {
21     value = 17;
22   }
23   printf("node %d has value %d before broadcast\n", rank, value);
24   MPI_Bcast(&value, 1, MPI_INT, 0, MPI_COMM_WORLD);
25   printf("node %d has value %d after broadcast\n", rank, value);
26
27   MPI_Barrier(MPI_COMM_WORLD);
28   if (0 == rank && !quiet)
29     printf("Elapsed time on rank %d: %lf s\n", rank,
30            MPI_Wtime() - start_timer);
31   MPI_Finalize();
32   return 0;
33 }