1 /* Copyright (c) 2009-2010, 2013-2014. The SimGrid Team.
2 * All rights reserved. */
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. */
14 #define EXIT_SUCCESS 0
15 #define EXIT_FAILURE 1
18 int main(int argc, char *argv[])
22 int *recv_counts, *recv_disps;
26 MPI_Init(&argc, &argv);
27 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
28 MPI_Comm_size(MPI_COMM_WORLD, &size);
30 recv_counts = (int *) xbt_malloc(size * sizeof(int));
31 recv_disps = (int *) xbt_malloc(size * sizeof(int));
34 for (i = 0; i < size; i++) {
35 recv_counts[i] = i + 1;
36 recv_disps[i] = recv_sb_size;
37 recv_sb_size += i + 1;
40 sb = (int *) xbt_malloc(recv_counts[rank] * sizeof(int));
41 rb = (int *) xbt_malloc(recv_sb_size * sizeof(int));
43 for (i = 0; i < recv_counts[rank]; ++i)
44 sb[i] = recv_disps[rank] + i;
45 for (i = 0; i < recv_sb_size; ++i)
48 printf("[%d] sndbuf=[", rank);
49 for (i = 0; i < recv_counts[rank]; i++)
53 status = MPI_Allgatherv(sb, recv_counts[rank], MPI_INT, rb, recv_counts, recv_disps, MPI_INT, MPI_COMM_WORLD);
55 printf("[%d] rcvbuf=[", rank);
56 for (i = 0; i < recv_sb_size; i++)
61 if (status != MPI_SUCCESS) {
62 printf("allgatherv returned %d\n", status);
71 return (EXIT_SUCCESS);