Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
have allreduce test work on much larger arrays to trigger segmentation in one algorithm
[simgrid.git] / teshsuite / smpi / allreduce_coll.c
1 /* Copyright (c) 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 <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
28   MPI_Init(&argc, &argv);
29   MPI_Comm_rank(MPI_COMM_WORLD, &rank);
30   MPI_Comm_size(MPI_COMM_WORLD, &size);
31
32   sb = (int *) xbt_malloc(size *MAXLEN * sizeof(int));
33   rb = (int *) xbt_malloc(size *MAXLEN * sizeof(int));
34   
35   for (i = 0; i < size *MAXLEN; ++i) {
36     sb[i] = rank*size + i;
37     rb[i] = 0;
38   }
39
40   printf("[%d] sndbuf=[", rank);
41   for (i = 0; i < size *size; i++)
42     printf("%d ", sb[i]);
43   printf("]\n");
44
45   status = MPI_Allreduce(sb, rb, size *MAXLEN, MPI_INT, MPI_SUM, MPI_COMM_WORLD);
46
47   printf("[%d] rcvbuf=[", rank);
48   for (i = 0; i < size *size; i++)//do not print everything
49     printf("%d ", rb[i]);
50   printf("]\n");
51
52
53   if (rank == 0) {
54     if (status != MPI_SUCCESS) {
55       printf("all_to_all returned %d\n", status);
56       fflush(stdout);
57     }
58   }
59   free(sb);
60   free(rb);
61   MPI_Finalize();
62   return (EXIT_SUCCESS);
63 }