TRIQS/triqs_tprf 4.0.0
A TRIQS application
Loading...
Searching...
No Matches
mpi.hpp
1/*******************************************************************************
2 *
3 * TRIQS: a Toolbox for Research in Interacting Quantum Systems
4 *
5 * Copyright (C) 2018, The Simons Foundation
6 * Author: H. U.R. Strand
7 *
8 * TRIQS is free software: you can redistribute it and/or modify it under the
9 * terms of the GNU General Public License as published by the Free Software
10 * Foundation, either version 3 of the License, or (at your option) any later
11 * version.
12 *
13 * TRIQS is distributed in the hope that it will be useful, but WITHOUT ANY
14 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
16 * details.
17 *
18 * You should have received a copy of the GNU General Public License along with
19 * TRIQS. If not, see <http://www.gnu.org/licenses/>.
20 *
21 ******************************************************************************/
22#pragma once
23
24#include <itertools/itertools.hpp>
25#include <mpi/mpi.hpp>
26
27#include <span>
28
29#include "types.hpp"
30
31namespace triqs_tprf {
32
33 template <class T> auto mpi_view(const T &mesh, mpi::communicator c = {}) {
34
35 auto slice = itertools::chunk_range(0, mesh.size(), c.size(), c.rank());
36 int size = slice.second - slice.first;
37
38 std::vector<typename T::mesh_point_t> arr{};
39 arr.reserve(size);
40
41 auto iter = std::next(mesh.begin(), slice.first);
42 for ([[maybe_unused]] auto idx : range(0, size)) {
43 arr.emplace_back(*iter);
44 iter++;
45 }
46
47 return arr;
48 }
49
50} // namespace triqs_tprf