Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
608c5c35981731ab03725c62baa98d1d146bf900
[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    int quiet = 0;
9
10   MPI_Init(&argc, &argv);
11   MPI_Comm_size(MPI_COMM_WORLD, &size);
12   MPI_Comm_rank(MPI_COMM_WORLD, &rank);
13
14    if (argc > 1 && !strcmp(argv[1],"-q")) 
15      quiet=1;
16    
17   start_timer = MPI_Wtime();
18
19   if (0 == rank) {
20     value = 17;
21   }
22   printf("node %d has value %d before broadcast\n", rank, value);
23   MPI_Bcast(&value, 1, MPI_INT, 0, MPI_COMM_WORLD);
24   printf("node %d has value %d after broadcast\n", rank, value);
25
26   MPI_Barrier( MPI_COMM_WORLD );
27   if ( 0 == rank && !quiet)
28             printf("Elapsed time on rank %d: %lf s\n", rank, MPI_Wtime()-start_timer);
29   MPI_Finalize();
30   return 0;
31 }