Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
adapt two collectives of starmpi to avoid timing issues, by using only smpi calls...
[simgrid.git] / src / smpi / colls / allgather-NTSLR.c
1 #include "colls.h"
2
3 // Allgather-Non-Topoloty-Scecific-Logical-Ring algorithm
4 int
5 smpi_coll_tuned_allgather_NTSLR(void *sbuf, int scount, MPI_Datatype stype,
6                                 void *rbuf, int rcount, MPI_Datatype rtype,
7                                 MPI_Comm comm)
8 {
9   MPI_Aint rextent, sextent;
10   MPI_Status status;
11   int i, to, from, rank, size;
12   int send_offset, recv_offset;
13   int tag = 500;
14
15   MPI_Comm_rank(comm, &rank);
16   MPI_Comm_size(comm, &size);
17   MPI_Type_extent(rtype, &rextent);
18   MPI_Type_extent(stype, &sextent);
19
20   // irregular case use default MPI fucntions
21   if (scount * sextent != rcount * rextent)
22     MPI_Allgather(sbuf, scount, stype, rbuf, rcount, rtype, comm);
23
24   // topo non-specific
25   to = (rank + 1) % size;
26   from = (rank + size - 1) % size;
27
28   //copy a single segment from sbuf to rbuf
29   send_offset = rank * scount * sextent;
30
31   MPI_Sendrecv(sbuf, scount, stype, rank, tag,
32                (char *)rbuf + send_offset, rcount, rtype, rank, tag,
33                comm, &status);
34
35
36   //start sending logical ring message
37   int increment = scount * sextent;
38   for (i = 0; i < size - 1; i++) {
39     send_offset = ((rank - i + size) % size) * increment;
40     recv_offset = ((rank - i - 1 + size) % size) * increment;
41     MPI_Sendrecv((char *) rbuf + send_offset, scount, stype, to, tag + i,
42                  (char *) rbuf + recv_offset, rcount, rtype, from, tag + i,
43                  comm, &status);
44   }
45
46   return MPI_SUCCESS;
47 }