Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
EXIT_SUCCESS/EXIT_FAILURE are standard C defined in stdlib.h.
[simgrid.git] / teshsuite / smpi / coll-alltoall / coll-alltoall.c
1 /* Copyright (c) 2009-2010, 2013-2018. 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 rank;
16   int size;
17   int i;
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* sb = (int *) xbt_malloc(size * sizeof(int) * 2);
25   int* rb = (int *) xbt_malloc(size * sizeof(int) * 2);
26
27   for (i = 0; i < size; ++i) {
28     sb[i] = rank*size + i;
29     rb[i] = 0;
30   }
31
32   printf("[%d] sndbuf=[", rank);
33   for (i = 0; i < size; i++)
34     printf("%d ", sb[i]);
35   printf("]\n");
36
37   status = MPI_Alltoall(sb, 1, MPI_INT, rb, 1, MPI_INT, MPI_COMM_WORLD);
38
39   printf("[%d] rcvbuf=[", rank);
40   for (i = 0; i < size; i++)
41     printf("%d ", rb[i]);
42   printf("]\n");
43
44   if (rank == 0 && status != MPI_SUCCESS) {
45     printf("all_to_all returned %d\n", status);
46     fflush(stdout);
47   }
48   xbt_free(sb);
49   xbt_free(rb);
50   MPI_Finalize();
51   return (EXIT_SUCCESS);
52 }