GPRidge v1.0.0
GPR-accelerated saddle point searches on potential energy surfaces
☾
Toggle main menu visibility
Loading...
Searching...
No Matches
Lp64Limits.h
Go to the documentation of this file.
1
// SPDX-License-Identifier: MIT
2
// Copyright (c) gpridge developers
3
// See LICENSE for details.
4
22
23
#ifndef GPR_LINALG_LP64_LIMITS_H_
24
#define GPR_LINALG_LP64_LIMITS_H_
25
26
#include <algorithm>
27
#include <atomic>
28
#include <cstdint>
29
#include <limits>
30
31
namespace
gpr
{
32
namespace
linalg
{
33
35
inline
constexpr
std::int64_t
kLp64IndexLimit
=
36
std::numeric_limits<std::int32_t>::max();
37
39
enum
Lp64DescriptorField
:
int
{
40
kDescM
= 2,
41
kDescN
= 3,
42
kDescMb
= 4,
43
kDescNb
= 5,
44
kDescRsrc
= 6,
45
kDescCsrc
= 7,
46
kDescLld
= 8
47
};
48
55
constexpr
std::int64_t
blockCyclicLocalExtent
(std::int64_t n, std::int64_t nb,
56
std::int64_t iproc,
57
std::int64_t isrc,
58
std::int64_t nprocs)
noexcept
59
{
60
if
(n <= 0 || nb <= 0 || nprocs <= 0)
return
0;
61
const
std::int64_t distance = ((iproc - isrc) % nprocs + nprocs) % nprocs;
62
const
std::int64_t blocks = n / nb;
63
std::int64_t extent = (blocks / nprocs) * nb;
64
const
std::int64_t extra = blocks % nprocs;
65
if
(distance < extra)
66
extent += nb;
67
else
if
(distance == extra)
68
extent += n % nb;
69
return
extent;
70
}
71
84
constexpr
std::int64_t
largestLocalEntries
(std::int64_t m, std::int64_t n,
85
std::int64_t mb, std::int64_t nb,
86
std::int64_t rsrc, std::int64_t csrc,
87
std::int64_t nprow,
88
std::int64_t npcol)
noexcept
89
{
90
const
std::int64_t rows =
blockCyclicLocalExtent
(m, mb, rsrc, rsrc, nprow);
91
const
std::int64_t cols =
blockCyclicLocalExtent
(n, nb, csrc, csrc, npcol);
92
return
std::max<std::int64_t>(1, rows) * cols;
93
}
94
98
constexpr
std::int64_t
largestLocalEntries
(
const
int
* desc,
int
nprow,
99
int
npcol)
noexcept
100
{
101
const
std::int64_t by_layout =
largestLocalEntries
(
102
desc[
kDescM
], desc[
kDescN
], desc[
kDescMb
], desc[
kDescNb
],
103
desc[
kDescRsrc
], desc[
kDescCsrc
], nprow, npcol);
104
const
std::int64_t cols =
blockCyclicLocalExtent
(
105
desc[
kDescN
], desc[
kDescNb
], desc[
kDescCsrc
], desc[
kDescCsrc
], npcol);
106
return
std::max(by_layout,
107
static_cast<
std::int64_t
>
(desc[
kDescLld
]) * cols);
108
}
109
114
inline
std::atomic<std::int64_t>&
lp64IndexLimitStore
() noexcept
115
{
116
static
std::atomic<std::int64_t> limit{
kLp64IndexLimit
};
117
return
limit;
118
}
119
120
inline
std::int64_t
lp64IndexLimit
() noexcept
121
{
122
return
lp64IndexLimitStore
().load(std::memory_order_relaxed);
123
}
124
126
class
ScopedLp64IndexLimit
{
127
public
:
128
explicit
ScopedLp64IndexLimit
(std::int64_t limit) noexcept
129
: previous_(
lp64IndexLimitStore
().exchange(limit))
130
{
131
}
132
~ScopedLp64IndexLimit
()
133
{
134
lp64IndexLimitStore
().store(previous_);
135
}
136
ScopedLp64IndexLimit
(
const
ScopedLp64IndexLimit
&) =
delete
;
137
ScopedLp64IndexLimit
&
operator=
(
const
ScopedLp64IndexLimit
&) =
delete
;
138
139
private
:
140
std::int64_t previous_;
141
};
142
151
inline
bool
exceedsLp64
(
const
int
* desc,
int
nprow,
int
npcol)
noexcept
152
{
153
return
largestLocalEntries
(desc, nprow, npcol) >
lp64IndexLimit
();
154
}
155
157
inline
bool
exceedsLp64
(std::int64_t count)
noexcept
158
{
159
return
count >
lp64IndexLimit
();
160
}
161
162
}
// namespace linalg
163
}
// namespace gpr
164
165
#endif
// GPR_LINALG_LP64_LIMITS_H_
gpr::linalg::ScopedLp64IndexLimit::ScopedLp64IndexLimit
ScopedLp64IndexLimit(const ScopedLp64IndexLimit &)=delete
gpr::linalg::ScopedLp64IndexLimit::ScopedLp64IndexLimit
ScopedLp64IndexLimit(std::int64_t limit) noexcept
Definition
Lp64Limits.h:128
gpr::linalg::ScopedLp64IndexLimit::~ScopedLp64IndexLimit
~ScopedLp64IndexLimit()
Definition
Lp64Limits.h:132
gpr::linalg::ScopedLp64IndexLimit::operator=
ScopedLp64IndexLimit & operator=(const ScopedLp64IndexLimit &)=delete
gpr::linalg
Dense and structured linear algebra behind the GP: Cholesky and eigen solvers, linear operators,...
Definition
ConditionedKernel.h:14
gpr::linalg::lp64IndexLimit
std::int64_t lp64IndexLimit() noexcept
Definition
Lp64Limits.h:120
gpr::linalg::lp64IndexLimitStore
std::atomic< std::int64_t > & lp64IndexLimitStore() noexcept
Definition
Lp64Limits.h:114
gpr::linalg::Lp64DescriptorField
Lp64DescriptorField
Offsets of the ScaLAPACK array descriptor fields (DTYPE_ .. LLD_ - 1).
Definition
Lp64Limits.h:39
gpr::linalg::kDescLld
@ kDescLld
Definition
Lp64Limits.h:46
gpr::linalg::kDescNb
@ kDescNb
Definition
Lp64Limits.h:43
gpr::linalg::kDescM
@ kDescM
Definition
Lp64Limits.h:40
gpr::linalg::kDescRsrc
@ kDescRsrc
Definition
Lp64Limits.h:44
gpr::linalg::kDescCsrc
@ kDescCsrc
Definition
Lp64Limits.h:45
gpr::linalg::kDescMb
@ kDescMb
Definition
Lp64Limits.h:42
gpr::linalg::kDescN
@ kDescN
Definition
Lp64Limits.h:41
gpr::linalg::largestLocalEntries
constexpr std::int64_t largestLocalEntries(std::int64_t m, std::int64_t n, std::int64_t mb, std::int64_t nb, std::int64_t rsrc, std::int64_t csrc, std::int64_t nprow, std::int64_t npcol) noexcept
Definition
Lp64Limits.h:84
gpr::linalg::exceedsLp64
bool exceedsLp64(const int *desc, int nprow, int npcol) noexcept
Definition
Lp64Limits.h:151
gpr::linalg::blockCyclicLocalExtent
constexpr std::int64_t blockCyclicLocalExtent(std::int64_t n, std::int64_t nb, std::int64_t iproc, std::int64_t isrc, std::int64_t nprocs) noexcept
Definition
Lp64Limits.h:55
gpr::linalg::kLp64IndexLimit
constexpr std::int64_t kLp64IndexLimit
Largest element offset an LP64 ScaLAPACK routine forms without overflow.
Definition
Lp64Limits.h:35
gpr
Gaussian-process regression, kernels, priors, and the searches that run on the surrogate.
Definition
Macros.h:16
gpr
linalg
Lp64Limits.h
Generated by
1.17.0
Generated by
Doxygen 1.17.0
Analytics by
Antics
provided by
TurtleTech ehf