3 // Allgather-Non-Topoloty-Scecific-Logical-Ring algorithm
5 smpi_coll_tuned_allgather_NTSLR_NB(void *sbuf, int scount, MPI_Datatype stype,
6 void *rbuf, int rcount, MPI_Datatype rtype,
9 MPI_Aint rextent, sextent;
10 MPI_Status status, status2;
11 int i, to, from, rank, size;
12 int send_offset, recv_offset;
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 MPI_Request *rrequest_array;
20 MPI_Request *srequest_array;
21 rrequest_array = (MPI_Request *) malloc(size * sizeof(MPI_Request));
22 srequest_array = (MPI_Request *) malloc(size * sizeof(MPI_Request));
24 // irregular case use default MPI fucntions
25 if (scount * sextent != rcount * rextent)
26 MPI_Allgather(sbuf, scount, stype, rbuf, rcount, rtype, comm);
29 to = (rank + 1) % size;
30 from = (rank + size - 1) % size;
32 //copy a single segment from sbuf to rbuf
33 send_offset = rank * scount * sextent;
35 MPI_Sendrecv(sbuf, scount, stype, rank, tag,
36 (char *)rbuf + send_offset, rcount, rtype, rank, tag, comm, &status);
39 //start sending logical ring message
40 int increment = scount * sextent;
42 //post all irecv first
43 for (i = 0; i < size - 1; i++) {
44 recv_offset = ((rank - i - 1 + size) % size) * increment;
45 MPI_Irecv((char *)rbuf + recv_offset, rcount, rtype, from, tag + i, comm,
50 for (i = 0; i < size - 1; i++) {
51 send_offset = ((rank - i + size) % size) * increment;
52 MPI_Isend((char *)rbuf + send_offset, scount, stype, to, tag + i, comm,
54 MPI_Wait(&rrequest_array[i], &status);
55 MPI_Wait(&srequest_array[i], &status2);