Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Update copyright lines for 2022.
[simgrid.git] / teshsuite / smpi / coll-allreduce-with-leaks / coll-allreduce-with-leaks.c
1 /* Copyright (c) 2009-2022. 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 int main(int argc, char *argv[])
14 {
15   int rank;
16   int size;
17
18   MPI_Init(&argc, &argv);
19   int maxlen = argc >= 2 ? atoi(argv[1]) : 1;
20
21   MPI_Comm_rank(MPI_COMM_WORLD, &rank);
22   MPI_Comm dup;
23   MPI_Comm_dup(MPI_COMM_WORLD, &dup);
24   MPI_Comm_size(MPI_COMM_WORLD, &size);
25   MPI_Comm_set_errhandler(dup, MPI_ERRORS_RETURN);
26
27   int* sb = (int*)calloc(size * maxlen, sizeof(int));
28   int* rb = (int*)calloc(size * maxlen+rank, sizeof(int));
29
30   for (int i = 0; i < size * maxlen; ++i) {
31     sb[i] = rank*size + i;
32     rb[i] = 0;
33   }
34
35   int status = MPI_Allreduce(sb, rb, size * maxlen, MPI_INT, MPI_SUM, dup);
36
37   if (rank == 0 && status != MPI_SUCCESS) {
38     printf("all_to_all returned %d\n", status);
39     fflush(stdout);
40   }
41   //Do not free dup and rb/sb
42   MPI_Finalize();
43   return EXIT_SUCCESS;
44 }