1 /* Copyright (c) 2009-2021. 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. */
13 int main(int argc, char *argv[])
18 MPI_Init(&argc, &argv);
19 int maxlen = argc >= 2 ? atoi(argv[1]) : 1;
21 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
23 MPI_Comm_dup(MPI_COMM_WORLD, &dup);
24 MPI_Comm_size(MPI_COMM_WORLD, &size);
25 MPI_Comm_set_errhandler(dup, MPI_ERRORS_RETURN);
27 int* sb = (int*)calloc(size * maxlen, sizeof(int));
28 int* rb = (int*)calloc(size * maxlen+rank, sizeof(int));
30 for (int i = 0; i < size * maxlen; ++i) {
31 sb[i] = rank*size + i;
35 int status = MPI_Allreduce(sb, rb, size * maxlen, MPI_INT, MPI_SUM, dup);
37 if (rank == 0 && status != MPI_SUCCESS) {
38 printf("all_to_all returned %d\n", status);
41 //Do not free dup and rb/sb