Logo AND Algorithmique Numérique Distribuée

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