TRIQS/nda 1.3.0
Multi-dimensional array library for C++
Loading...
Searching...
No Matches
broadcast.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
25#include "../concepts.hpp"
26#include "../exceptions.hpp"
27#include "../traits.hpp"
28
29#include <mpi/mpi.hpp>
30
31namespace nda {
32
60 template <typename A>
61 void mpi_broadcast(A &a, mpi::communicator comm = {}, int root = 0)
63 {
64 static_assert(has_contiguous_layout<A>, "Error in MPI broadcast for nda::Array: Array needs to be contiguous");
65 auto dims = a.shape();
66 MPI_Bcast(&dims[0], dims.size(), mpi::mpi_type<typename decltype(dims)::value_type>::get(), root, comm.get());
67 if (comm.rank() != root) { resize_or_check_if_view(a, dims); }
68 MPI_Bcast(a.data(), a.size(), mpi::mpi_type<typename A::value_type>::get(), root, comm.get());
69 }
70
71} // namespace nda
Provides basic functions to create and manipulate arrays and views.
Provides concepts for the nda library.
Provides a custom runtime error class and macros to assert conditions and throw exceptions.
void resize_or_check_if_view(A &a, std::array< long, A::rank > const &sha)
Resize a given regular array to the given shape or check if a given view as the correct shape.
void mpi_broadcast(A &a, mpi::communicator comm={}, int root=0)
Implementation of an MPI broadcast for nda::basic_array or nda::basic_array_view types.
Definition broadcast.hpp:61
constexpr bool is_regular_or_view_v
Constexpr variable that is true if type A is either a regular array or a view.
Definition traits.hpp:163
constexpr bool has_contiguous_layout
Constexpr variable that is true if type A has the contiguous nda::layout_prop_e guarantee.
Definition traits.hpp:330
Provides type traits for the nda library.