KaMPIng 0.2.1
(Near) zero-overhead MPI wrapper for C++
Loading...
Searching...
No Matches
contiguous_type.hpp
Go to the documentation of this file.
1// This file is part of KaMPIng.
2//
3// Copyright 2021-2026 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/// @file
15/// @brief `MPI_Type_contiguous` implementation for \ref kamping::types::contiguous_type and \ref
16/// kamping::types::byte_serialized.
17
18#pragma once
19#include <cstddef>
20#include <type_traits>
21
22#include <mpi.h>
23
24#include "kamping/kassert/kassert.hpp"
25// contiguous_type and byte_serialized structs are declared in the fwd header;
26// include it here so consumers only need this single header.
29
30namespace kamping::types {
31
32/// @addtogroup kamping_types
33/// @{
34
35template <typename T, size_t N, typename Lookup>
37 MPI_Datatype type;
39 if constexpr (std::is_same_v<T, std::byte>) {
41 } else {
42 static_assert(
43 Lookup::template has_type_v<T>,
44 "\n --> Type not supported by the current Lookup policy. "
45 "Please specialize mpi_type_traits for this type or provide a custom Lookup."
46 );
47 base_type = Lookup::template get<T>();
48 }
49 int const count = static_cast<int>(N);
50 int const err = MPI_Type_contiguous(count, base_type, &type);
51 KAMPING_ASSERT(err == MPI_SUCCESS, "MPI_Type_contiguous failed");
52 return type;
53}
54
55/// @}
56
57} // namespace kamping::types
STL-compatible allocator for requesting memory using the builtin MPI allocator.
Definition allocator.hpp:32
Forward declarations for contiguous_type and byte_serialized to break include cycles.
static MPI_Datatype data_type()
Returns the MPI_Datatype for a contiguous block of N elements of type T.
Definition contiguous_type.hpp:36
Type traits and dispatcher for mapping C++ types to MPI datatypes.