TRIQS/TRIQS 4.0.0
Researching Interacting Quantum Systems
Loading...
Searching...
No Matches
mpi.hpp
Go to the documentation of this file.
1// Copyright (c) 2020-2021 Simons Foundation
2//
3// This program is free software: you can redistribute it and/or modify
4// it under the terms of the GNU General Public License as published by
5// the Free Software Foundation, either version 3 of the License, or
6// (at your option) any later version.
7//
8// This program is distributed in the hope that it will be useful,
9// but WITHOUT ANY WARRANTY; without even the implied warranty of
10// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11// GNU General Public License for more details.
12//
13// You may obtain a copy of the License at
14// https://www.gnu.org/licenses/gpl-3.0.txt
15//
16// Authors: Michel Ferrero, Olivier Parcollet, Nils Wentzell
17
22
23#pragma once
24
25#include "./gf.hpp"
27
28#include <mpi/mpi.hpp>
29#include <nda/nda.hpp>
30
31#include <type_traits>
32
33namespace triqs::gfs {
34
39
53 template <MemoryGf G> void mpi_broadcast(G &&g, mpi::communicator c, int root) { // NOLINT (temporary views are allowed)
54 constexpr bool is_view = std::decay_t<G>::is_view;
55
56 // broadcast mesh
57 if constexpr (!is_view) {
58 // for non-view GFs, we broadcast the mesh directly into the GF
59 mpi::broadcast(g._mesh, c, root);
60 } else {
61 // for views, we keep the mesh in the GF but check that it is the same as the mesh on the root process
62 auto m = g.mesh();
63 mpi::broadcast(m, c, root);
64 EXPECTS(m.mesh_hash() == g.mesh().mesh_hash());
65 }
66
67 // broadcast data
68 mpi::broadcast(g.data(), c, root);
69 }
70
97 template <MemoryGf G1, MemoryGf G2>
98 void mpi_reduce_into(G1 const &g_in, G2 &&g_out, mpi::communicator c, // NOLINT (temporary views are allowed here)
99 int root, bool all, MPI_Op op) {
100 constexpr bool is_view = std::decay_t<G2>::is_view;
101
102 // check the meshes of the input GFs
103 EXPECTS(mpi::all_equal(g_in.mesh().mesh_hash(), c));
104
105 // assign (check) the mesh of the output GF (view) on receiving ranks
106 if (c.rank() == root || all) {
107 if constexpr (is_view) {
108 EXPECTS(g_in.mesh().mesh_hash() == g_out.mesh().mesh_hash());
109 } else {
110 g_out._mesh = g_in.mesh();
111 }
112 }
113
114 // reduce the data
115 mpi::reduce_into(g_in.data(), g_out.data(), c, root, all, op);
116 }
117
138 template <MemoryGf G> auto mpi_reduce(G const &g, mpi::communicator c = {}, int root = 0, bool all = false, MPI_Op op = MPI_SUM) {
139 auto res = typename G::regular_type{};
140 mpi_reduce_into(g, res, c, root, all, op);
141 return res;
142 }
143
145
146} // namespace triqs::gfs
Provides the Green's function class.
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.
Definition mpi.hpp:79
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...
Definition mpi.hpp:124
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.
Definition mpi.hpp:166
Common macros used in TRIQS.
Trait that detects view types by checking for inheritance from is_view_tag.
Definition traits.hpp:74