TRIQS/nda 1.3.0
Multi-dimensional array library for C++
Loading...
Searching...
No Matches
utils.hpp
Go to the documentation of this file.
1// Copyright (c) 2020-2023 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: Olivier Parcollet, Nils Wentzell
16
22#pragma once
23
24#include "../concepts.hpp"
25#include "../exceptions.hpp"
26
27#include <mpi/mpi.hpp>
28
29#include <string>
30
31namespace nda::detail {
32
33 // Check if the layout of an array/view is contiguous with positive strides, otherwise throw an exception.
34 template <nda::Array A>
35 void check_layout_mpi_compatible(const A &a, const std::string &func) {
36 if (not a.is_contiguous() or not a.has_positive_strides())
37 NDA_RUNTIME_ERROR << "Error in function " << func << ": Array is not contiguous with positive strides";
38 }
39
40 // Check if the ranks of arrays/views are the same on all processes.
41 template <nda::Array A>
42 bool have_mpi_equal_ranks(const A &a, const mpi::communicator &comm) {
43 return mpi::all_equal(a.rank, comm);
44 }
45
46 // Check if the shape of arrays/views are the same on all processes.
47 template <nda::Array A>
48 bool have_mpi_equal_shapes(const A &a, const mpi::communicator &comm) {
49 return have_mpi_equal_ranks(a, comm) && mpi::all_equal(a.shape(), comm);
50 }
51
52} // namespace nda::detail
Provides concepts for the nda library.
Provides a custom runtime error class and macros to assert conditions and throw exceptions.