1 /* Copyright (c) 2013-2021. 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. */
9 * (C) 2001 by Argonne National Laboratory.
10 * See COPYRIGHT in top-level directory.
13 #include "../colls_private.hpp"
15 /*****************************************************************************
16 * Function: allgather_mpich_ring
19 * send_buff: send input buffer
20 * send_count: number of elements to send
21 * send_type: data type of elements being sent
22 * recv_buff: receive output buffer
23 * recv_count: number of elements to received
24 * recv_type: data type of elements being received
26 ****************************************************************************/
31 int allgatherv__mpich_ring(const void *sendbuf, int sendcount,
32 MPI_Datatype send_type, void *recvbuf,
33 const int *recvcounts, const int *displs, MPI_Datatype recvtype,
37 char *sbuf = nullptr, *rbuf = nullptr;
39 int torecv=0, tosend=0, min, rank, comm_size;
43 MPI_Aint recvtype_extent;
44 int right, left, total_count, i;
46 comm_size=comm->size();
48 recvtype_extent= recvtype->get_extent();
50 for (i=0; i<comm_size; i++)
51 total_count += recvcounts[i];
53 if (sendbuf != MPI_IN_PLACE) {
54 /* First, load the "local" version in the recvbuf. */
55 Datatype::copy(sendbuf, sendcount, send_type,
56 ((char *)recvbuf + displs[rank]*recvtype_extent),
57 recvcounts[rank], recvtype);
60 left = (comm_size + rank - 1) % comm_size;
61 right = (rank + 1) % comm_size;
63 torecv = total_count - recvcounts[rank];
64 tosend = total_count - recvcounts[right];
67 for (i = 1; i < comm_size; i++)
68 if (min > recvcounts[i])
70 if (min * recvtype_extent < 32768*8)
71 min = 32768*8 / recvtype_extent;
72 /* Handle the case where the datatype extent is larger than
73 * the pipeline size. */
81 while (tosend || torecv) { /* While we have data to send or receive */
82 sendnow = ((recvcounts[sidx] - soffset) > min) ? min : (recvcounts[sidx] - soffset);
83 recvnow = ((recvcounts[ridx] - roffset) > min) ? min : (recvcounts[ridx] - roffset);
84 sbuf = (char *)recvbuf + ((displs[sidx] + soffset) * recvtype_extent);
85 rbuf = (char *)recvbuf + ((displs[ridx] + roffset) * recvtype_extent);
87 /* Protect against wrap-around of indices */
94 if (not sendnow && not recvnow) {
95 /* Don't do anything. This case is possible if two
96 * consecutive processes contribute 0 bytes each. */
97 } else if (not sendnow) { /* If there's no data to send, just do a recv call */
98 Request::recv(rbuf, recvnow, recvtype, left, COLL_TAG_ALLGATHERV, comm, &status);
101 } else if (not recvnow) { /* If there's no data to receive, just do a send call */
102 Request::send(sbuf, sendnow, recvtype, right, COLL_TAG_ALLGATHERV, comm);
106 else { /* There's data to be sent and received */
107 Request::sendrecv(sbuf, sendnow, recvtype, right, COLL_TAG_ALLGATHERV,
108 rbuf, recvnow, recvtype, left, COLL_TAG_ALLGATHERV,
116 if (soffset == recvcounts[sidx]) {
118 sidx = (sidx + comm_size - 1) % comm_size;
120 if (roffset == recvcounts[ridx]) {
122 ridx = (ridx + comm_size - 1) % comm_size;