LIBINT  2.1.0-stable
policy.h
1 /*
2  * This file is a part of Libint.
3  * Copyright (C) 2004-2014 Edward F. Valeev
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation, either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program. If not, see http://www.gnu.org/licenses/.
17  *
18  */
19 
20 #ifndef _libint2_src_bin_libint_policy_h_
21 #define _libint2_src_bin_libint_policy_h_
22 
23 #include <vector>
24 #include <smart_ptr.h>
25 #include <traits.h>
26 
27 #include <boost/type_traits/is_same.hpp>
28 
29 using namespace std;
30 
31 namespace 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, vector<subobj_stype>& subobj)
48  {
49  subobj.push_back(obj);
50  }
51  static void default_dealloc_subobj(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, 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(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:23
Definition: stdarray.h:18