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 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{ namespace psimrcc{
53 
54 class CCIndex;
55 class CCMatrix;
56 
58 
62 class CCBLAS{
63 public:
64  typedef std::vector<std::string> strvec;
65  typedef std::vector<int> intvec;
66  typedef std::vector<std::pair<int,int> > intpairvec;
67  typedef std::deque<CCOperation> OpDeque;
68 
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 private:
128  size_t work_size;
129  size_t buffer_size;
139 private:
140 
142  CCMatrix* get_Matrix(std::string& str);
143  CCMatrix* get_Matrix(const char* cstr);
144  CCMatrix* get_Matrix(const char* cstr, int reference);
145  CCMatrix* get_Matrix(std::string& str,std::string& expression); // Prints a clear error message
146  double* get_work(int n) {return(work[n]);}
147 // double*** get_sortmap(CCIndex* T_left,CCIndex* T_right,int thread);
148 
150  void load(CCMatrix* Matrix);
151  void load_irrep(CCMatrix* Matrix,int h);
153  // Class private functions
155  void add_Matrix_ref(std::string& str);
156  void add_indices();
157  void add_matrix_ref(std::string& str);
158  void solve_ref(std::string& str);
159  int parse(std::string& str);
160  void process_operations();
161  void process_reduce_spaces(CCMatrix* out_Matrix,CCMatrix* in_Matrix);
162  void process_expand_spaces(CCMatrix* out_Matrix,CCMatrix* in_Matrix);
163  bool get_factor(const std::string& str,double& factor);
164  // General routines
165 
166  void make_space(size_t memory_required);
167  // Low level memory routines
168  void init();
169  void cleanup();
170  void allocate_work();
171  void allocate_buffer();
172  void free_sortmap();
173  void free_work();
174  void free_indices();
175  void free_matrices();
176  void free_buffer();
177 };
178 
179 extern CCBLAS *blas;
180 
181 }} /* End Namespaces */
182 
183 #endif // _psi_src_bin_psimrcc_ccblas_h
size_t work_size
Definition: psimrcc/blas.h:128
double * get_work(int n)
Definition: psimrcc/blas.h:146
void cleanup()
Definition: psimrcc/blas.cc:71
MatCnt matrices_in_deque_source
Definition: psimrcc/blas.h:137
IndexMap & get_IndexMap()
Definition: psimrcc/blas.h:141
PsiReturnType psimrcc(SharedWavefunction, Options &)
Definition: psimrcc/main.cc:87
CCBLAS(Options &options)
Definition: psimrcc/blas.cc:49
void set_scalar(const char *cstr, int reference, double value)
Definition: blas_interface.cc:185
Options & options_
Definition: psimrcc/blas.h:73
Definition: psimrcc/matrix.h:48
void load_irrep(CCMatrix *Matrix, int h)
Definition: blas_interface.cc:256
void diis_save_t_amps(int cycle)
Definition: blas_diis.cc:68
std::vector< std::string > strvec
Definition: psimrcc/blas.h:64
Definition: matrixtmp.h:47
MatrixMap matrices
Definition: psimrcc/blas.h:130
void free_buffer()
Definition: psimrcc/blas.cc:155
void allocate_buffer()
Definition: psimrcc/blas.cc:112
void print_memory()
Definition: psimrcc/blas.cc:268
void diis_add(std::string amps, std::string delta_amps)
Definition: blas_diis.cc:59
std::map< psi::psimrcc::CCMatrix *, int > MatCnt
Definition: sort.h:33
std::vector< std::pair< int, int > > intpairvec
Definition: psimrcc/blas.h:66
int compute_storage_strategy()
Definition: psimrcc/blas.cc:307
void free_matrices()
Definition: psimrcc/blas.cc:165
std::map< std::string, psi::psimrcc::CCIndex * > IndexMap
Definition: index_types.h:32
double get_scalar(std::string str)
Definition: blas_interface.cc:224
MatCnt matrices_in_deque_target
Definition: psimrcc/blas.h:136
void free_indices()
Definition: psimrcc/blas.cc:172
void solve(const char *cstr)
Definition: blas_solve.cc:44
Definition: index.h:67
void process_reduce_spaces(CCMatrix *out_Matrix, CCMatrix *in_Matrix)
Definition: blas_algorithms.cc:136
void add_indices()
Definition: psimrcc/blas.cc:179
Definition: psimrcc/blas.h:57
void diis(int cycle, double delta, DiisType diis_type)
Definition: blas_diis.cc:87
bool get_factor(const std::string &str, double &factor)
Definition: blas_parser.cc:120
void zero_non_doubly_occupied(const char *cstr)
Definition: blas_algorithms.cc:73
void reference(void)
Definition: reference.cc:50
CCIndex * get_index(const char *cstr)
Definition: blas_interface.cc:88
Definition: psimrcc/blas.h:57
MatrixMap & get_MatrixMap()
Definition: psimrcc/blas.h:125
std::vector< double * > ArrayVec
Definition: types.h:32
bool full_in_core
Definition: psimrcc/blas.h:127
void zero_right_four_diagonal(const char *cstr)
Definition: blas_algorithms.cc:59
void load(CCMatrix *Matrix)
Definition: blas_interface.cc:236
OpDeque operations
Definition: psimrcc/blas.h:132
void reduce_spaces(const char *out, const char *in)
Definition: blas_algorithms.cc:120
size_t buffer_size
Definition: psimrcc/blas.h:129
void print_ref(std::string &str)
Definition: psimrcc/blas.cc:263
std::vector< int > intvec
Definition: psimrcc/blas.h:65
void print(const char *cstr)
Definition: psimrcc/blas.cc:255
CCMatrix * get_Matrix(std::string &str)
Definition: blas_interface.cc:164
std::map< std::string, psi::psimrcc::CCMatrix * > MatrixMap
Definition: sort.h:34
void init()
Definition: psimrcc/blas.cc:64
void solve_ref(std::string &str)
void scale(const char *cstr, int reference, double value)
Definition: blas_algorithms.cc:101
~CCBLAS()
Definition: psimrcc/blas.cc:59
Definition: psimrcc/blas.h:62
Makes using matrices just a little easier.
Definition: libmints/matrix.h:66
void append(const char *cstr)
Definition: blas_solve.cc:64
std::deque< CCOperation > OpDeque
Definition: psimrcc/blas.h:67
Definition: liboptions.h:355
void process_expand_spaces(CCMatrix *out_Matrix, CCMatrix *in_Matrix)
Definition: blas_algorithms.cc:208
void solve_zero_two_diagonal(const char *cstr)
Definition: blas_solve.cc:247
std::map< std::string, double *** > SortMap
Definition: types.h:33
SortMap sortmap
Definition: psimrcc/blas.h:138
MatCnt matrices_in_deque
Definition: psimrcc/blas.h:135
Definition: matrixtmp.h:61
void show_storage()
Definition: psimrcc/blas.cc:442
std::vector< std::pair< std::string, std::string > > diis_matrices
Definition: psimrcc/blas.h:122
DiskOpt
Definition: matrixtmp.h:42
int delta(const int i, const int j)
Definition: bend.cc:175
ArrayVec buffer
Definition: psimrcc/blas.h:134
void allocate_work()
Definition: psimrcc/blas.cc:80
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:132
void allocate_matrices_in_core()
void append_zero_two_diagonal(const char *cstr)
Definition: blas_solve.cc:231
void add_Matrix(const char *cstr)
Definition: blas_interface.cc:57
void add_Matrix_ref(std::string &str)
Definition: blas_interface.cc:72
void add_matrix_ref(std::string &str)
void zero(const char *cstr)
Definition: blas_algorithms.cc:45
int parse(std::string &str)
Definition: blas_parser.cc:48
CCBLAS * blas
Definition: psimrcc/main.cc:78
ArrayVec work
Definition: psimrcc/blas.h:133
indices
Definition: libdpd/dpd.h:246
void free_sortmap()
Definition: psimrcc/blas.cc:136
void zero_non_external(const char *cstr)
Definition: blas_algorithms.cc:87
IndexMap indices
Definition: psimrcc/blas.h:131
void free_work()
Definition: psimrcc/blas.cc:145
void make_space(size_t memory_required)
Definition: blas_interface.cc:276
void expand_spaces(const char *out, const char *in)
Definition: blas_algorithms.cc:192
void zero_left_four_diagonal(const char *cstr)
CCMatTmp get_MatTmp(std::string str, int reference, DiskOpt disk_option)
Definition: blas_interface.cc:113
void compute()
Definition: blas_solve.cc:106
DiisType
Definition: psimrcc/blas.h:57