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) 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, Olivier Parcollet, Nils Wentzell
16
22#pragma once
23
24#include "./utils.hpp"
26#include "../traits.hpp"
27
28#include <mpi/mpi.hpp>
29
30#include <cstddef>
31#include <span>
32
33namespace nda {
34
55 template <typename A>
56 void mpi_broadcast(A &&a, mpi::communicator comm = {}, int root = 0) // NOLINT (temporary views are allowed here)
58 {
59 detail::check_layout_mpi_compatible(a, "mpi_broadcast");
60 auto dims = a.shape();
61 mpi::broadcast(dims, comm, root);
62 if (comm.rank() != root) { resize_or_check_if_view(a, dims); }
63 mpi::broadcast_range(std::span{a.data(), static_cast<std::size_t>(a.size())}, comm, root);
64 }
65
66} // namespace nda
Provides basic functions to create and manipulate arrays and views.
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:56
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
Provides various utility functions used by the MPI interface of nda.
Provides type traits for the nda library.