Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Fix most of spelling mistakes in src/
[simgrid.git] / src / smpi / colls / allgather / allgather-NTSLR.cpp
1 /* Copyright (c) 2013-2020. 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 "../colls_private.hpp"
8
9 namespace simgrid{
10 namespace smpi{
11
12 // Allgather-Non-Topology-Specific-Logical-Ring algorithm
13 int
14 allgather__NTSLR(const void *sbuf, int scount, MPI_Datatype stype,
15                  void *rbuf, int rcount, MPI_Datatype rtype,
16                  MPI_Comm comm)
17 {
18   MPI_Aint rextent, sextent;
19   MPI_Status status;
20   int i, to, from, rank, size;
21   int send_offset, recv_offset;
22   int tag = COLL_TAG_ALLGATHER;
23
24   rank = comm->rank();
25   size = comm->size();
26   rextent = rtype->get_extent();
27   sextent = stype->get_extent();
28
29   // irregular case use default MPI functions
30   if (scount * sextent != rcount * rextent) {
31     XBT_WARN("MPI_allgather_NTSLR use default MPI_allgather.");
32     allgather__default(sbuf, scount, stype, rbuf, rcount, rtype, comm);
33     return MPI_SUCCESS;
34   }
35
36   // topo non-specific
37   to = (rank + 1) % size;
38   from = (rank + size - 1) % size;
39
40   //copy a single segment from sbuf to rbuf
41   send_offset = rank * scount * sextent;
42
43   Request::sendrecv(sbuf, scount, stype, rank, tag,
44                (char *)rbuf + send_offset, rcount, rtype, rank, tag,
45                comm, &status);
46
47
48   //start sending logical ring message
49   int increment = scount * sextent;
50   for (i = 0; i < size - 1; i++) {
51     send_offset = ((rank - i + size) % size) * increment;
52     recv_offset = ((rank - i - 1 + size) % size) * increment;
53     Request::sendrecv((char *) rbuf + send_offset, scount, stype, to, tag + i,
54                  (char *) rbuf + recv_offset, rcount, rtype, from, tag + i,
55                  comm, &status);
56   }
57
58   return MPI_SUCCESS;
59 }
60
61
62 }
63 }