TRIQS/nda
2.0.0
Multi-dimensional array library for C++
Toggle main menu visibility
Loading...
Searching...
No Matches
broadcast.hpp
Go to the documentation of this file.
1
// Copyright (c) 2024--present, The Simons Foundation
2
// This file is part of TRIQS/nda and is licensed under the Apache License, Version 2.0.
3
// SPDX-License-Identifier: Apache-2.0
4
// See LICENSE in the root of this distribution for details.
5
10
11
#pragma once
12
13
#include "
../basic_functions.hpp
"
14
#include "
../traits.hpp
"
15
16
#include <mpi/mpi.hpp>
17
18
#include <cstddef>
19
#include <span>
20
21
namespace
nda {
22
44
template
<
typename
A>
45
void
mpi_broadcast
(A &&a, mpi::communicator comm = {},
int
root = 0)
// NOLINT (temporary views are allowed here)
46
requires
(
is_regular_or_view_v<A>
)
47
{
48
// broadcast the shape of the input array/view on the root process
49
auto
dims = a.shape();
50
mpi::broadcast(dims, comm, root);
51
52
// resize or check the output array/view on non-root processes
53
if
(comm.rank() != root)
resize_or_check_if_view
(a, dims);
54
55
// call mpi::broadcast_range with a span if the array/view is contiguous with positive strides
56
if
(a.is_contiguous() and a.has_positive_strides()) {
57
auto
a_span = std::span{a.data(),
static_cast<
std::size_t
>
(a.size())};
58
mpi::broadcast_range(a_span, comm, root);
59
}
else
{
60
mpi::broadcast_range(a, comm, root);
61
}
62
}
63
64
}
// namespace nda
basic_functions.hpp
Provides basic functions to create and manipulate arrays and views.
nda::resize_or_check_if_view
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.
Definition
basic_functions.hpp:305
nda::mpi_broadcast
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:45
nda::is_regular_or_view_v
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:162
traits.hpp
Provides type traits for the nda library.
nda
mpi
broadcast.hpp
Generated by
1.17.0