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.requestsis a range of(value, destination)pairs. Every process appliesmake_replyto each request it receives, and the replies travel back to the requesting process, where they are written toresult, 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
rfollow those for rankr - 1. Withlayout::ordered_by_source,resultmust 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 withrequests | views::with_value_type(dt)orrequests | views::with_auto_value_pool(pool).- Template parameters:
Exec–execution_policy::seq(default) orexecution_policy::par, which computes the replies and sorts the requests with OpenMP. The communication is single-threaded in both cases.Order–layout::unordered(default) orlayout::ordered_by_source.
- 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. Withviews::resize(orviews::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
resultbuffer: by reference if passed as an lvalue, by value if passed as an rvalue.
Defined in header
<dstl/request_reply.hpp>