Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add aliases #753

Merged
merged 1 commit into from
Sep 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
116 changes: 110 additions & 6 deletions include/kamping/result.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,10 +135,24 @@ class MPIResult {
template <
typename T = std::tuple<Args...>,
std::enable_if_t<internal::has_parameter_type_in_tuple<internal::ParameterType::recv_buf, T>(), bool> = true>
auto& get_recv_buffer() {
auto& get_recv_buf() {
return internal::select_parameter_type_in_tuple<internal::ParameterType::recv_buf>(_data).underlying();
}

/// @brief Get the \c recv_buffer from the MPIResult object. Alias for \ref get_recv_buf().
///
/// This function is only available if the underlying memory is owned by the
/// MPIResult object.
/// @tparam T Template parameter helper only needed to remove this function if the corresponding data is not part of
/// the result object.
/// @return Returns a reference to the underlying storage containing the received elements.
template <
typename T = std::tuple<Args...>,
std::enable_if_t<internal::has_parameter_type_in_tuple<internal::ParameterType::recv_buf, T>(), bool> = true>
auto& get_recv_buffer() {
return get_recv_buf();
}

/// @brief Get the \c recv_buffer from the MPIResult object.
///
/// This function is only available if the underlying memory is owned by the
Expand All @@ -149,10 +163,24 @@ class MPIResult {
template <
typename T = std::tuple<Args...>,
std::enable_if_t<internal::has_parameter_type_in_tuple<internal::ParameterType::recv_buf, T>(), bool> = true>
auto const& get_recv_buffer() const {
auto const& get_recv_buf() const {
return internal::select_parameter_type_in_tuple<internal::ParameterType::recv_buf>(_data).underlying();
}

/// @brief Get the \c recv_buffer from the MPIResult object. Alias for \ref get_recv_buf().
///
/// This function is only available if the underlying memory is owned by the
/// MPIResult object.
/// @tparam T Template parameter helper only needed to remove this function if the corresponding data is not part of
/// the result object.
/// @return Returns a reference to the underlying storage containing the received elements.
template <
typename T = std::tuple<Args...>,
std::enable_if_t<internal::has_parameter_type_in_tuple<internal::ParameterType::recv_buf, T>(), bool> = true>
auto const& get_recv_buffer() const {
return get_recv_buf();
}

/// @brief Get the \c send_buffer from the MPIResult object.
///
/// This function is only available if the underlying memory is owned by the
Expand All @@ -163,10 +191,24 @@ class MPIResult {
template <
typename T = std::tuple<Args...>,
std::enable_if_t<internal::has_parameter_type_in_tuple<internal::ParameterType::send_buf, T>(), bool> = true>
auto const& get_send_buffer() const {
auto const& get_send_buf() const {
return internal::select_parameter_type_in_tuple<internal::ParameterType::send_buf>(_data).underlying();
}

/// @brief Get the \c send_buffer from the MPIResult object. Alias for \ref get_send_buf().
///
/// This function is only available if the underlying memory is owned by the
/// MPIResult object.
/// @tparam T Template parameter helper only needed to remove this function if the corresponding data is not part of
/// the result object.
/// @return Returns a reference to the underlying storage containing the elements to send.
template <
typename T = std::tuple<Args...>,
std::enable_if_t<internal::has_parameter_type_in_tuple<internal::ParameterType::send_buf, T>(), bool> = true>
auto const& get_send_buffer() const {
return get_send_buf();
}

/// @brief Extracts the \c recv_buffer from the MPIResult object.
///
/// This function is only available if the underlying memory is owned by the
Expand All @@ -177,11 +219,41 @@ class MPIResult {
template <
typename T = std::tuple<Args...>,
std::enable_if_t<internal::has_parameter_type_in_tuple<internal::ParameterType::recv_buf, T>(), bool> = true>
auto extract_recv_buffer() {
auto extract_recv_buf() {
return internal::select_parameter_type_in_tuple<internal::ParameterType::recv_buf>(_data).extract();
}

/// @brief Extracts the \c recv_buffer from the MPIResult object. Alias for \ref extract_recv_buf().
///
/// This function is only available if the underlying memory is owned by the
/// MPIResult object.
/// @tparam T Template parameter helper only needed to remove this function if the corresponding data is not part of
/// the result object.
/// @return Returns the underlying storage containing the received elements.
template <
typename T = std::tuple<Args...>,
std::enable_if_t<internal::has_parameter_type_in_tuple<internal::ParameterType::recv_buf, T>(), bool> = true>
auto extract_recv_buffer() {
return extract_recv_buf();
}

/// @brief Get the \c send_recv_buffer from the MPIResult object. @todo discuss this
///
/// This function is only available if the underlying memory is owned by the
/// MPIResult object.
/// @tparam T Template parameter helper only needed to remove this function if the corresponding data is not part of
/// the result object.
/// @return Returns a reference to the underlying storage containing the received elements.
template <
typename T = std::tuple<Args...>,
std::enable_if_t<internal::has_parameter_type_in_tuple<internal::ParameterType::send_recv_buf, T>(), bool> =
true>
auto& get_recv_buf() {
return internal::select_parameter_type_in_tuple<internal::ParameterType::send_recv_buf>(_data).underlying();
}

/// @brief Get the \c send_recv_buffer from the MPIResult object. @todo discuss this
/// Alias for \ref get_recv_buf().
///
/// This function is only available if the underlying memory is owned by the
/// MPIResult object.
Expand All @@ -193,10 +265,26 @@ class MPIResult {
std::enable_if_t<internal::has_parameter_type_in_tuple<internal::ParameterType::send_recv_buf, T>(), bool> =
true>
auto& get_recv_buffer() {
return get_recv_buf();
}

/// @brief Get the \c send_recv_buffer from the MPIResult object. @todo discuss this
///
/// This function is only available if the underlying memory is owned by the
/// MPIResult object.
/// @tparam T Template parameter helper only needed to remove this function if the corresponding data is not part of
/// the result object.
/// @return Returns a reference to the underlying storage containing the received elements.
template <
typename T = std::tuple<Args...>,
std::enable_if_t<internal::has_parameter_type_in_tuple<internal::ParameterType::send_recv_buf, T>(), bool> =
true>
auto const& get_recv_buf() const {
return internal::select_parameter_type_in_tuple<internal::ParameterType::send_recv_buf>(_data).underlying();
}

/// @brief Get the \c send_recv_buffer from the MPIResult object. @todo discuss this
/// Alias for \ref get_recv_buf().
///
/// This function is only available if the underlying memory is owned by the
/// MPIResult object.
Expand All @@ -208,7 +296,7 @@ class MPIResult {
std::enable_if_t<internal::has_parameter_type_in_tuple<internal::ParameterType::send_recv_buf, T>(), bool> =
true>
auto const& get_recv_buffer() const {
return internal::select_parameter_type_in_tuple<internal::ParameterType::send_recv_buf>(_data).underlying();
return get_recv_buf();
}

/// @brief Extracts the \c send_recv_buffer from the MPIResult object. @todo discuss this
Expand All @@ -222,10 +310,26 @@ class MPIResult {
typename T = std::tuple<Args...>,
std::enable_if_t<internal::has_parameter_type_in_tuple<internal::ParameterType::send_recv_buf, T>(), bool> =
true>
auto extract_recv_buffer() {
auto extract_recv_buf() {
return internal::select_parameter_type_in_tuple<internal::ParameterType::send_recv_buf>(_data).extract();
}

/// @brief Extracts the \c send_recv_buffer from the MPIResult object. @todo discuss this
/// Alias for \ref extract_recv_buf().
///
/// This function is only available if the underlying memory is owned by the
/// MPIResult object.
/// @tparam T Template parameter helper only needed to remove this function if the corresponding data is not part of
/// the result object.
/// @return Returns the underlying storage containing the received elements.
template <
typename T = std::tuple<Args...>,
std::enable_if_t<internal::has_parameter_type_in_tuple<internal::ParameterType::send_recv_buf, T>(), bool> =
true>
auto extract_recv_buffer() {
return extract_recv_buf();
}

/// @brief Get the \c recv_counts from the MPIResult object.
///
/// This function is only available if the corresponding data is part of the result object.
Expand Down
22 changes: 22 additions & 0 deletions tests/result_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,27 @@ void test_recv_buffer_in_MPIResult() {
EXPECT_EQ(underlying_container[i], i);
}
}
{
MPIResult mpi_result{std::make_tuple(construct_recv_buffer())};
UnderlyingContainer underlying_container = mpi_result.extract_recv_buf();
for (size_t i = 0; i < 10; ++i) {
EXPECT_EQ(underlying_container[i], i);
}
}
{
MPIResult mpi_result{std::make_tuple(construct_recv_buffer())};
UnderlyingContainer& underlying_container = mpi_result.get_recv_buffer();
for (size_t i = 0; i < 10; ++i) {
EXPECT_EQ(underlying_container[i], i);
}
}
{
MPIResult mpi_result{std::make_tuple(construct_recv_buffer())};
UnderlyingContainer& underlying_container = mpi_result.get_recv_buf();
for (size_t i = 0; i < 10; ++i) {
EXPECT_EQ(underlying_container[i], i);
}
}
{
MPIResult mpi_result{std::make_tuple(construct_recv_buffer())};
UnderlyingContainer& underlying_container =
Expand All @@ -85,6 +99,14 @@ void test_recv_buffer_in_MPIResult() {
EXPECT_EQ(underlying_container[i], i);
}
}
{
MPIResult const mpi_result{std::make_tuple(construct_recv_buffer())};
mpi_result.get_recv_buffer();
UnderlyingContainer const& underlying_container = mpi_result.get_recv_buf();
for (size_t i = 0; i < 10; ++i) {
EXPECT_EQ(underlying_container[i], i);
}
}
{
MPIResult const mpi_result{std::make_tuple(construct_recv_buffer())};
UnderlyingContainer const& underlying_container =
Expand Down
Loading