20#include <kassert/kassert.hpp>
23#include "kamping/assertion_levels.hpp"
25#include "kamping/collectives/bcast.hpp"
26#include "kamping/collectives/gather.hpp"
27#include "kamping/communicator.hpp"
81 template <
typename...>
82 typename DefaultContainerType,
83 template <
typename,
template <
typename...>
typename>
85template <
typename recv_value_type_tparam ,
typename... Args>
103 "Invalid root rank " <<
int_root <<
" in communicator of size " << size(),
112 .construct_buffer_or_rebind();
120 internal::select_parameter_type_or_default<internal::ParameterType::recv_buf, default_recv_buf_type>(
128 !std::is_same_v<recv_value_type, internal::unused_tparam>,
129 "No send_buf or recv_buf parameter provided and no receive value given as template parameter. One of these is "
135 internal::determine_mpi_datatypes<send_value_type, recv_value_type, decltype(recv_buf)>(
args...);
138 "Send type must be specified on root.",
146 internal::select_parameter_type_or_default<internal::ParameterType::send_count, default_send_count_type>(
150 .construct_buffer_or_rebind();
156 "No send count is given and the size of the send buffer ("
157 <<
send_buf.size() <<
") at the root is not divisible by the number of PEs (" << size()
158 <<
") in the communicator.",
169 internal::select_parameter_type_or_default<internal::ParameterType::recv_count, default_recv_count_type>(
173 .construct_buffer_or_rebind();
178 "recv_count() parameter is an output parameter on some PEs, but not on alle PEs.",
196 "Recv buffer is not large enough to hold all received elements.",
210 this->mpi_error_hook(
err,
"MPI_Scatter");
212 return make_mpi_result<std::tuple<
Args...>>(
237 template <
typename...>
239 template <
typename,
template <
typename...>
typename>
250 std::tuple(this->
root()),
255 if constexpr (kassert::internal::assertion_enabled(
assert::light)) {
256 if (is_root(
root.rank_signed())) {
264 "send_buf of size equal to comm.size() must be provided on the root rank.",
270 if constexpr (has_parameter_type<ParameterType::send_buf,
Args...>()) {
272 using value_type =
typename send_recv_buf_type::value_type;
323 template <
typename...>
325 template <
typename,
template <
typename...>
typename>
354 "Invalid root rank " <<
root_val <<
" in communicator of size " << size(),
363 .construct_buffer_or_rebind();
372 internal::select_parameter_type_or_default<internal::ParameterType::recv_buf, default_recv_buf_type>(
380 !std::is_same_v<recv_value_type, internal::unused_tparam>,
381 "No send_buf or recv_buf parameter provided and no receive value given as template parameter. One of these is "
387 internal::determine_mpi_datatypes<send_value_type, recv_value_type, decltype(recv_buf)>(
args...);
398 "send_counts() must be given on the root PE.",
403 "Send counts buffer is smaller than the number of PEs at the root PE.",
417 send_displs.resize_if_requested([&]() {
return this->size(); });
421 "Send displs buffer is smaller than the number of PEs at the root PE.",
434 .construct_buffer_or_rebind();
440 "recv_counts() must be given on all PEs or on no PEs",
454 return static_cast<size_t>(
recv_count.get_single_element());
461 "Recv buffer is not large enough to hold all received elements.",
476 this->mpi_error_hook(
err,
"MPI_Scatterv");
478 return make_mpi_result<std::tuple<
Args...>>(
Helper functions that make casts safer.
STL-compatible allocator for requesting memory using the builtin MPI allocator.
Definition allocator.hpp:32
T value_type
The value type.
Definition allocator.hpp:53
constexpr int light
Assertion level for lightweight assertions.
Definition assertion_levels.hpp:13
constexpr int light_communication
Assertions that perform lightweight communication.
Definition assertion_levels.hpp:25
auto scatter(Args... args) const
Definition scatter.hpp:86
auto scatterv(Args... args) const
Wrapper for MPI_Scatterv.
Definition scatter.hpp:328
auto scatter_single(Args... args) const
Definition scatter.hpp:242
static constexpr auto alloc_new
Convenience wrapper for creating library allocated containers. See AllocNewT for details.
Definition data_buffer.hpp:194
auto root(int rank)
Passes rank as root rank to the underlying call. This parameter is needed in functions like MPI_Gathe...
Definition named_parameters.hpp:979
auto send_count(int count)
Passes count as send count to the underlying call.
Definition named_parameters.hpp:321
auto send_type(MPI_Datatype send_type)
Passes send_type as send type to the underlying call.
Definition named_parameters.hpp:1195
auto recv_buf(Container &&container)
Passes a container, into which the received elements will be written, to the underlying call....
Definition named_parameters.hpp:859
auto send_buf(internal::ignore_t< Data > ignore)
Generates a dummy send buf that wraps a nullptr.
Definition named_parameters.hpp:51
auto send_counts_out()
Indicates to construct a container with type kamping::Communicator::default_container_type<int>,...
Definition named_parameters.hpp:309
auto send_count_out()
Indicates to deduce the send count and return it to the caller as part of the underlying call's resul...
Definition named_parameters.hpp:347
auto send_recv_buf(Data &&data)
Passes a container/single value as a send or receive buffer to the underlying MPI call.
Definition named_parameters.hpp:137
auto send_counts(Container &&container)
Passes a container as send counts to the underlying call, i.e. the container's storage must contain t...
Definition named_parameters.hpp:203
auto recv_count(int count)
Passes count as recv count to the underlying call.
Definition named_parameters.hpp:490
auto send_displs_out()
Indicates to construct a container with type kamping::Communicator::default_container_type<int>,...
Definition named_parameters.hpp:679
auto recv_type(MPI_Datatype recv_type)
Passes recv_type as recv type to the underlying call.
Definition named_parameters.hpp:1238
auto send_displs(Container &&container)
Passes a container as send displacements to the underlying call, i.e. the container's storage must co...
Definition named_parameters.hpp:574
auto recv_count_out()
Indicates to deduce the recv count and return it to the caller as part of the underlying call's resul...
Definition named_parameters.hpp:516
std:: tuple_element_t< find_pos< std::integral_constant< ParameterType, parameter_type >, 0, Args... >(), std::tuple< Args... > > buffer_type_with_requested_parameter_type
Type of Buffer with requested.
Definition named_parameter_selection.hpp:176
Utility that maps C++ types to types that can be understood by MPI.
Template magic to check named parameters passed to wrappers at compile time.
#define KAMPING_REQUIRED_PARAMETERS(...)
Wrapper to pass (possibly empty) list of parameter type names as required parameters to KAMPING_CHECK...
Definition named_parameter_check.hpp:52
#define KAMPING_OPTIONAL_PARAMETERS(...)
Wrapper to pass (possibly empty) list of parameter type names as optional parameters to KAMPING_CHECK...
Definition named_parameter_check.hpp:58
#define KAMPING_CHECK_PARAMETERS(args, required, optional)
Assertion macro that checks if passed parameters are correct, i.e., all parameter types are unique,...
Definition named_parameter_check.hpp:80
Template magic to implement named parameters in cpp.
File containing the parameter types used by the KaMPIng library.
Factory methods for buffer wrappers.
Internal namespace marking the code that is not user-facing.
Definition collectives_helpers.hpp:20
static constexpr bool has_to_be_computed
Checks if the buffer has to be computed by kamping, i.e. if it is an output parameter or the buffer h...
Definition named_parameter_check.hpp:398
Some functions and types simplifying/enabling the development of wrapped MPI calls in KaMPIng.