LIBINT  2.6.0
default_params.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_defaultparams_h_
22 #define _libint2_src_bin_libint_defaultparams_h_
23 
24 #include <ostream>
25 #include <string>
26 #include <map>
27 #include <vector>
28 #include <climits>
29 #include <smart_ptr.h>
30 
35 namespace libint2 {
36 
39  std::string default_task_name_;
40 
41  public:
42 
46 
48  unsigned int max_am(std::string t = "", unsigned int c = 0) const;
50  unsigned int max_am_opt(std::string t = "") const;
52  unsigned int num_bf(std::string t = "") const;
54  unsigned int max_vector_length() const {
55  return max_vector_length_;
56  }
58  bool vectorize_by_line() const {
59  return vectorize_by_line_;
60  }
62  unsigned int unroll_threshold() const {
63  return unroll_threshold_;
64  }
66  unsigned int align_size() const {
67  return align_size_;
68  }
70  const std::string& source_directory() const {
71  return source_directory_;
72  }
74  const std::string& api_prefix() const {
75  return api_prefix_;
76  }
78  bool single_evaltype() const {
79  return single_evaltype_;
80  }
82  bool use_C_linking() const {
83  return use_C_linking_;
84  }
86  bool count_flops() const {
87  return count_flops_;
88  }
90  bool profile() const {
91  return profile_;
92  }
94  bool accumulate_targets() const {
95  return accumulate_targets_;
96  }
98  const std::string& realtype() const {
99  return realtype_;
100  }
102  bool contracted_targets() const {
103  return contracted_targets_;
104  }
106  const std::string& default_task_name() const {
107  return default_task_name_;
108  }
109 
111  void max_am(const std::string& t, unsigned int a, unsigned int c=0);
113  void max_am_opt(const std::string& t, unsigned int a);
115  void num_bf(const std::string& t, unsigned int a);
117  void max_vector_length(unsigned int a) {
118  max_vector_length_ = a;
119  }
121  void vectorize_by_line(bool flag) {
122  vectorize_by_line_ = flag;
123  }
125  void align_size(unsigned int a) {
126  align_size_ = a;
127  }
129  void unroll_threshold(unsigned int a) {
130  unroll_threshold_ = a;
131  }
133  void source_directory(const std::string& a) {
134  source_directory_ = a;
135  }
137  void api_prefix(const std::string& a) {
138  api_prefix_ = a;
139  }
141  void single_evaltype(bool se) {
142  single_evaltype_ = se;
143  }
145  void use_C_linking(bool a) {
146  use_C_linking_ = a;
147  }
149  void count_flops(bool a) {
150  count_flops_ = a;
151  }
153  void profile(bool a) {
154  profile_ = a;
155  }
157  void accumulate_targets(bool a) {
158  accumulate_targets_ = a;
159  }
161  void realtype(const std::string& realtype) {
162  realtype_ = realtype;
163  }
165  void contracted_targets(bool c) {
166  contracted_targets_ = c;
167  }
169  void default_task_name(const std::string& s) {
170  default_task_name_ = s;
171  }
172 
174  void print(std::ostream& os) const;
175 
176  private:
177  struct Defaults {
179  static const unsigned int max_am = 1;
181  static const unsigned int max_am_opt = 1;
183  static const unsigned int num_bf = 4;
185  static const unsigned int max_vector_length = 1;
187  static const bool vectorize_by_line = false;
189  static const unsigned int align_size = 0;
191  static const unsigned int unroll_threshold = 0;
193  static const std::string source_directory;
195  static const std::string api_prefix;
197  static const bool single_evaltype = true;
199  static const bool use_C_linking = true;
201  static const bool count_flops = false;
203  static const bool profile = false;
205  static const bool accumulate_targets = false;
207  static const std::string realtype;
209  static const bool contracted_targets = false;
211  static const std::string task_name;
212  };
213 
214  struct TaskParameters {
216  std::vector<unsigned int> max_am;
218  unsigned int max_am_opt;
220  unsigned int num_bf;
221 
222  TaskParameters() : max_am(1, 0u), max_am_opt(0u), num_bf(0u) {}
223  };
225  std::map<std::string,TaskParameters> task_params_;
227  void task_exists(const std::string& t) const;
229  void add_task(const std::string& t);
230 
232  unsigned int max_vector_length_;
234  bool vectorize_by_line_;
238  unsigned int align_size_;
240  unsigned int unroll_threshold_;
242  std::string source_directory_;
244  std::string api_prefix_;
246  bool single_evaltype_;
248  bool use_C_linking_;
250  bool count_flops_;
252  bool profile_;
254  bool accumulate_targets_;
256  std::string realtype_;
258  bool contracted_targets_;
259  };
260 
266  public:
267  TaskParameters();
268  ~TaskParameters() {}
269 
271  unsigned int max_ntarget() const {
272  return max_ntarget_;
273  }
275  unsigned int max_am() const {
276  return max_stack_size_.size() - 1;
277  }
279  unsigned int max_stack_size(unsigned int am) const {
280  return max_stack_size_.at(am);
281  }
286  unsigned int max_vector_stack_size(unsigned int am) const {
287  if (am + 1 > max_vector_stack_size_.size())
288  return 0;
289  else
290  return max_vector_stack_size_[am];
291  }
295  unsigned int max_hrr_hsrank(unsigned int am) const {
296  if (am + 1 > max_hrr_hsrank_.size())
297  return 0;
298  else
299  return max_hrr_hsrank_[am];
300  }
304  unsigned int max_hrr_lsrank(unsigned int am) const {
305  if (am + 1 > max_hrr_lsrank_.size())
306  return 0;
307  else
308  return max_hrr_lsrank_[am];
309  }
310 
312  void max_ntarget(unsigned int ntarget) {
313  if (max_ntarget_ < ntarget)
314  max_ntarget_ = ntarget;
315  }
316 
318  void max_stack_size(unsigned int am, unsigned int size) {
319  extend_max_size(max_stack_size_, am, size);
320  }
321 
323  void max_vector_stack_size(unsigned int am, unsigned int size) {
324  extend_max_size(max_vector_stack_size_, am, size);
325  }
326 
328  void max_hrr_hsrank(unsigned int am, unsigned int rank) {
329  extend_max_size(max_hrr_hsrank_, am, rank);
330  }
331 
333  void max_hrr_lsrank(unsigned int am, unsigned int rank) {
334  extend_max_size(max_hrr_lsrank_, am, rank);
335  }
336 
337  private:
338  unsigned int max_ntarget_;
339  std::vector<unsigned int> max_stack_size_; //< keeps track of stack size needed to compute integrals up to a given quantum number
340  std::vector<unsigned int> max_vector_stack_size_;
341  std::vector<unsigned int> max_hrr_hsrank_;
342  std::vector<unsigned int> max_hrr_lsrank_;
343 
344  static void extend_max_size(std::vector<unsigned int>& max_size, unsigned int am, unsigned int size) {
345  const int max_am = (int)max_size.size() - 1u;
346  if (max_am < (int)am) {
347  max_size.resize(am + 1);
348  for(int l = std::max(max_am+1,1); l<=(int)am; ++l)
349  max_size[l] = max_size[l-1];
350  }
351  if (max_size[am] < size)
352  max_size[am] = size;
353  }
354  };
355 
361  static const unsigned int num_am_letters = 10;
363  static const char am_letters[num_am_letters+1];
364  };
365 
367  std::string label_to_funcname(const std::string& label);
368 
371  bool condense_expr(unsigned int unroll_threshold, bool vectorize);
372 };
373 
374 #endif
375 
void max_hrr_lsrank(unsigned int am, unsigned int rank)
if max_hrr_lsrank_ < rank then set max_hrr_lsrank_=rank
Definition: default_params.h:333
bool profile() const
whether profiling instrumentation is enabled
Definition: default_params.h:90
unsigned int max_hrr_hsrank(unsigned int am) const
returns max rank of high-significance functions in a HRR call.
Definition: default_params.h:295
void source_directory(const std::string &a)
set generated source directory
Definition: default_params.h:133
void max_stack_size(unsigned int am, unsigned int size)
if max_stack_size_ < size then set max_stack_size_=size
Definition: default_params.h:318
void max_vector_stack_size(unsigned int am, unsigned int size)
if max_vector_stack_size_ < size then set max_vector_stack_size_=size
Definition: default_params.h:323
void vectorize_by_line(bool flag)
set vectorize_by_line flag
Definition: default_params.h:121
bool vectorize_by_line() const
returns whether to vectorize line-by-line
Definition: default_params.h:58
Static parameters.
Definition: default_params.h:357
std::string label_to_funcname(const std::string &label)
Converts a label, e.g. name of the target node, to the name of the function to compute it.
Definition: default_params.cc:216
const std::string & source_directory() const
returns directory path for the generated source
Definition: default_params.h:70
unsigned int max_am(std::string t="", unsigned int c=0) const
returns max AM for task t and center c
Definition: default_params.cc:100
void unroll_threshold(unsigned int a)
set unroll threshold
Definition: default_params.h:129
bool condense_expr(unsigned int unroll_threshold, bool vectorize)
need to condense expressions? Makes sense if vectorizing the code or the compiler somehow prefers lon...
Definition: default_params.cc:229
void single_evaltype(bool se)
generate a single evaluator type (i.e. not specific to each task)?
Definition: default_params.h:141
void contracted_targets(bool c)
support contracted targets?
Definition: default_params.h:165
Defaults definitions for various parameters assumed by Libint.
Definition: algebra.cc:24
void max_hrr_hsrank(unsigned int am, unsigned int rank)
if max_hrr_hsrank_ < rank then set max_hrr_hsrank_=rank
Definition: default_params.h:328
const std::string & realtype() const
name of the floating-point type
Definition: default_params.h:98
void realtype(const std::string &realtype)
which floating-point type to use
Definition: default_params.h:161
This class maintains various parameters for each task type which can only be determined during the so...
Definition: default_params.h:265
unsigned int max_ntarget() const
returns the max number of targets
Definition: default_params.h:271
unsigned int num_bf(std::string t="") const
returns number of basis functions in integrals for task t
Definition: default_params.cc:128
static const char am_letters[num_am_letters+1]
am -> char conversion
Definition: default_params.h:363
static const unsigned int num_am_letters
basis functions with angular momenta 0 .
Definition: default_params.h:361
void accumulate_targets(bool a)
accumulate targets?
Definition: default_params.h:157
const std::string & api_prefix() const
the API prefix
Definition: default_params.h:74
bool use_C_linking() const
returns whether to use C-style linking
Definition: default_params.h:82
unsigned int max_stack_size(unsigned int am) const
returns max stack size needed for quantum numbers up to am
Definition: default_params.h:279
const std::string & default_task_name() const
default task name
Definition: default_params.h:106
unsigned int max_am_opt(std::string t="") const
returns max AM for which to produce optimal code for task t
Definition: default_params.cc:114
unsigned int align_size() const
returns alignment size (in units of sizeof(LIBINT_FLOAT))
Definition: default_params.h:66
void print(std::ostream &os) const
print params out
Definition: default_params.cc:56
void max_vector_length(unsigned int a)
set max vector length
Definition: default_params.h:117
unsigned int max_vector_stack_size(unsigned int am) const
returns max vector stack size.
Definition: default_params.h:286
void default_task_name(const std::string &s)
default task name
Definition: default_params.h:169
CompilationParameters()
Use default parameters.
Definition: default_params.cc:34
void use_C_linking(bool a)
set whether to use C style linking
Definition: default_params.h:145
void profile(bool a)
set to instrument profiling
Definition: default_params.h:153
bool contracted_targets() const
whether contracted targets are supported
Definition: default_params.h:102
bool single_evaltype() const
generate single evaluator type (i.e. not specific to each task)?
Definition: default_params.h:78
bool count_flops() const
whether FLOP counting is enabled
Definition: default_params.h:86
unsigned int max_vector_length() const
returns max vector length
Definition: default_params.h:54
void align_size(unsigned int a)
set alignment size (in units of sizeof(LIBINT_FLOAT))
Definition: default_params.h:125
unsigned int unroll_threshold() const
returns unroll threshold
Definition: default_params.h:62
bool accumulate_targets() const
whether target integrals are accumulated
Definition: default_params.h:94
void api_prefix(const std::string &a)
API prefix.
Definition: default_params.h:137
unsigned int max_hrr_lsrank(unsigned int am) const
returns max rank of low-significance functions in a HRR call.
Definition: default_params.h:304
void count_flops(bool a)
set whether to count FLOPs
Definition: default_params.h:149
These are the parameters received by the compiler.
Definition: default_params.h:38
unsigned int max_am() const
returns the max quantum number of targets
Definition: default_params.h:275
void max_ntarget(unsigned int ntarget)
if max_ntarget_ < ntarget then set max_ntarget_=ntarget
Definition: default_params.h:312