Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Fix copyright headers
[simgrid.git] / src / smpi / sample / reduce.c
1 /* Copyright (c) 2007, 2009, 2010. The SimGrid Team.
2  * All rights reserved.                                                     */
3
4 /* This program is free software; you can redistribute it and/or modify it
5   * under the terms of the license (GNU LGPL) which comes with this package. */
6
7 #include <stdio.h>
8 #include <mpi.h>
9
10 int main (int argc, char **argv) {
11   int size, rank;
12   int root=0;
13   int value = 1;
14   int sum=-99;
15
16   double start_timer;
17
18
19   MPI_Init(&argc, &argv);
20   MPI_Comm_size(MPI_COMM_WORLD, &size);
21   MPI_Comm_rank(MPI_COMM_WORLD, &rank);
22
23   start_timer = MPI_Wtime();
24
25   printf("rank %d has value %d\n", rank, value);
26   MPI_Reduce(&value, &sum, 1, MPI_INT, MPI_SUM, root, MPI_COMM_WORLD);
27   if ( rank == root) {
28           printf("On root: sum=%d\n",sum);
29             printf("Elapsed time=%lf s\n", MPI_Wtime()-start_timer);
30   }
31   MPI_Finalize();
32   return 0;
33 }