Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Enum ResultStatus: valid is not a valid value. Use value.
[simgrid.git] / teshsuite / smpi / coll-allgatherv / coll-allgatherv.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 int main(int argc, char *argv[])
19 {
20   int i;
21   int rank;
22   int size;
23   int status;
24
25   MPI_Init(&argc, &argv);
26   MPI_Comm_rank(MPI_COMM_WORLD, &rank);
27   MPI_Comm_size(MPI_COMM_WORLD, &size);
28
29   int* recv_counts = (int *) xbt_malloc(size * sizeof(int));
30   int* recv_disps = (int *) xbt_malloc(size * sizeof(int));
31
32   int recv_sb_size = 0;
33   for (i = 0; i < size; i++) {
34     recv_counts[i] = i + 1;
35     recv_disps[i] = recv_sb_size;
36     recv_sb_size += i + 1;
37   }
38
39   int* sb = (int *) xbt_malloc(recv_counts[rank] * sizeof(int));
40   int* rb = (int *) xbt_malloc(recv_sb_size * sizeof(int));
41
42   printf("[%d] sndbuf=[", rank);
43   for (i = 0; i < recv_counts[rank]; i++){
44     sb[i] = recv_disps[rank] + i;
45     printf("%d ", sb[i]);
46   }
47   printf("]\n");
48
49   for (i = 0; i < recv_sb_size; i++)
50     rb[i] = -1;
51
52   status = MPI_Allgatherv(sb, recv_counts[rank], MPI_INT, rb, recv_counts, recv_disps, MPI_INT, MPI_COMM_WORLD);
53
54   printf("[%d] rcvbuf=[", rank);
55   for (i = 0; i < recv_sb_size; i++)
56     printf("%d ", rb[i]);
57   printf("]\n");
58
59   if (rank == 0) {
60     if (status != MPI_SUCCESS) {
61       printf("allgatherv returned %d\n", status);
62       fflush(stdout);
63     }
64   }
65   xbt_free(sb);
66   xbt_free(rb);
67   xbt_free(recv_counts);
68   xbt_free(recv_disps);
69   MPI_Finalize();
70   return (EXIT_SUCCESS);
71 }