Psi4
psimrcc/blas.h
Go to the documentation of this file.
1 /*
2  * @BEGIN LICENSE
3  *
4  * Psi4: an open-source quantum chemistry software package
5  *
6  * Copyright (c) 2007-2019 The Psi4 Developers.
7  *
8  * The copyrights for code used from other parties are included in
9  * the corresponding files.
10  *
11  * This file is part of Psi4.
12  *
13  * Psi4 is free software; you can redistribute it and/or modify
14  * it under the terms of the GNU Lesser General Public License as published by
15  * the Free Software Foundation, version 3.
16  *
17  * Psi4 is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20  * GNU Lesser General Public License for more details.
21  *
22  * You should have received a copy of the GNU Lesser General Public License along
23  * with Psi4; if not, write to the Free Software Foundation, Inc.,
24  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
25  *
26  * @END LICENSE
27  */
28 
29 #ifndef _psi_src_bin_psimrcc_ccblas_h
30 #define _psi_src_bin_psimrcc_ccblas_h
31 
37 #include <deque>
38 #include <string>
39 #include <vector>
40 #include <map>
41 #include <utility>
42 
45 #include "matrixtmp.h"
46 #include "operation.h"
47 
48 #include "index_types.h"
49 #include "matrix_types.h"
50 #include "types.h"
51 
52 namespace psi {
53 namespace psimrcc {
54 
55 class CCIndex;
56 class CCMatrix;
57 
59 
63 class CCBLAS {
64  public:
65  typedef std::vector<std::string> strvec;
66  typedef std::vector<int> intvec;
67  typedef std::vector<std::pair<int, int> > intpairvec;
68  typedef std::deque<CCOperation> OpDeque;
69 
70  CCBLAS(Options& options);
71  ~CCBLAS();
72 
74  // Add routines
75  void add_Matrix(const char* cstr);
76  void add_Matrix(std::string str);
77  void add_index(const char* cstr);
78  // Solve and sort
79  void solve(const char* cstr);
80  void solve(std::string str);
81  void solve_zero_two_diagonal(const char* cstr);
82  void zero_right_four_diagonal(const char* cstr);
83  void zero_left_four_diagonal(const char* cstr);
84  void zero_non_doubly_occupied(const char* cstr);
85  void zero_non_external(const char* cstr);
86  void zero(const char* cstr);
87  void scale(const char* cstr, int reference, double value);
88  void scale(std::string& str, int reference, double value);
89  void reduce_spaces(const char* out, const char* in);
90  void expand_spaces(const char* out, const char* in);
91  void append(const char* cstr);
92  void append(std::string str);
93  void append_zero_two_diagonal(const char* cstr);
94  void compute();
96  void show_storage();
97  // DIIS
98  void diis_add(std::string amps, std::string delta_amps);
99  void diis_save_t_amps(int cycle);
100  void diis(int cycle, double delta, DiisType diis_type);
101  // Printing
102  void print(const char* cstr);
103  void print_ref(std::string& str);
104  void print_memory();
105  // Safe get and set
106  CCIndex* get_index(const char* cstr);
107  CCIndex* get_index(std::string& str);
108  CCMatTmp get_MatTmp(std::string str, int reference, DiskOpt disk_option);
109  CCMatTmp get_MatTmp(std::string str, DiskOpt disk_option);
110  CCMatTmp get_MatTmp(CCMatrix* Matrix, DiskOpt disk_option);
111  CCMatIrTmp get_MatIrTmp(std::string str, int reference, int irrep, DiskOpt disk_option);
112  CCMatIrTmp get_MatIrTmp(std::string str, int irrep, DiskOpt disk_option);
113  CCMatIrTmp get_MatIrTmp(CCMatrix* Matrix, int irrep, DiskOpt disk_option);
114 
115  double get_scalar(std::string str);
116  double get_scalar(const char* cstr, int reference);
117  double get_scalar(std::string& str, int reference);
118  void set_scalar(const char* cstr, int reference, double value);
119  void set_scalar(std::string& str, int reference, double value);
120 
121  // DIIS
122  std::vector<std::pair<std::string, std::string> > diis_matrices;
123 
124  // These have to be improved
126 
127  private:
129  size_t work_size;
130  size_t buffer_size;
140 
141  private:
142  IndexMap& get_IndexMap() { return (indices); }
143  CCMatrix* get_Matrix(std::string& str);
144  CCMatrix* get_Matrix(const char* cstr);
145  CCMatrix* get_Matrix(const char* cstr, int reference);
146  CCMatrix* get_Matrix(std::string& str, std::string& expression); // Prints a clear error message
147  double* get_work(int n) { return (work[n]); }
148  // double*** get_sortmap(CCIndex* T_left,CCIndex* T_right,int thread);
149 
151  void load(CCMatrix* Matrix);
152  void load_irrep(CCMatrix* Matrix, int h);
154  // Class private functions
156  void add_Matrix_ref(std::string& str);
157  void add_indices();
158  void add_matrix_ref(std::string& str);
159  void solve_ref(std::string& str);
160  int parse(std::string& str);
161  void process_operations();
162  void process_reduce_spaces(CCMatrix* out_Matrix, CCMatrix* in_Matrix);
163  void process_expand_spaces(CCMatrix* out_Matrix, CCMatrix* in_Matrix);
164  bool get_factor(const std::string& str, double& factor);
165  // General routines
166 
167  void make_space(size_t memory_required);
168  // Low level memory routines
169  void init();
170  void cleanup();
171  void allocate_work();
172  void allocate_buffer();
173  void free_sortmap();
174  void free_work();
175  void free_indices();
176  void free_matrices();
177  void free_buffer();
178 };
179 
180 extern CCBLAS* blas;
181 
182 } // namespace psimrcc
183 } // namespace psi
184 
185 #endif // _psi_src_bin_psimrcc_ccblas_h
size_t work_size
Definition: psimrcc/blas.h:129
double * get_work(int n)
Definition: psimrcc/blas.h:147
void cleanup()
Definition: psimrcc/blas.cc:58
MatCnt matrices_in_deque_source
Definition: psimrcc/blas.h:138
IndexMap & get_IndexMap()
Definition: psimrcc/blas.h:142
PsiReturnType psimrcc(SharedWavefunction, Options &)
Definition: psimrcc/main.cc:86
CCBLAS(Options &options)
Definition: psimrcc/blas.cc:48
void set_scalar(const char *cstr, int reference, double value)
Definition: blas_interface.cc:166
Options & options_
Definition: psimrcc/blas.h:73
std::vector< std::pair< std::string, std::string > > diis_matrices
Definition: psimrcc/blas.h:122
std::vector< std::pair< int, int > > intpairvec
Definition: psimrcc/blas.h:67
std::map< std::string, psi::psimrcc::CCMatrix * > MatrixMap
Definition: sort.h:34
Definition: psimrcc/matrix.h:49
void load_irrep(CCMatrix *Matrix, int h)
Definition: blas_interface.cc:226
void diis_save_t_amps(int cycle)
Definition: blas_diis.cc:66
std::vector< std::string > strvec
Definition: psimrcc/blas.h:65
Definition: matrixtmp.h:47
MatrixMap matrices
Definition: psimrcc/blas.h:131
void free_buffer()
Definition: psimrcc/blas.cc:134
void allocate_buffer()
Definition: psimrcc/blas.cc:96
void print_memory()
Definition: psimrcc/blas.cc:238
void reference()
Definition: reference.cc:51
void diis_add(std::string amps, std::string delta_amps)
Definition: blas_diis.cc:58
int compute_storage_strategy()
Definition: psimrcc/blas.cc:276
void free_matrices()
Definition: psimrcc/blas.cc:143
double get_scalar(std::string str)
Definition: blas_interface.cc:201
MatCnt matrices_in_deque_target
Definition: psimrcc/blas.h:137
void free_indices()
Definition: psimrcc/blas.cc:149
void solve(const char *cstr)
Definition: blas_solve.cc:45
Definition: index.h:67
void process_reduce_spaces(CCMatrix *out_Matrix, CCMatrix *in_Matrix)
Definition: blas_algorithms.cc:119
void add_indices()
Definition: psimrcc/blas.cc:155
Definition: psimrcc/blas.h:58
void diis(int cycle, double delta, DiisType diis_type)
Definition: blas_diis.cc:86
bool get_factor(const std::string &str, double &factor)
Definition: blas_parser.cc:116
void zero_non_doubly_occupied(const char *cstr)
Definition: blas_algorithms.cc:66
CCIndex * get_index(const char *cstr)
Definition: blas_interface.cc:81
Definition: psimrcc/blas.h:58
MatrixMap & get_MatrixMap()
Definition: psimrcc/blas.h:125
std::vector< double * > ArrayVec
Definition: types.h:32
bool full_in_core
Definition: psimrcc/blas.h:128
void zero_right_four_diagonal(const char *cstr)
Definition: blas_algorithms.cc:55
void load(CCMatrix *Matrix)
Definition: blas_interface.cc:212
OpDeque operations
Definition: psimrcc/blas.h:133
void reduce_spaces(const char *out, const char *in)
Definition: blas_algorithms.cc:105
size_t buffer_size
Definition: psimrcc/blas.h:130
void print_ref(std::string &str)
Definition: psimrcc/blas.cc:236
std::vector< int > intvec
Definition: psimrcc/blas.h:66
void print(const char *cstr)
Definition: psimrcc/blas.cc:230
CCMatrix * get_Matrix(std::string &str)
Definition: blas_interface.cc:147
void init()
Definition: psimrcc/blas.cc:52
void solve_ref(std::string &str)
void scale(const char *cstr, int reference, double value)
Definition: blas_algorithms.cc:88
~CCBLAS()
Definition: psimrcc/blas.cc:50
Definition: psimrcc/blas.h:63
Makes using matrices just a little easier.
Definition: libmints/matrix.h:112
void append(const char *cstr)
Definition: blas_solve.cc:63
std::deque< CCOperation > OpDeque
Definition: psimrcc/blas.h:68
Definition: liboptions.h:352
std::map< psi::psimrcc::CCMatrix *, int > MatCnt
Definition: sort.h:33
void process_expand_spaces(CCMatrix *out_Matrix, CCMatrix *in_Matrix)
Definition: blas_algorithms.cc:189
void solve_zero_two_diagonal(const char *cstr)
Definition: blas_solve.cc:239
SortMap sortmap
Definition: psimrcc/blas.h:139
MatCnt matrices_in_deque
Definition: psimrcc/blas.h:136
Definition: matrixtmp.h:62
void show_storage()
Definition: psimrcc/blas.cc:412
DiskOpt
Definition: matrixtmp.h:42
int delta(const int i, const int j)
Definition: bend.cc:175
ArrayVec buffer
Definition: psimrcc/blas.h:135
void allocate_work()
Definition: psimrcc/blas.cc:66
void add_index(const char *cstr)
Definition: blas_interface.cc:47
CCMatIrTmp get_MatIrTmp(std::string str, int reference, int irrep, DiskOpt disk_option)
Definition: blas_interface.cc:120
void allocate_matrices_in_core()
void append_zero_two_diagonal(const char *cstr)
Definition: blas_solve.cc:224
void add_Matrix(const char *cstr)
Definition: blas_interface.cc:56
void add_Matrix_ref(std::string &str)
Definition: blas_interface.cc:67
void add_matrix_ref(std::string &str)
void zero(const char *cstr)
Definition: blas_algorithms.cc:44
int parse(std::string &str)
Definition: blas_parser.cc:48
std::map< std::string, double *** > SortMap
Definition: types.h:33
CCBLAS * blas
Definition: psimrcc/main.cc:78
ArrayVec work
Definition: psimrcc/blas.h:134
indices
Definition: libdpd/dpd.h:262
void free_sortmap()
Definition: psimrcc/blas.cc:118
void zero_non_external(const char *cstr)
Definition: blas_algorithms.cc:77
IndexMap indices
Definition: psimrcc/blas.h:132
void free_work()
Definition: psimrcc/blas.cc:125
void make_space(size_t memory_required)
Definition: blas_interface.cc:241
void expand_spaces(const char *out, const char *in)
Definition: blas_algorithms.cc:175
void zero_left_four_diagonal(const char *cstr)
CCMatTmp get_MatTmp(std::string str, int reference, DiskOpt disk_option)
Definition: blas_interface.cc:104
std::map< std::string, psi::psimrcc::CCIndex * > IndexMap
Definition: index_types.h:32
void compute()
Definition: blas_solve.cc:101
DiisType
Definition: psimrcc/blas.h:58