ESPResSo
Extensible Simulation Package for Research on Soft Matter Systems
Loading...
Searching...
No Matches
CodeInfo.cpp
Go to the documentation of this file.
1/*
2 * Copyright (C) 2022 The ESPResSo project
3 *
4 * This file is part of ESPResSo.
5 *
6 * ESPResSo is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * ESPResSo is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20#include "CodeInfo.hpp"
21
22#include "config/config-features.hpp"
23#include "config/config-features.impl.hpp"
24#include "config/version.hpp"
26
27#include <boost/algorithm/string/join.hpp>
28
29#include <cstddef>
30#include <stdexcept>
31#include <string>
32#include <unordered_set>
33#include <vector>
34
35namespace ScriptInterface {
36namespace CodeInfo {
37
38static auto get_feature_vector(char const *const ptr[], std::size_t len) {
39 return std::vector<std::string>{ptr, ptr + len};
40}
41
42static auto get_feature_set(char const *const ptr[], std::size_t len) {
43 return std::unordered_set<std::string>(ptr, ptr + len);
44}
45
46Variant CodeInfo::do_call_method(std::string const &name, VariantMap const &) {
47 if (name == "features") {
49 }
50 if (name == "all_features") {
53 }
54 if (name == "build_type") {
55 return std::string(ESPRESSO_BUILD_TYPE);
56 }
57 if (name == "scafacos_methods") {
58#ifdef ESPRESSO_SCAFACOS
60#else // ESPRESSO_SCAFACOS
61 return make_vector_of_variants(std::vector<std::string>(0));
62#endif // ESPRESSO_SCAFACOS
63 }
64 if (name == "has_fast_math") {
65#if defined(__FAST_MATH__)
66 return true;
67#else
68 return false;
69#endif
70 }
71 return {};
72}
73
74void check_features(std::vector<std::string> const &features) {
77 std::vector<std::string> missing_features{};
78 for (auto const &feature : features) {
79 if (not allowed.contains(feature)) {
80 throw std::runtime_error("Unknown feature '" + feature + "'");
81 }
82 if (not compiled_features.contains(feature)) {
83 missing_features.emplace_back(feature);
84 }
85 }
86 if (not missing_features.empty()) {
87 throw std::runtime_error("Missing features " +
88 boost::algorithm::join(missing_features, ", "));
89 }
90}
91
92} // namespace CodeInfo
93} // namespace ScriptInterface
Variant do_call_method(std::string const &name, VariantMap const &parameters) override
Definition CodeInfo.cpp:46
std::string_view name() const
cudaStream_t stream[1]
CUDA streams for parallel computing on CPU and GPU.
static auto get_feature_set(char const *const ptr[], std::size_t len)
Definition CodeInfo.cpp:42
void check_features(std::vector< std::string > const &features)
Definition CodeInfo.cpp:74
static auto get_feature_vector(char const *const ptr[], std::size_t len)
Definition CodeInfo.cpp:38
std::vector< std::string > available_methods()
Fetch list of methods compiled in ScaFaCoS.
Definition scafacos.cpp:50
std::unordered_map< std::string, Variant > VariantMap
Definition Variant.hpp:133
auto make_vector_of_variants(std::vector< T > const &v)
Definition Variant.hpp:148
Recursive variant implementation.
Definition Variant.hpp:84