Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Restructure teshsuite smpi
[simgrid.git] / teshsuite / smpi / allreduce / allreduce_coll.c
1 /* Copyright (c) 2009-2010, 2013-2014. 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 <stdlib.h>
8 #include <stdio.h>
9 #include <string.h>
10 #include <errno.h>
11 #include "mpi.h"
12
13 #ifndef EXIT_SUCCESS
14 #define EXIT_SUCCESS 0
15 #define EXIT_FAILURE 1
16 #endif
17
18 //define MAXLEN  300000
19
20 int main(int argc, char *argv[])
21 {
22   int rank, size;
23   int i;
24   int *sb;
25   int *rb;
26   int status;
27   int mult=1;
28
29   MPI_Init(&argc, &argv);
30   int maxlen = argc >= 2 ? atoi(argv[1]) : 1;
31
32   MPI_Comm_rank(MPI_COMM_WORLD, &rank);
33   MPI_Comm_size(MPI_COMM_WORLD, &size);
34   if (maxlen>1)mult=size;
35   sb = (int *) xbt_malloc(size *maxlen * sizeof(int));
36   rb = (int *) xbt_malloc(size *maxlen * sizeof(int));
37   
38   for (i = 0; i < size *maxlen; ++i) {
39     sb[i] = rank*size + i;
40     rb[i] = 0;
41   }
42
43   printf("[%d] sndbuf=[", rank);
44   for (i = 0; i < size *mult; i++)
45     printf("%d ", sb[i]);
46   printf("]\n");
47
48   status = MPI_Allreduce(sb, rb, size *maxlen, MPI_INT, MPI_SUM, MPI_COMM_WORLD);
49
50   printf("[%d] rcvbuf=[", rank);
51   for (i =  0; i < size *mult; i++)//do not print everything
52     printf("%d ", rb[i]);
53   printf("]\n");
54
55
56   if (rank == 0) {
57     if (status != MPI_SUCCESS) {
58       printf("all_to_all returned %d\n", status);
59       fflush(stdout);
60     }
61   }
62   free(sb);
63   free(rb);
64   MPI_Finalize();
65   return (EXIT_SUCCESS);
66 }