LIBINT 2.7.2
policy.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_policy_h_
22#define _libint2_src_bin_libint_policy_h_
23
24#include <vector>
25#include <smart_ptr.h>
26#include <traits.h>
27
28#include <boost/type_traits/is_same.hpp>
29
30
31namespace libint2 {
32
37 template <class T, bool exists>
38 struct ExistsDefaultSubobjAllocator;
39
40 template <class T>
41 struct 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, std::vector<subobj_stype>& subobj)
48 {
49 subobj.push_back(obj);
50 }
51 static void default_dealloc_subobj(std::vector<subobj_stype>& subobj)
52 {
53 }
54 };
55
56
60 template < class T>
61 struct StdLibintTDPolicy {
62 typedef T obj_type;
63 typedef typename obj_type::iter_type subobj_type;
65 typedef typename TypeTraits<obj_type>::StorageType obj_stype;
67 typedef typename TypeTraits<subobj_type>::StorageType subobj_stype;
68
70 static void init_subobj(const obj_stype& obj, std::vector<subobj_stype>& subobj)
71 {
72 // If types are not the same then this function should not be used -- user must provide a specialization
73 ExistsDefaultSubobjAllocator< T, boost::is_same<obj_type,subobj_type>::value >::default_init_subobj(obj,subobj);
74 }
75 static void dealloc_subobj(std::vector<subobj_stype>& subobj)
76 {
77 // If types are not the same then this function should not be used -- user must provide a specialization
78 ExistsDefaultSubobjAllocator< T, boost::is_same<obj_type,subobj_type>::value >::default_dealloc_subobj(subobj);
79 }
80 };
81
82
86 class StdLibintTIPolicy {
87
89 static unsigned int max_set_size_to_unroll_;
90
91 public:
92
93 StdLibintTIPolicy() {}
94
95 virtual void set_max_set_size_to_unroll(unsigned int i)
96 {
97 max_set_size_to_unroll_ = i;
98 }
99
100 virtual unsigned int max_set_size_to_unroll() const
101 {
102 return max_set_size_to_unroll_;
103 }
104
105 };
106
107
112#if CXX_ALLOWS_DEFPARAMTEMPLATE_AS_TEMPTEMPPARAM
113 template <class T, class TIPol = StdLibintTIPolicy, template <class> class TDPol = StdLibintTDPolicy>
114 class Policy : public TDPol<T>, public TIPol
115 {
116#else
117#define TDPol StdLibintTDPolicy
118#define TIPol StdLibintTIPolicy
119 template <class T>
120 class Policy : public TDPol<T>, public TIPol
121 {
122#endif
123 public:
125 typedef typename TDPol<T>::obj_stype obj_stype;
127 typedef typename TDPol<T>::subobj_stype subobj_stype;
128
129 /*
130 typedef typename TDPol<T>::obj_type obj_type;
131 typedef typename obj_type::iter_type subobj_type;
132
133 static void init_subobj(const SafePtr<obj_type>& obj, const vector< SafePtr<subobj_type> >& subobj)
134 {
135 TDPol<T>::init_subobj(obj,subobj);
136 }
137
138 static void dealloc_subobj(const vector< SafePtr<subobj_type> >& subobj)
139 {
140 TDPol<T>::dealloc_subobj(subobj);
141 }
142 */
143
144 private:
146 bool can_unroll_intset(const SafePtr<T>& iset)
147 {
148 return iset->set_size() <= TIPol::max_set_size_to_unroll();
149 }
150 };
151
152
153};
154
155
156#endif
Defaults definitions for various parameters assumed by Libint.
Definition: algebra.cc:24
StorageTraits< T >::StorageType StorageType
By default, use SafePtr to manage these objects.
Definition: traits.h:84