TRIQS/mpi
2.0.0
C++ interface to MPI
Toggle main menu visibility
Loading...
Searching...
No Matches
string.hpp
Go to the documentation of this file.
1
// Copyright (c) 2019-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
21
22
#pragma once
23
24
#include "
./communicator.hpp
"
25
#include "
./generic_communication.hpp
"
26
#include "
./ranges.hpp
"
27
28
#include <string>
29
30
namespace
mpi {
31
36
47
inline
void
mpi_broadcast
(std::string &s,
communicator
c,
int
root) {
48
auto
count = s.size();
49
broadcast
(count, c, root);
50
if
(c.
rank
() != root) s.resize(count);
51
broadcast_range
(s, c, root);
52
}
53
67
inline
void
mpi_gather_into
(std::string
const
&s_in, std::string &s_out,
communicator
c = {},
int
root = 0,
bool
all =
false
) {
68
auto
const
gather_size =
mpi::all_reduce
(s_in.size(), c);
69
if
((c.rank() == root || all) && s_out.size() != gather_size) s_out.resize(gather_size);
70
gather_range
(s_in, s_out, c, root, all);
71
}
72
74
75
}
// namespace mpi
mpi::communicator
C++ wrapper around MPI_Comm providing various convenience functions.
Definition
communicator.hpp:51
mpi::communicator::rank
int rank() const
Get the rank of the calling process in the communicator.
Definition
communicator.hpp:72
communicator.hpp
Provides a C++ wrapper class for an MPI_Comm object.
generic_communication.hpp
Provides generic implementations for a subset of collective MPI communications (broadcast,...
mpi::mpi_gather_into
void mpi_gather_into(T const &x, R &&rg, communicator c={}, int root=0, bool all=false)
Implementation of an MPI gather that gathers directly into an existing output range for types that ha...
Definition
generic_communication.hpp:442
mpi::gather_range
void gather_range(R1 &&in_rg, R2 &&out_rg, communicator c={}, int root=0, bool all=false)
Implementation of an MPI gather for mpi::MPICompatibleRange objects.
Definition
ranges.hpp:278
mpi::broadcast_range
void broadcast_range(R &&rg, communicator c={}, int root=0)
Implementation of an MPI broadcast for std::ranges::sized_range objects.
Definition
ranges.hpp:69
mpi::mpi_broadcast
void mpi_broadcast(std::array< T, N > &arr, communicator c={}, int root=0)
Implementation of an MPI broadcast for a std::array.
Definition
array.hpp:53
mpi::all_reduce
decltype(auto) all_reduce(T &&x, communicator c={}, MPI_Op op=MPI_SUM)
Generic MPI all-reduce.
Definition
generic_communication.hpp:242
mpi::broadcast
void broadcast(T &&x, communicator c={}, int root=0)
Generic MPI broadcast.
Definition
generic_communication.hpp:68
ranges.hpp
Provides an MPI broadcast, reduce, scatter and gather for generic ranges.
mpi
string.hpp
Generated by
1.17.0