KaMPIng 0.1.1
Flexible and (near) zero-overhead C++ bindings for MPI
Loading...
Searching...
No Matches
implementation_helpers.hpp
1// This file is part of KaMPIng.
2//
3// Copyright 2022 The KaMPIng Authors
4//
5// KaMPIng is free software : you can redistribute it and/or modify it under the terms of the GNU Lesser General Public
6// License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later
7// version. KaMPIng is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the
8// implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
9// for more details.
10//
11// You should have received a copy of the GNU Lesser General Public License along with KaMPIng. If not, see
12// <https://www.gnu.org/licenses/>.
13
14#pragma once
15
17
18namespace kamping::internal {
19/// @brief Checks whether a RankDataBuffer contains a valid rank in the given communicator.
20///
21/// Can also be configured to accept RankType::null or RankType::any.
22///
23/// @param rank_data_buffer The RankDataBuffer encapsulating the rank to check.
24/// @param comm The Communicator to check for validity in.
25/// @param allow_null Whether this function should return true for RankType::null.
26/// @param allow_any Whether this function should return true for RankType::any.
27/// @tparam RankDataBufferClass The template instantiation of RankDataBuffer.
28/// @tparam Comm The template instantiation of Communicator.
29template <typename RankDataBufferClass, typename Comm>
30constexpr bool is_valid_rank_in_comm(
32 Comm const& comm,
33 bool const allow_null = false,
34 bool const allow_any = false
35) {
36 constexpr auto rank_type = std::remove_reference_t<decltype(rank_data_buffer)>::rank_type;
37 if constexpr (rank_type == RankType::value) {
38 return comm.is_valid_rank(rank_data_buffer.rank_signed());
39 } else if constexpr (rank_type == RankType::null) {
40 return allow_null;
41 } else if constexpr (rank_type == RankType::any) {
42 return allow_any;
43 }
44 return false;
45}
46
47} // namespace kamping::internal
STL-compatible allocator for requesting memory using the builtin MPI allocator.
Definition allocator.hpp:32
Internal namespace marking the code that is not user-facing.
Definition collectives_helpers.hpp:20
@ any
holds MPI_ANY_SOURCE
@ null
holds MPI_PROC_NULL
constexpr bool is_valid_rank_in_comm(RankDataBufferClass const &rank_data_buffer, Comm const &comm, bool const allow_null=false, bool const allow_any=false)
Checks whether a RankDataBuffer contains a valid rank in the given communicator.
Definition implementation_helpers.hpp:30
Parameter objects return by named parameter factory functions.