Debian Codegraph @

packages/tpetra/core/test/MPIAdvance/fake_alltoallw.hpp

raw
1 // @HEADER
2 // *****************************************************************************
3 // Tpetra: Templated Linear Algebra Services Package
4 //
5 // Copyright 2008 NTESS and the Tpetra contributors.
6 // SPDX-License-Identifier: BSD-3-Clause
7 // *****************************************************************************
8 // @HEADER
9
10 #pragma once
11
12 #include <mpi.h>
13
14 /*! reference alltoallw impl
15 */
16 inline void Fake_Alltoallw(const void *sendbuf, const int *sendcounts,
17 const int *sdispls, const MPI_Datatype *sendtypes, void *recvbuf,
18 const int *recvcounts, const int *rdispls,
19 const MPI_Datatype *recvtypes, MPI_Comm comm) {
20
21 constexpr int ARBITRARY_TAG = 0;
22
23 // communicator properties
24 int size, rank;
25 MPI_Comm_size(comm, &size);
26 MPI_Comm_rank(comm, &rank);
27
28 // requests for sends and receives
29 std::vector<MPI_Request> sreqs(size, MPI_REQUEST_NULL);
30 std::vector<MPI_Request> rreqs(size, MPI_REQUEST_NULL);
31
32 // use bytes as displs are in bytes
33 auto rb = reinterpret_cast<char *>(recvbuf);
34 auto sb = reinterpret_cast<const char *>(sendbuf);
35
36 // issue sends & recvs
37 for (int source = 0; source < size; ++source) {
38 MPI_Irecv(&rb[rdispls[source]], recvcounts[source], recvtypes[source], source,
39 ARBITRARY_TAG, comm, &rreqs[source]);
40 }
41 for (int dest = 0; dest < size; ++dest) {
42 MPI_Isend(&sb[sdispls[dest]], sendcounts[dest], sendtypes[dest], dest,
43 ARBITRARY_TAG, comm, &sreqs[dest]);
44 }
45
46 // wait for communication to finish
47 MPI_Waitall(size, sreqs.data(), MPI_STATUSES_IGNORE);
48 MPI_Waitall(size, rreqs.data(), MPI_STATUSES_IGNORE);
49 }