X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/d47debaeffa6807956ee9cc7da90759efe49beda..6760cb07d6b57be16928d95339d71e57c4e24f36:/src/smpi/sample/reduce.c diff --git a/src/smpi/sample/reduce.c b/src/smpi/sample/reduce.c index 9fc0be2483..d939385bba 100644 --- a/src/smpi/sample/reduce.c +++ b/src/smpi/sample/reduce.c @@ -1,31 +1,33 @@ +/* Copyright (c) 2007, 2009, 2010. The SimGrid Team. + * All rights reserved. */ + +/* This program is free software; you can redistribute it and/or modify it + * under the terms of the license (GNU LGPL) which comes with this package. */ + #include -#include #include -int main(int argc, char *argv[]) { - int rank, size; - int i; - int *sendbuf, *recvbuf; +int main (int argc, char **argv) { + int size, rank; + int root=0; + int value = 1; + int sum=-99; + + double start_timer; + + MPI_Init(&argc, &argv); - MPI_Comm_rank(MPI_COMM_WORLD, &rank); MPI_Comm_size(MPI_COMM_WORLD, &size); - sendbuf = malloc(sizeof(int) * size); - recvbuf = malloc(sizeof(int) * size); - for (i = 0; i < size; i++) { - sendbuf[i] = 0; - recvbuf[i] = 0; - } - sendbuf[rank] = rank + 1; - MPI_Reduce(sendbuf, recvbuf, size, MPI_INT, MPI_SUM, 0, MPI_COMM_WORLD); - if (0 == rank) { - printf("nodes: ", rank); - for (i = 0; i < size; i++) { - printf("%d ", recvbuf[i]); - } - printf("\n"); + MPI_Comm_rank(MPI_COMM_WORLD, &rank); + + start_timer = MPI_Wtime(); + + printf("rank %d has value %d\n", rank, value); + MPI_Reduce(&value, &sum, 1, MPI_INT, MPI_SUM, root, MPI_COMM_WORLD); + if ( rank == root) { + printf("On root: sum=%d\n",sum); + printf("Elapsed time=%lf s\n", MPI_Wtime()-start_timer); } - free(sendbuf); - free(recvbuf); MPI_Finalize(); return 0; }