Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Restructure teshsuite simdag
[simgrid.git] / teshsuite / smpi / gather_coll.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 rank, size;
21   int i;
22   int *sb;
23   int *rb;
24   int status;
25
26   int root = 0;
27
28   MPI_Init(&argc, &argv);
29   MPI_Comm_rank(MPI_COMM_WORLD, &rank);
30   MPI_Comm_size(MPI_COMM_WORLD, &size);
31
32   int count = 2;
33   sb = (int *) xbt_malloc(count * sizeof(int));
34   rb = (int *) xbt_malloc(count * size * sizeof(int));
35   
36   for (i = 0; i < count; ++i)
37     sb[i] = rank * count + i;
38   for (i = 0; i < count * size; ++i)  
39     rb[i] = 0;
40
41   printf("[%d] sndbuf=[", rank);
42   for (i = 0; i < count; i++)
43     printf("%d ", sb[i]);
44   printf("]\n");
45
46   status = MPI_Gather(sb, count, MPI_INT, rb, count, MPI_INT, root, MPI_COMM_WORLD);
47
48   if (rank == root) {
49   printf("[%d] rcvbuf=[", rank);
50   for (i = 0; i < count * size; i++)
51     printf("%d ", rb[i]);
52   printf("]\n");
53
54
55     if (status != MPI_SUCCESS) {
56       printf("allgather returned %d\n", status);
57       fflush(stdout);
58     }
59   }
60   free(sb);
61   free(rb);
62   MPI_Barrier(MPI_COMM_WORLD);
63   MPI_Finalize();
64   return (EXIT_SUCCESS);
65 }