1 /* Copyright (c) 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. */
7 #include "colls_private.h"
9 // Allgather-Non-Topoloty-Scecific-Logical-Ring algorithm
11 smpi_coll_tuned_allgather_NTSLR(void *sbuf, int scount, MPI_Datatype stype,
12 void *rbuf, int rcount, MPI_Datatype rtype,
15 MPI_Aint rextent, sextent;
17 int i, to, from, rank, size;
18 int send_offset, recv_offset;
19 int tag = COLL_TAG_ALLGATHER;
21 rank = smpi_comm_rank(comm);
22 size = smpi_comm_size(comm);
23 rextent = smpi_datatype_get_extent(rtype);
24 sextent = smpi_datatype_get_extent(stype);
26 // irregular case use default MPI fucntions
27 if (scount * sextent != rcount * rextent) {
28 XBT_WARN("MPI_allgather_NTSLR use default MPI_allgather.");
29 smpi_mpi_allgather(sbuf, scount, stype, rbuf, rcount, rtype, comm);
34 to = (rank + 1) % size;
35 from = (rank + size - 1) % size;
37 //copy a single segment from sbuf to rbuf
38 send_offset = rank * scount * sextent;
40 smpi_mpi_sendrecv(sbuf, scount, stype, rank, tag,
41 (char *)rbuf + send_offset, rcount, rtype, rank, tag,
45 //start sending logical ring message
46 int increment = scount * sextent;
47 for (i = 0; i < size - 1; i++) {
48 send_offset = ((rank - i + size) % size) * increment;
49 recv_offset = ((rank - i - 1 + size) % size) * increment;
50 smpi_mpi_sendrecv((char *) rbuf + send_offset, scount, stype, to, tag + i,
51 (char *) rbuf + recv_offset, rcount, rtype, from, tag + i,