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