TRIQS/mpi 1.3.0
C++ interface to MPI
Loading...
Searching...
No Matches
utils.hpp
Go to the documentation of this file.
1// Copyright (c) 2024 Simons Foundation
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0.txt
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14//
15// Authors: Thomas Hahn, Alexander Hampel, Olivier Parcollet, Nils Wentzell
16
22#pragma once
23
24#include <mpi.h>
25
26#include <stdexcept>
27#include <string>
28
29namespace mpi {
30
36 namespace detail {
37
38 // Helper struct to get the regular type of a type.
39 template <typename T, typename Enable = void> struct _regular {
40 using type = T;
41 };
42
43 // Spezialization of _regular for types with a `regular_type` type alias.
44 template <typename T> struct _regular<T, std::void_t<typename T::regular_type>> {
45 using type = typename T::regular_type;
46 };
47
48 } // namespace detail
49
55 template <typename T> using regular_t = typename detail::_regular<std::decay_t<T>>::type;
56
72 inline void check_mpi_call(int errcode, const std::string &mpi_routine) {
73 if (errcode != MPI_SUCCESS) throw std::runtime_error("MPI error " + std::to_string(errcode) + " in MPI routine " + mpi_routine);
74 }
75
80 template <typename R>
81 concept contiguous_sized_range = std::ranges::contiguous_range<R> && std::ranges::sized_range<R>;
82
85} // namespace mpi
A concept that checks if a range type is contiguous and sized.
Definition utils.hpp:81
typename detail::_regular< std::decay_t< T > >::type regular_t
Type trait to get the regular type of a type.
Definition utils.hpp:55
void check_mpi_call(int errcode, const std::string &mpi_routine)
Check the success of an MPI call.
Definition utils.hpp:72