TRIQS/mpi
2.0.0
C++ interface to MPI
Toggle main menu visibility
Loading...
Searching...
No Matches
operators.hpp
Go to the documentation of this file.
1
// Copyright (c) 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, Alexander Hampel, Olivier Parcollet, Nils Wentzell
16
21
22
#pragma once
23
24
#include "
./utils.hpp
"
25
26
#include <mpi.h>
27
28
namespace
mpi {
29
34
46
template
<
typename
T, T (*F)(T const &, T const &)> MPI_Op
map_C_function
() {
47
MPI_Op myOp{};
48
MPI_User_function *map_function = +[](
void
*in,
void
*inout,
int
*len, MPI_Datatype *) {
// NOLINT (MPI_Op_create needs a non-const pointer)
49
auto
*inT =
static_cast<
T *
>
(in);
50
auto
*inoutT =
static_cast<
T *
>
(inout);
51
for
(
int
i = 0; i < *len; ++i, ++inT, ++inoutT) { *inoutT = F(*inoutT, *inT); }
52
};
53
check_mpi_call
(MPI_Op_create(map_function,
true
, &myOp),
"MPI_Op_create"
);
54
return
myOp;
55
}
56
57
namespace
detail {
58
59
// Generic addition. FIXME Convert to lambda, requires gcc 13.2+
60
template
<
typename
T> T generic_add(T
const
&lhs, T
const
&rhs) {
return
lhs + rhs; }
61
62
}
// namespace detail
63
72
template
<
typename
T> MPI_Op
map_add
() {
return
map_C_function<T, detail::generic_add>
(); }
73
74
}
// namespace mpi
mpi::map_add
MPI_Op map_add()
Create a new MPI_Op for a generic addition by calling MPI_Op_create.
Definition
operators.hpp:72
mpi::map_C_function
MPI_Op map_C_function()
Create a new MPI_Op from a given binary function by calling MPI_Op_create.
Definition
operators.hpp:46
mpi::check_mpi_call
void check_mpi_call(int errcode, const std::string &mpi_routine)
Check the success of an MPI call.
Definition
utils.hpp:48
utils.hpp
Provides general utilities related to MPI.
mpi
operators.hpp
Generated by
1.17.0