1 /* Copyright (c) 2013-2020. 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. */
7 #include "../colls_private.hpp"
9 /*Naive and simple basic alltoall implementation. */
16 int alltoall__basic_linear(const void *sendbuf, int sendcount, MPI_Datatype sendtype,
17 void *recvbuf, int recvcount, MPI_Datatype recvtype, MPI_Comm comm)
19 int system_tag = COLL_TAG_ALLTOALL;
22 MPI_Aint lb = 0, sendext = 0, recvext = 0;
25 int rank = comm->rank();
26 int size = comm->size();
27 XBT_DEBUG("<%d> algorithm alltoall_basic_linear() called.", rank);
28 sendtype->extent(&lb, &sendext);
29 recvtype->extent(&lb, &recvext);
30 /* simple optimization */
31 int err = Datatype::copy(static_cast<const char *>(sendbuf) + rank * sendcount * sendext, sendcount, sendtype,
32 static_cast<char *>(recvbuf) + rank * recvcount * recvext, recvcount, recvtype);
33 if (err == MPI_SUCCESS && size > 1) {
34 /* Initiate all send/recv to/from others. */
35 auto* requests = new MPI_Request[2 * (size - 1)];
36 /* Post all receives first -- a simple optimization */
38 for (i = (rank + 1) % size; i != rank; i = (i + 1) % size) {
39 requests[count] = Request::irecv_init(static_cast<char *>(recvbuf) + i * recvcount * recvext, recvcount,
40 recvtype, i, system_tag, comm);
43 /* Now post all sends in reverse order
44 * - We would like to minimize the search time through message queue
45 * when messages actually arrive in the order in which they were posted.
46 * TODO: check the previous assertion
48 for (i = (rank + size - 1) % size; i != rank; i = (i + size - 1) % size) {
49 requests[count] = Request::isend_init(static_cast<const char *>(sendbuf) + i * sendcount * sendext, sendcount,
50 sendtype, i, system_tag, comm);
53 /* Wait for them all. */
54 Request::startall(count, requests);
55 XBT_DEBUG("<%d> wait for %d requests", rank, count);
56 Request::waitall(count, requests, MPI_STATUS_IGNORE);
57 for(i = 0; i < count; i++) {
58 if(requests[i]!=MPI_REQUEST_NULL)
59 Request::unref(&requests[i]);