40 template <
typename G>
bool have_mpi_equal_shape(
const G &bg,
const mpi::communicator &comm) {
41 if constexpr (G::arity == 1) {
42 return mpi::all_equal(bg.size(), comm);
44 return mpi::all_equal(bg.size1(), comm) && mpi::all_equal(bg.size2(), comm);
49 template <
typename G> std::size_t hash_names(G
const &bg) {
50 auto bin_op = [](std::size_t acc,
auto const &name) {
return acc + std::hash<std::string>{}(name); };
51 if constexpr (G::arity == 1) {
52 return std::accumulate(bg.block_names().begin(), bg.block_names().end(), std::size_t{0}, bin_op);
55 for (
auto const &vec : bg.block_names()) {
hash += std::accumulate(vec.begin(), vec.end(), std::size_t{0}, bin_op); }
79 template <BlockGf BG>
void mpi_broadcast(BG &&bg, mpi::communicator c,
int root) {
80 constexpr bool is_view = std::decay_t<BG>::is_view;
85 mpi::broadcast(bg._block_names, c, root);
88 auto names = bg.block_names();
89 mpi::broadcast(names, c, root);
90 EXPECTS(bg.block_names() == names);
94 mpi::broadcast(bg.data(), c, root);
123 template <BlockGf BG1, BlockGf BG2>
125 bool all, MPI_Op op) {
126 constexpr bool is_view = std::decay_t<BG2>::is_view;
129 EXPECTS(mpi::all_equal(detail::hash_names(bg_in), c));
130 if (not detail::have_mpi_equal_shape(bg_in, c))
131 TRIQS_RUNTIME_ERROR <<
"Error in triqs::gfs::mpi_reduce_into: Shapes of input block GFs must be equal";
134 if ((c.rank() == root || all)) {
136 EXPECTS(bg_in.block_names() == bg_out.block_names());
138 bg_out._block_names = bg_in.block_names();
143 mpi::reduce_into(bg_in.data(), bg_out.data(), c, root, all, op);
166 template <BlockGf BG>
auto mpi_reduce(BG
const &bg, mpi::communicator c = {},
int root = 0,
bool all =
false, MPI_Op op = MPI_SUM) {
167 auto res =
typename BG::regular_type{};
Provides the block Green's function container.
TRIQS exception hierarchy and related macros.
void mpi_broadcast(BG &&bg, mpi::communicator c={}, int root=0)
Implementation of an MPI broadcast for triqs::gfs::block_gf and triqs::gfs::block_gf_view types.
void mpi_reduce_into(BG1 const &bg_in, BG2 &&bg_out, mpi::communicator c={}, int root=0, bool all=false, MPI_Op op=MPI_SUM)
Implementation of an MPI reduce for triqs::gfs::block_gf and triqs::gfs::block_gf_view types that red...
auto mpi_reduce(BG const &bg, mpi::communicator c={}, int root=0, bool all=false, MPI_Op op=MPI_SUM)
Implementation of an MPI reduce for triqs::gfs::block_gf and triqs::gfs::block_gf_view types.
uint64_t hash(Ts &&...ts)
Generic hash function for multiple arguments.
#define TRIQS_RUNTIME_ERROR
Throw a triqs::runtime_error with the current source location.
Trait that detects view types by checking for inheritance from is_view_tag.