Logo AND Algorithmique Numérique Distribuée

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