Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
SMPI: Add an option to display the timing at the end of the simulation (need to turn...
[simgrid.git] / examples / smpi / bcast.c
1 #include <stdio.h>
2 #include <mpi.h>
3
4 int main (int argc, char **argv) {
5   int size, rank;
6   int value = 3;
7   double start_timer;
8
9   MPI_Init(&argc, &argv);
10   MPI_Comm_size(MPI_COMM_WORLD, &size);
11   MPI_Comm_rank(MPI_COMM_WORLD, &rank);
12
13   start_timer = MPI_Wtime();
14
15   if (0 == rank) {
16     value = 17;
17   }
18   printf("node %d has value %d\n", rank, value);
19   MPI_Bcast(&value, 1, MPI_INT, 0, MPI_COMM_WORLD);
20   printf("node %d has value %d\n", rank, value);
21
22   MPI_Barrier( MPI_COMM_WORLD );
23   if ( 0 == rank)
24             printf("Elapsed time on rank %d: %lf s\n", rank, MPI_Wtime()-start_timer);
25   MPI_Finalize();
26   return 0;
27 }