LIBINT 2.7.2
iface.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 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 General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with Libint. If not, see <http://www.gnu.org/licenses/>.
18 *
19 */
20
21#ifndef _libint2_src_bin_libint_iface_h_
22#define _libint2_src_bin_libint_iface_h_
23
24#include <ostream>
25#include <sstream>
26#include <smart_ptr.h>
27#include <default_params.h>
28#include <context.h>
29#include <task.h>
30
31namespace libint2 {
42 public:
43 typedef std::vector<std::string> Tasks;
44 Libint2Iface(const SafePtr<CompilationParameters>& cparams,
45 const SafePtr<CodeContext>& ctext);
47
49 void to_types(const std::string& s) {
50 th_ << s << std::endl;
51 }
53 void to_params(const std::string& s) {
54 ph_ << s << std::endl;
55 }
57 void to_iface(const std::string& s) {
58 ih_ << s << std::endl;
59 }
61 void to_int_iface(const std::string& s) {
62 ii_ << s << std::endl;
63 }
65 void to_static_init(const std::string& s) {
66 si_ << s << std::endl;
67 }
69 void to_static_cleanup(const std::string& s) {
70 sc_ << s << std::endl;
71 }
73 //void to_libint_init(const std::string& s) {
74 // li_ << s << endl;
75 //}
76
77 std::string macro(const std::string& label) {
78 std::string result("LIBINT2_"); result += label;
79 return result;
80 }
81
82 std::string macro(const std::string& task_label, const std::string& label) {
83 std::string result("LIBINT2_"); result += label; if (task_label != "") { result += "_"; result += task_label; }
84 return result;
85 }
86
87 template <typename T> std::string macro_define(const std::string& label, const T& value) {
88 oss_ .str(null_str_);
89 oss_ << "#ifndef " << macro(label) << std::endl;
90 oss_ << "# define " << macro(label) << " " << value << std::endl;
91 oss_ << "#endif" << std::endl;
92 return oss_.str();
93 }
94
95 template <typename T> std::string macro_define(const std::string& task_label, const std::string& label, const T& value) {
96 oss_ .str(null_str_);
97 oss_ << "#define " << macro(task_label,label) << " " << value << std::endl;
98 return oss_.str();
99 }
100
101 template <typename T> std::string var_declare_v(const std::string& label) {
102 return ctext_->declare_v(ctext_->type_name<T>(),ctext_->label_to_name(label),macro("MAX_VECLEN"));
103 }
104
105 private:
106 std::string null_str_;
107 std::ostringstream oss_;
108 SafePtr<CompilationParameters> cparams_;
109 SafePtr<CodeContext> ctext_;
110
111 // computation-specific functions are libint2_init_xxx, libint2_cleanup_xxx, etc. -- these are their declarations,
112 // e.g. "libint2_init_xxx(Libint_t* libint, int max_am, LIBINT2_REALTYPE* buf)"
113 std::vector<std::string> li_decls_; // _init_
114 std::vector<std::string> lm_decls_; // _need_memory_
115 std::vector<std::string> lc_decls_; // _cleanup_
116
117 std::string lf_decl_; // _init_flopcounter
118
119 typedef std::basic_ofstream<char> fstream;
120
121 fstream th_;
122 fstream ph_;
123 fstream ih_;
124 fstream ii_;
125 fstream si_;
126 fstream sc_;
127 fstream li_;
128
129 void generate_inteval_type(std::ostream& os);
130
131 };
132};
133
134#endif
135
Libint2Iface is used to generate Libint2 interfaces.
Definition: iface.h:41
std::string macro(const std::string &label)
Writes string s to the Libint_t init code.
Definition: iface.h:77
void to_int_iface(const std::string &s)
Writes string s to the internal iface header.
Definition: iface.h:61
void to_types(const std::string &s)
Writes string s to the types header.
Definition: iface.h:49
void to_iface(const std::string &s)
Writes string s to the iface header.
Definition: iface.h:57
void to_static_cleanup(const std::string &s)
Writes string s to the static cleanup code.
Definition: iface.h:69
void to_params(const std::string &s)
Writes string s to the params header.
Definition: iface.h:53
void to_static_init(const std::string &s)
Writes string s to the static init code.
Definition: iface.h:65
Defaults definitions for various parameters assumed by Libint.
Definition: algebra.cc:24