19#include <kassert/kassert.hpp>
22#include "kamping/assertion_levels.hpp"
24#include "kamping/collectives/collectives_helpers.hpp"
25#include "kamping/comm_helper/is_same_on_all_ranks.hpp"
26#include "kamping/communicator.hpp"
75 template <
typename...>
76 typename DefaultContainerType,
77 template <
typename,
template <
typename...>
typename>
79template <
typename... Args>
88 auto&&
root = internal::select_parameter_type_or_default<internal::ParameterType::root, internal::RootDataBuffer>(
89 std::tuple(this->
root()),
92 KASSERT(this->is_valid_rank(
root.rank_signed()),
"Invalid rank as root.");
94 this->is_same_on_all_ranks(
root.rank_signed()),
95 "Root has to be the same on all ranks.",
100 internal::select_parameter_type<internal::ParameterType::send_buf>(
args...).construct_buffer_or_rebind();
105 internal::select_parameter_type_or_default<internal::ParameterType::send_count, default_send_count_type>(
109 .construct_buffer_or_rebind();
118 internal::select_parameter_type_or_default<internal::ParameterType::recv_buf, default_recv_buf_type>(
127 internal::determine_mpi_datatypes<send_value_type, recv_value_type, decltype(recv_buf)>(
args...);
134 internal::select_parameter_type_or_default<internal::ParameterType::recv_count, default_recv_count_type>(
138 .construct_buffer_or_rebind();
141 if (this->is_root(
root.rank_signed())) {
149 if (this->is_root(
root.rank_signed())) {
155 "Recv buffer is not large enough to hold all received elements.",
169 this->mpi_communicator()
171 this->mpi_error_hook(
err,
"MPI_Gather");
172 return make_mpi_result<std::tuple<
Args...>>(
217 template <
typename...>
219 template <
typename,
template <
typename...>
typename>
221template <
typename...
Args>
232 internal::select_parameter_type<internal::ParameterType::send_buf>(
args...).construct_buffer_or_rebind();
238 internal::select_parameter_type_or_default<internal::ParameterType::recv_buf, default_recv_buf_type>(
246 auto&&
root = internal::select_parameter_type_or_default<internal::ParameterType::root, internal::RootDataBuffer>(
247 std::tuple(this->
root()),
253 internal::determine_mpi_datatypes<send_value_type, recv_value_type, decltype(recv_buf)>(
args...);
259 internal::select_parameter_type_or_default<internal::ParameterType::recv_counts, default_recv_counts_type>(
265 static_assert(std::is_same_v<std::remove_const_t<recv_counts_type>,
int>,
"Recv counts must be of type int");
268 is_empty_data_buffer_v<
274 KASSERT(this->is_valid_rank(
root.rank_signed()),
"Invalid rank as root.");
276 this->is_same_on_all_ranks(
root.rank_signed()),
277 "Root has to be the same on all ranks.",
283 internal::select_parameter_type_or_default<internal::ParameterType::send_count, default_send_count_type>(
287 .construct_buffer_or_rebind();
296 internal::select_parameter_type_or_default<internal::ParameterType::recv_displs, default_recv_displs_type>(
302 static_assert(std::is_same_v<std::remove_const_t<recv_displs_type>,
int>,
"Recv displs must be of type int");
309 "Receive counts are given on some ranks and are omitted on others",
317 if (this->is_root(
root.rank_signed())) {
321 "Recv counts buffer is smaller than the number of PEs at the root PE.",
333 if (this->is_root(
root.rank_signed())) {
336 "Recv counts buffer is smaller than the number of PEs at the root PE.",
350 if (this->is_root(
root.rank_signed())) {
355 if (this->is_root(
root.rank_signed())) {
358 "Recv displs buffer is smaller than the number of PEs at the root PE.",
363 if (this->is_root(
root.rank_signed())) {
365 return compute_required_recv_buf_size_in_vectorized_communication(
recv_counts,
recv_displs, this->size());
372 "Recv buffer is not large enough to hold all received elements.",
387 this->mpi_communicator()
389 this->mpi_error_hook(
err,
"MPI_Gather");
390 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 gather(Args... args) const
Wrapper for MPI_Gather.
Definition gather.hpp:80
auto gatherv(Args... args) const
Wrapper for MPI_Gatherv.
Definition gather.hpp:222
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 recv_counts(Container &&container)
Passes a container as recv counts to the underlying call, i.e. the container's storage must contain t...
Definition named_parameters.hpp:366
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_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 recv_counts_out()
Indicates to construct a container with type kamping::Communicator::default_container_type<int>,...
Definition named_parameters.hpp:478
auto recv_displs_out()
Indicates to construct a container with type kamping::Communicator::default_container_type<int>,...
Definition named_parameters.hpp:802
auto recv_displs(Container &&container)
Passes a container as receive displacements to the underlying call, i.e. the container's storage must...
Definition named_parameters.hpp:697
auto recv_count(int count)
Passes count as recv count to the underlying call.
Definition named_parameters.hpp:490
auto recv_type(MPI_Datatype recv_type)
Passes recv_type as recv type to the underlying call.
Definition named_parameters.hpp:1238
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
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.