LIBINT  2.6.0
policy.h
1 /*
2  * Copyright (C) 2004-2019 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 using namespace std;
31 
32 namespace libint2 {
33 
38  template <class T, bool exists>
39  struct ExistsDefaultSubobjAllocator;
40 
41  template <class T>
42  struct ExistsDefaultSubobjAllocator<T,true>{
43  typedef T obj_type;
44  typedef typename TypeTraits<obj_type>::StorageType obj_stype;
45  typedef typename TypeTraits<obj_type>::StorageType subobj_stype;
46  typedef typename obj_type::iter_type subobj_type;
47 
48  static void default_init_subobj(const obj_stype& obj, vector<subobj_stype>& subobj)
49  {
50  subobj.push_back(obj);
51  }
52  static void default_dealloc_subobj(vector<subobj_stype>& subobj)
53  {
54  }
55  };
56 
57 
61  template < class T>
62  struct StdLibintTDPolicy {
63  typedef T obj_type;
64  typedef typename obj_type::iter_type subobj_type;
66  typedef typename TypeTraits<obj_type>::StorageType obj_stype;
68  typedef typename TypeTraits<subobj_type>::StorageType subobj_stype;
69 
71  static void init_subobj(const obj_stype& obj, vector<subobj_stype>& subobj)
72  {
73  // If types are not the same then this function should not be used -- user must provide a specialization
74  ExistsDefaultSubobjAllocator< T, boost::is_same<obj_type,subobj_type>::value >::default_init_subobj(obj,subobj);
75  }
76  static void dealloc_subobj(vector<subobj_stype>& subobj)
77  {
78  // If types are not the same then this function should not be used -- user must provide a specialization
79  ExistsDefaultSubobjAllocator< T, boost::is_same<obj_type,subobj_type>::value >::default_dealloc_subobj(subobj);
80  }
81  };
82 
83 
87  class StdLibintTIPolicy {
88 
90  static unsigned int max_set_size_to_unroll_;
91 
92  public:
93 
94  StdLibintTIPolicy() {}
95 
96  virtual void set_max_set_size_to_unroll(unsigned int i)
97  {
98  max_set_size_to_unroll_ = i;
99  }
100 
101  virtual unsigned int max_set_size_to_unroll() const
102  {
103  return max_set_size_to_unroll_;
104  }
105 
106  };
107 
108 
113 #if CXX_ALLOWS_DEFPARAMTEMPLATE_AS_TEMPTEMPPARAM
114  template <class T, class TIPol = StdLibintTIPolicy, template <class> class TDPol = StdLibintTDPolicy>
115  class Policy : public TDPol<T>, public TIPol
116  {
117 #else
118 #define TDPol StdLibintTDPolicy
119 #define TIPol StdLibintTIPolicy
120  template <class T>
121  class Policy : public TDPol<T>, public TIPol
122  {
123 #endif
124  public:
126  typedef typename TDPol<T>::obj_stype obj_stype;
128  typedef typename TDPol<T>::subobj_stype subobj_stype;
129 
130  /*
131  typedef typename TDPol<T>::obj_type obj_type;
132  typedef typename obj_type::iter_type subobj_type;
133 
134  static void init_subobj(const SafePtr<obj_type>& obj, const vector< SafePtr<subobj_type> >& subobj)
135  {
136  TDPol<T>::init_subobj(obj,subobj);
137  }
138 
139  static void dealloc_subobj(const vector< SafePtr<subobj_type> >& subobj)
140  {
141  TDPol<T>::dealloc_subobj(subobj);
142  }
143  */
144 
145  private:
147  bool can_unroll_intset(const SafePtr<T>& iset)
148  {
149  return iset->set_size() <= TIPol::max_set_size_to_unroll();
150  }
151  };
152 
153 
154 };
155 
156 
157 #endif
Defaults definitions for various parameters assumed by Libint.
Definition: algebra.cc:24