Request-reply

template<kamping::v2::value_destination_pair_buffer Requests, typename RBuf, typename MakeReply, kamping::v2::convertible_to_mpi_handle<MPI_Comm> Comm = MPI_Comm, is_execution_policy Exec = execution_policy::seq, is_output_layout Order = layout::unordered>
requires detail::request_reply_args<Requests, RBuf, MakeReply, Order> && kamping::v2::has_mpi_value_type<Requests>
RBuf request_reply(Requests &&requests, RBuf &&result, MakeReply &&make_reply, Comm const &comm = MPI_COMM_WORLD, Exec exec = {}, Order order = {})

Sends each request to its destination, answers it there with make_reply, and returns the replies.

requests is a range of (value, destination) pairs. Every process applies make_reply to each request it receives, and the replies travel back to the requesting process, where they are written to result, grouped by the rank that answered them and, within a group, in the order of the requests:

std::vector<std::pair<int, int>> requests = ...;   // (key, owner rank)
std::vector<double> values;
dstl::request_reply(requests, values | views::resize, [&](int key) { return lookup(key); }, comm);

The replies to the requests for rank r follow those for rank r - 1. With layout::ordered_by_source, result must be a variable-size receive buffer (e.g. views::auto_recv_v), which then also receives the number of replies per rank.

Requests and replies must be trivially copyable. The datatype of the requests is the payload datatype of requests: for builtin types it is found automatically; otherwise attach it with requests | views::with_value_type(dt) or requests | views::with_auto_value_pool(pool).

Template parameters:
Parameters:
  • requests – A sized random-access range of (value, destination) pairs; the destination is a rank.

  • result – The receive buffer for the replies, a contiguous range. With views::resize (or views::auto_recv_v) it is sized automatically; otherwise it must already hold all replies.

  • make_reply – Computes the reply to a request: Reply(Value const&).

  • comm – The communicator.

Returns:

The result buffer: by reference if passed as an lvalue, by value if passed as an rvalue.

Defined in header <dstl/request_reply.hpp>