LIBINT 2.9.0
policy.h
1/*
2 * Copyright (C) 2004-2024 Edward F. Valeev
3 *
4 * This file is part of Libint compiler.
5 *
6 * Libint compiler 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 compiler 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 compiler. If not, see <http://www.gnu.org/licenses/>.
18 *
19 */
20
21#ifndef _libint2_src_bin_libint_policy_h_
22#define _libint2_src_bin_libint_policy_h_
23
24#include <smart_ptr.h>
25#include <traits.h>
26
27#include <boost/type_traits/is_same.hpp>
28#include <vector>
29
30namespace libint2 {
31
37template <class T, bool exists>
38struct ExistsDefaultSubobjAllocator;
39
40template <class T>
41struct ExistsDefaultSubobjAllocator<T, true> {
42 typedef T obj_type;
43 typedef typename TypeTraits<obj_type>::StorageType obj_stype;
44 typedef typename TypeTraits<obj_type>::StorageType subobj_stype;
45 typedef typename obj_type::iter_type subobj_type;
46
47 static void default_init_subobj(const obj_stype& obj,
48 std::vector<subobj_stype>& subobj) {
49 subobj.push_back(obj);
50 }
51 static void default_dealloc_subobj(std::vector<subobj_stype>& subobj) {}
52};
53
57template <class T>
58struct StdLibintTDPolicy {
59 typedef T obj_type;
60 typedef typename obj_type::iter_type subobj_type;
62 typedef typename TypeTraits<obj_type>::StorageType obj_stype;
64 typedef typename TypeTraits<subobj_type>::StorageType subobj_stype;
65
68 static void init_subobj(const obj_stype& obj,
69 std::vector<subobj_stype>& subobj) {
70 // If types are not the same then this function should not be used -- user
71 // must provide a specialization
72 ExistsDefaultSubobjAllocator<T,
73 boost::is_same<obj_type, subobj_type>::value>::
74 default_init_subobj(obj, subobj);
75 }
76 static void dealloc_subobj(std::vector<subobj_stype>& subobj) {
77 // If types are not the same then this function should not be used -- user
78 // must provide a specialization
79 ExistsDefaultSubobjAllocator<T, boost::is_same<obj_type, subobj_type>::
80 value>::default_dealloc_subobj(subobj);
81 }
82};
83
87class StdLibintTIPolicy {
89 static unsigned int max_set_size_to_unroll_;
90
91 public:
92 StdLibintTIPolicy() {}
93
94 virtual void set_max_set_size_to_unroll(unsigned int i) {
95 max_set_size_to_unroll_ = i;
96 }
97
98 virtual unsigned int max_set_size_to_unroll() const {
99 return max_set_size_to_unroll_;
100 }
101};
102
107#if CXX_ALLOWS_DEFPARAMTEMPLATE_AS_TEMPTEMPPARAM
108template <class T, class TIPol = StdLibintTIPolicy,
109 template <class> class TDPol = StdLibintTDPolicy>
110class Policy : public TDPol<T>, public TIPol {
111#else
112#define TDPol StdLibintTDPolicy
113#define TIPol StdLibintTIPolicy
114template <class T>
115class Policy : public TDPol<T>, public TIPol {
116#endif
117 public:
119 typedef typename TDPol<T>::obj_stype obj_stype;
121 typedef typename TDPol<T>::subobj_stype subobj_stype;
122
123 /*
124 typedef typename TDPol<T>::obj_type obj_type;
125 typedef typename obj_type::iter_type subobj_type;
126
127 static void init_subobj(const std::shared_ptr<obj_type>& obj, const vector<
128 std::shared_ptr<subobj_type> >& subobj)
129 {
130 TDPol<T>::init_subobj(obj,subobj);
131 }
132
133 static void dealloc_subobj(const vector< std::shared_ptr<subobj_type> >&
134 subobj)
135 {
136 TDPol<T>::dealloc_subobj(subobj);
137 }
138 */
139
140 private:
142 bool can_unroll_intset(const std::shared_ptr<T>& iset) {
143 return iset->set_size() <= TIPol::max_set_size_to_unroll();
144 }
145};
146
147}; // namespace libint2
148
149#endif
Defaults definitions for various parameters assumed by Libint.
Definition algebra.cc:24