GPRidge v1.0.0
GPR-accelerated saddle point searches on potential energy surfaces
☾
Toggle main menu visibility
Loading...
Searching...
No Matches
CollectiveAssembly.h
Go to the documentation of this file.
1
// SPDX-License-Identifier: MIT
2
// Copyright (c) gpridge developers
3
#pragma once
4
5
#include <Eigen/Core>
6
#include <algorithm>
7
#include <exception>
8
#include <limits>
9
#include <stdexcept>
10
11
#include "
MpiCollectives.h
"
12
13
namespace
gpr::linalg
{
14
18
template
<
class
Matrices,
class
Body>
19
void
assembleCollectively
(
const
MpiContext
& context, Matrices& result,
20
const
Body& body)
21
{
22
std::exception_ptr failure;
23
try
{
24
body();
25
}
catch
(...) {
26
failure = std::current_exception();
27
}
28
#if defined(GPR_HAVE_MPI) || defined(GPR_LINALG_SCALAPACK)
29
if
(context.
is_distributed
()) {
30
int
failed = failure ? 1 : 0;
31
if
(MPI_Allreduce(MPI_IN_PLACE, &failed, 1, MPI_INT, MPI_MAX,
32
context.
comm
) != MPI_SUCCESS)
33
throw
std::runtime_error(
"could not share assembly status"
);
34
if
(failed && !failure)
35
throw
std::runtime_error(
"assembly failed on another rank"
);
36
}
37
#endif
38
if
(failure) std::rethrow_exception(failure);
39
if
(!context.
is_distributed
())
return
;
40
constexpr
Eigen::Index maximum = std::numeric_limits<int>::max();
41
for
(
auto
& matrix: result)
42
for
(Eigen::Index offset = 0; offset < matrix.size();) {
43
const
int
entries =
44
static_cast<
int
>
(std::min(maximum, matrix.size() - offset));
45
disjoint_sum_bcast
(matrix.data() + offset, entries, context);
46
offset += entries;
47
}
48
}
49
50
}
// namespace gpr::linalg
MpiCollectives.h
gpr::linalg
Dense and structured linear algebra behind the GP: Cholesky and eigen solvers, linear operators,...
Definition
ConditionedKernel.h:14
gpr::linalg::disjoint_sum_bcast
void disjoint_sum_bcast(double *data, int count, const MpiContext &context)
Definition
MpiCollectives.h:49
gpr::linalg::assembleCollectively
void assembleCollectively(const MpiContext &context, Matrices &result, const Body &body)
Definition
CollectiveAssembly.h:19
gpr::linalg::MpiContext
Definition
MpiContext.h:59
gpr::linalg::MpiContext::is_distributed
bool is_distributed() const noexcept
Definition
MpiContext.h:67
gpr::linalg::MpiContext::comm
MpiCommType comm
Definition
MpiContext.h:62
gpr
linalg
CollectiveAssembly.h
Generated by
1.17.0
Generated by
Doxygen 1.17.0
Analytics by
Antics
provided by
TurtleTech ehf