// @HEADER // ***************************************************************************** // Tpetra: Templated Linear Algebra Services Package // // Copyright 2008 NTESS and the Tpetra contributors. // SPDX-License-Identifier: BSD-3-Clause // ***************************************************************************** // @HEADER #pragma once #include /*! reference alltoallw impl */ inline void Fake_Alltoallw(const void *sendbuf, const int *sendcounts, const int *sdispls, const MPI_Datatype *sendtypes, void *recvbuf, const int *recvcounts, const int *rdispls, const MPI_Datatype *recvtypes, MPI_Comm comm) { constexpr int ARBITRARY_TAG = 0; // communicator properties int size, rank; MPI_Comm_size(comm, &size); MPI_Comm_rank(comm, &rank); // requests for sends and receives std::vector sreqs(size, MPI_REQUEST_NULL); std::vector rreqs(size, MPI_REQUEST_NULL); // use bytes as displs are in bytes auto rb = reinterpret_cast(recvbuf); auto sb = reinterpret_cast(sendbuf); // issue sends & recvs for (int source = 0; source < size; ++source) { MPI_Irecv(&rb[rdispls[source]], recvcounts[source], recvtypes[source], source, ARBITRARY_TAG, comm, &rreqs[source]); } for (int dest = 0; dest < size; ++dest) { MPI_Isend(&sb[sdispls[dest]], sendcounts[dest], sendtypes[dest], dest, ARBITRARY_TAG, comm, &sreqs[dest]); } // wait for communication to finish MPI_Waitall(size, sreqs.data(), MPI_STATUSES_IGNORE); MPI_Waitall(size, rreqs.data(), MPI_STATUSES_IGNORE); }