LIBINT 2.7.2
initialize.h
1/*
2 * Copyright (C) 2004-2021 Edward F. Valeev
3 *
4 * This file is part of Libint.
5 *
6 * Libint is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU Lesser 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 * Libint 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 Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with Libint. If not, see <http://www.gnu.org/licenses/>.
18 *
19 */
20
21#ifndef _libint2_src_lib_libint_initialize_h_
22#define _libint2_src_lib_libint_initialize_h_
23
24#include <libint2/util/cxxstd.h>
25#if LIBINT2_CPLUSPLUS_STD < 2011
26# error "Libint2 C++ API requires C++11 support"
27#endif
28
29#include <atomic>
30#include <cassert>
31#include <iostream>
32
33#include <libint2.h>
34#include <libint2/util/deprecated.h>
35#include <libint2/util/singleton.h>
36#include <libint2/deriv_map.h>
37
38namespace libint2 {
39
40 namespace detail {
43 libint2_static_init();
44 libint2::DerivMapGenerator::initialize();
45 }
47 libint2_static_cleanup();
48 }
49 };
50
51 inline std::atomic<bool>& verbose_accessor() {
52 static std::atomic<bool> value{false};
53 return value;
54 }
55 inline std::ostream*& verbose_stream_accessor() {
56 static std::ostream* value = &std::clog;
57 return value;
58 }
59 } // namespace libint2::detail
60
63 inline bool initialized() {
64 using namespace detail;
65 return managed_singleton<__initializer>::instance_exists();
66 }
70 inline void initialize(bool verbose = false) {
71 if (!initialized()) {
72 using namespace detail;
73 __initializer *x = managed_singleton<__initializer>::instance();
74 (void) x; // to suppress unused variable warning (not guaranteed to work) TODO revise when upgrade to C++17
75 assert(x != nullptr);
76 verbose_accessor() = verbose;
77 }
78 }
79
82 inline void initialize(std::ostream& os) {
83 if (!initialized()) {
84 initialize(true);
85 using namespace detail;
86 verbose_stream_accessor() = &os;
87 }
88 }
90 inline void finalize() {
91 if (initialized()) {
92 using namespace detail;
93 managed_singleton<__initializer>::delete_instance();
94 verbose_accessor() = true;
95 verbose_stream_accessor() = &std::clog;
96 }
97 }
100 inline std::ostream& verbose_stream() {
101 return *detail::verbose_stream_accessor();
102 }
106 inline bool verbose() {
107 if (initialized()) {
108 return detail::verbose_accessor();
109 } else {
110 return false;
111 }
112 }
113}
114
115#endif /* _libint2_src_lib_libint_initialize_h_ */
116
Defaults definitions for various parameters assumed by Libint.
Definition: algebra.cc:24
void initialize(bool verbose=false)
initializes the libint library if not currently initialized, no-op otherwise
Definition: initialize.h:70
std::ostream & verbose_stream()
Accessor for the disgnostics stream.
Definition: initialize.h:100
bool initialized()
checks if the libint has been initialized.
Definition: initialize.h:63
bool verbose()
Accessor for the verbose flag.
Definition: initialize.h:106
void finalize()
finalizes the libint library.
Definition: initialize.h:90
Definition: initialize.h:41