Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Update copyright lines with new year.
[simgrid.git] / teshsuite / smpi / coll-allgatherv / coll-allgatherv.c
1 /* Copyright (c) 2009-2019. 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 i;
16   int rank;
17   int size;
18   int status;
19
20   MPI_Init(&argc, &argv);
21   MPI_Comm_rank(MPI_COMM_WORLD, &rank);
22   MPI_Comm_size(MPI_COMM_WORLD, &size);
23
24   int* recv_counts = (int *) xbt_malloc(size * sizeof(int));
25   int* recv_disps = (int *) xbt_malloc(size * sizeof(int));
26
27   int recv_sb_size = 0;
28   for (i = 0; i < size; i++) {
29     recv_counts[i] = i + 1;
30     recv_disps[i] = recv_sb_size;
31     recv_sb_size += i + 1;
32   }
33
34   int* sb = (int *) xbt_malloc(recv_counts[rank] * sizeof(int));
35   int* rb = (int *) xbt_malloc(recv_sb_size * sizeof(int));
36
37   printf("[%d] sndbuf=[", rank);
38   for (i = 0; i < recv_counts[rank]; i++){
39     sb[i] = recv_disps[rank] + i;
40     printf("%d ", sb[i]);
41   }
42   printf("]\n");
43
44   for (i = 0; i < recv_sb_size; i++)
45     rb[i] = -1;
46
47   status = MPI_Allgatherv(sb, recv_counts[rank], MPI_INT, rb, recv_counts, recv_disps, MPI_INT, MPI_COMM_WORLD);
48
49   printf("[%d] rcvbuf=[", rank);
50   for (i = 0; i < recv_sb_size; i++)
51     printf("%d ", rb[i]);
52   printf("]\n");
53
54   if (rank == 0 && status != MPI_SUCCESS) {
55     printf("allgatherv returned %d\n", status);
56     fflush(stdout);
57   }
58   xbt_free(sb);
59   xbt_free(rb);
60   xbt_free(recv_counts);
61   xbt_free(recv_disps);
62   MPI_Finalize();
63   return (EXIT_SUCCESS);
64 }