GPRidge v1.0.0
GPR-accelerated saddle point searches on potential energy surfaces
☾
Toggle main menu visibility
Loading...
Searching...
No Matches
OptimAbi.h
Go to the documentation of this file.
1
// SPDX-License-Identifier: MIT
2
// Copyright (c) gpridge developers
3
// See LICENSE for details.
4
#pragma once
5
6
// Layout stamp between gprn/gprd and libgpridge.
7
//
8
// GPNEBResult and OCINEBResult are filled by the library and destroyed by
9
// the driver. A driver built against an older header frees the wrong
10
// offsets and segfaults. The byte counts below are compiled into the
11
// driver from this header, and libraryResultLayout() returns the counts
12
// compiled into libgpridge. They disagree exactly when the two were not
13
// built together.
14
//
15
// Bump kResultLayoutVersion when either struct's layout changes, including
16
// a reorder that keeps the size. A size change is caught even if the
17
// version is left alone.
18
19
#include <cstddef>
20
#include <cstdint>
21
#include <stdexcept>
22
#include <string>
23
24
#include "
neb/OCINEBController.h
"
25
26
namespace
gpr::optim_abi
{
27
30
inline
constexpr
std::uint32_t
kResultLayoutVersion
= 2;
31
32
struct
ResultLayoutStamp
{
33
std::uint32_t
version
= 0;
34
std::uint32_t
gpneb_result_bytes
= 0;
35
std::uint32_t
ocineb_result_bytes
= 0;
36
};
37
38
[[nodiscard]]
inline
bool
operator==
(
const
ResultLayoutStamp
& a,
39
const
ResultLayoutStamp
& b)
noexcept
40
{
41
return
a.version == b.version &&
42
a.gpneb_result_bytes == b.gpneb_result_bytes &&
43
a.ocineb_result_bytes == b.ocineb_result_bytes;
44
}
45
47
[[nodiscard]]
inline
ResultLayoutStamp
compiledResultLayout
() noexcept
48
{
49
return
{
kResultLayoutVersion
,
50
static_cast<
std::uint32_t
>
(
sizeof
(
neb::GPNEBResult
)),
51
static_cast<
std::uint32_t
>
(
sizeof
(
neb::OCINEBResult
))};
52
}
53
56
[[nodiscard]] ResultLayoutStamp
libraryResultLayout
();
57
58
[[nodiscard]]
inline
std::string
describe
(
const
ResultLayoutStamp
& stamp)
59
{
60
return
std::to_string(stamp.
version
) +
"/"
+
61
std::to_string(stamp.
gpneb_result_bytes
) +
"/"
+
62
std::to_string(stamp.
ocineb_result_bytes
);
63
}
64
66
[[nodiscard]]
inline
std::string
resultLayoutMismatch
(
67
const
ResultLayoutStamp
& driver,
const
ResultLayoutStamp
& library)
68
{
69
if
(driver == library)
return
{};
70
return
"libgpridge result layout mismatch: this program was built "
71
"against layout "
+
72
std::to_string(driver.
version
) +
" (GPNEBResult "
+
73
std::to_string(driver.
gpneb_result_bytes
) +
" bytes, OCINEBResult "
+
74
std::to_string(driver.
ocineb_result_bytes
) +
75
" bytes) but the loaded library reports layout "
+
76
std::to_string(library.
version
) +
" (GPNEBResult "
+
77
std::to_string(library.
gpneb_result_bytes
) +
78
" bytes, OCINEBResult "
+
79
std::to_string(library.
ocineb_result_bytes
) +
80
" bytes). Rebuild gprn and gprd against this libgpridge; a "
81
"stale driver frees the wrong offsets in OCINEBResult's "
82
"destructor."
;
83
}
84
85
inline
void
refuseMismatchedResultLayout
(
const
ResultLayoutStamp
& driver,
86
const
ResultLayoutStamp
& library)
87
{
88
const
std::string message =
resultLayoutMismatch
(driver, library);
89
if
(!message.empty())
throw
std::runtime_error(message);
90
}
91
92
inline
void
requireResultLayout
()
93
{
94
refuseMismatchedResultLayout
(
compiledResultLayout
(),
libraryResultLayout
());
95
}
96
97
}
// namespace gpr::optim_abi
OCINEBController.h
GP-OCINEB controller – faithful port of the eOn ~NEBOcinebController~ pattern (eOn/client/ NEBOcinebC...
gpr::optim_abi
Definition
OptimAbi.cpp:7
gpr::optim_abi::operator==
bool operator==(const ResultLayoutStamp &a, const ResultLayoutStamp &b) noexcept
Definition
OptimAbi.h:38
gpr::optim_abi::requireResultLayout
void requireResultLayout()
Definition
OptimAbi.h:92
gpr::optim_abi::kResultLayoutVersion
constexpr std::uint32_t kResultLayoutVersion
Definition
OptimAbi.h:30
gpr::optim_abi::refuseMismatchedResultLayout
void refuseMismatchedResultLayout(const ResultLayoutStamp &driver, const ResultLayoutStamp &library)
Definition
OptimAbi.h:85
gpr::optim_abi::describe
std::string describe(const ResultLayoutStamp &stamp)
Definition
OptimAbi.h:58
gpr::optim_abi::compiledResultLayout
ResultLayoutStamp compiledResultLayout() noexcept
What this translation unit compiled against.
Definition
OptimAbi.h:47
gpr::optim_abi::resultLayoutMismatch
std::string resultLayoutMismatch(const ResultLayoutStamp &driver, const ResultLayoutStamp &library)
Empty when the stamps agree. Otherwise a message naming both.
Definition
OptimAbi.h:66
gpr::optim_abi::libraryResultLayout
ResultLayoutStamp libraryResultLayout()
Definition
OptimAbi.cpp:9
gpr::neb::GPNEBResult
Definition
GPNEB.h:3681
gpr::neb::OCINEBResult
Definition
OCINEBController.h:1337
gpr::optim_abi::ResultLayoutStamp
Definition
OptimAbi.h:32
gpr::optim_abi::ResultLayoutStamp::gpneb_result_bytes
std::uint32_t gpneb_result_bytes
Definition
OptimAbi.h:34
gpr::optim_abi::ResultLayoutStamp::version
std::uint32_t version
Definition
OptimAbi.h:33
gpr::optim_abi::ResultLayoutStamp::ocineb_result_bytes
std::uint32_t ocineb_result_bytes
Definition
OptimAbi.h:35
gpr
OptimAbi.h
Generated by
1.17.0
Generated by
Doxygen 1.17.0
Analytics by
Antics
provided by
TurtleTech ehf