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 
44 #include "matrixtmp.h"
45 #include "operation.h"
46 
47 #include "index_types.h"
48 #include "matrix_types.h"
49 #include "types.h"
50 
51 namespace psi{ namespace psimrcc{
52 
53 class CCIndex;
54 class CCMatrix;
55 
57 
61 class CCBLAS{
62 public:
63  typedef std::vector<std::string> strvec;
64  typedef std::vector<int> intvec;
65  typedef std::vector<std::pair<int,int> > intpairvec;
66  typedef std::deque<CCOperation> OpDeque;
67 
68 
69  CCBLAS(Options &options);
70  ~CCBLAS();
71 
73  // Add routines
74  void add_Matrix(const char* cstr);
75  void add_Matrix(std::string str);
76  void add_index(const char* cstr);
77  // Solve and sort
78  void solve(const char* cstr);
79  void solve(std::string str);
80  void solve_zero_two_diagonal(const char* cstr);
81  void zero_right_four_diagonal(const char* cstr);
82  void zero_left_four_diagonal(const char* cstr);
83  void zero_non_doubly_occupied(const char* cstr);
84  void zero_non_external(const char* cstr);
85  void zero(const char* cstr);
86  void scale(const char* cstr,int reference,double value);
87  void scale(std::string& str,int reference,double value);
88  void reduce_spaces(const char* out,const char* in);
89  void expand_spaces(const char* out,const char* in);
90  void append(const char* cstr);
91  void append(std::string str);
92  void append_zero_two_diagonal(const char* cstr);
93  void compute();
95  void show_storage();
96  // DIIS
97  void diis_add(std::string amps, std::string delta_amps);
98  void diis_save_t_amps(int cycle);
99  void diis(int cycle, double delta, DiisType diis_type);
100  // Printing
101  void print(const char* cstr);
102  void print_ref(std::string& str);
103  void print_memory();
104  // Safe get and set
105  CCIndex* get_index(const char* cstr);
106  CCIndex* get_index(std::string& str);
107  CCMatTmp get_MatTmp(std::string str, int reference, DiskOpt disk_option);
108  CCMatTmp get_MatTmp(std::string str, DiskOpt disk_option);
109  CCMatTmp get_MatTmp(CCMatrix* Matrix, DiskOpt disk_option);
110  CCMatIrTmp get_MatIrTmp(std::string str, int reference, int irrep, DiskOpt disk_option);
111  CCMatIrTmp get_MatIrTmp(std::string str, int irrep, DiskOpt disk_option);
112  CCMatIrTmp get_MatIrTmp(CCMatrix* Matrix, int irrep, DiskOpt disk_option);
113 
114  double get_scalar(std::string str);
115  double get_scalar(const char* cstr,int reference);
116  double get_scalar(std::string& str,int reference);
117  void set_scalar(const char* cstr,int reference,double value);
118  void set_scalar(std::string& str,int reference,double value);
119 
120  //DIIS
121  std::vector<std::pair<std::string,std::string> > diis_matrices;
122 
123  // These have to be improved
125 private:
127  size_t work_size;
128  size_t buffer_size;
138 private:
139 
141  CCMatrix* get_Matrix(std::string& str);
142  CCMatrix* get_Matrix(const char* cstr);
143  CCMatrix* get_Matrix(const char* cstr, int reference);
144  CCMatrix* get_Matrix(std::string& str,std::string& expression); // Prints a clear error message
145  double* get_work(int n) {return(work[n]);}
146 // double*** get_sortmap(CCIndex* T_left,CCIndex* T_right,int thread);
147 
149  void load(CCMatrix* Matrix);
150  void load_irrep(CCMatrix* Matrix,int h);
152  // Class private functions
154  void add_Matrix_ref(std::string& str);
155  void add_indices();
156  void add_matrix_ref(std::string& str);
157  void solve_ref(std::string& str);
158  int parse(std::string& str);
159  void process_operations();
160  void process_reduce_spaces(CCMatrix* out_Matrix,CCMatrix* in_Matrix);
161  void process_expand_spaces(CCMatrix* out_Matrix,CCMatrix* in_Matrix);
162  bool get_factor(const std::string& str,double& factor);
163  // General routines
164 
165  void make_space(size_t memory_required);
166  // Low level memory routines
167  void init();
168  void cleanup();
169  void allocate_work();
170  void allocate_buffer();
171  void free_sortmap();
172  void free_work();
173  void free_indices();
174  void free_matrices();
175  void free_buffer();
176 };
177 
178 extern CCBLAS *blas;
179 
180 }} /* End Namespaces */
181 
182 #endif // _psi_src_bin_psimrcc_ccblas_h
size_t work_size
Definition: psimrcc/blas.h:127
double * get_work(int n)
Definition: psimrcc/blas.h:145
void cleanup()
Definition: psimrcc/blas.cc:73
MatCnt matrices_in_deque_source
Definition: psimrcc/blas.h:136
IndexMap & get_IndexMap()
Definition: psimrcc/blas.h:140
PsiReturnType psimrcc(SharedWavefunction, Options &)
Definition: psimrcc/main.cc:87
CCBLAS(Options &options)
Definition: psimrcc/blas.cc:51
void set_scalar(const char *cstr, int reference, double value)
Definition: blas_interface.cc:187
Options & options_
Definition: psimrcc/blas.h:72
CCMatrix * get_Matrix(std::string &str)
Definition: psimrcc/matrix.h:48
void load_irrep(CCMatrix *Matrix, int h)
Definition: blas_interface.cc:258
void diis_save_t_amps(int cycle)
Definition: blas_diis.cc:70
std::vector< std::string > strvec
Definition: psimrcc/blas.h:63
Definition: matrixtmp.h:47
MatrixMap matrices
Definition: psimrcc/blas.h:129
void free_buffer()
Definition: psimrcc/blas.cc:157
void allocate_buffer()
Definition: psimrcc/blas.cc:114
void print_memory()
Definition: psimrcc/blas.cc:270
void diis_add(std::string amps, std::string delta_amps)
Definition: blas_diis.cc:61
std::vector< std::pair< int, int > > intpairvec
Definition: psimrcc/blas.h:65
int compute_storage_strategy()
Definition: psimrcc/blas.cc:309
void free_matrices()
Definition: psimrcc/blas.cc:167
std::map< std::string, psi::psimrcc::CCIndex * > IndexMap
Definition: index_types.h:32
double get_scalar(std::string str)
MatCnt matrices_in_deque_target
Definition: psimrcc/blas.h:135
void free_indices()
Definition: psimrcc/blas.cc:174
void solve(const char *cstr)
Definition: blas_solve.cc:46
Definition: index.h:67
void process_reduce_spaces(CCMatrix *out_Matrix, CCMatrix *in_Matrix)
Definition: blas_algorithms.cc:138
void add_indices()
Definition: psimrcc/blas.cc:181
Definition: psimrcc/blas.h:56
void diis(int cycle, double delta, DiisType diis_type)
Definition: blas_diis.cc:89
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:75
void reference(void)
Definition: reference.cc:49
CCIndex * get_index(const char *cstr)
Definition: blas_interface.cc:90
Definition: psimrcc/blas.h:56
MatrixMap & get_MatrixMap()
Definition: psimrcc/blas.h:124
std::vector< double * > ArrayVec
Definition: types.h:32
bool full_in_core
Definition: psimrcc/blas.h:126
void zero_right_four_diagonal(const char *cstr)
Definition: blas_algorithms.cc:61
void load(CCMatrix *Matrix)
Definition: blas_interface.cc:238
OpDeque operations
Definition: psimrcc/blas.h:131
void reduce_spaces(const char *out, const char *in)
Definition: blas_algorithms.cc:122
size_t buffer_size
Definition: psimrcc/blas.h:128
std::map< psi::psimrcc::CCMatrix *, int > MatCnt
Definition: matrix_types.h:32
void print_ref(std::string &str)
Definition: psimrcc/blas.cc:265
std::vector< int > intvec
Definition: psimrcc/blas.h:64
void print(const char *cstr)
Definition: psimrcc/blas.cc:257
void init()
Definition: psimrcc/blas.cc:66
void solve_ref(std::string &str)
void scale(const char *cstr, int reference, double value)
Definition: blas_algorithms.cc:103
~CCBLAS()
Definition: psimrcc/blas.cc:61
Definition: psimrcc/blas.h:61
std::map< std::string, psi::psimrcc::CCMatrix * > MatrixMap
Definition: matrix_types.h:33
Makes using matrices just a little easier.
Definition: libmints/matrix.h:70
void append(const char *cstr)
Definition: blas_solve.cc:66
std::deque< CCOperation > OpDeque
Definition: psimrcc/blas.h:66
Definition: liboptions.h:360
void process_expand_spaces(CCMatrix *out_Matrix, CCMatrix *in_Matrix)
Definition: blas_algorithms.cc:210
void solve_zero_two_diagonal(const char *cstr)
Definition: blas_solve.cc:249
std::map< std::string, double *** > SortMap
Definition: types.h:33
SortMap sortmap
Definition: psimrcc/blas.h:137
MatCnt matrices_in_deque
Definition: psimrcc/blas.h:134
Definition: matrixtmp.h:61
void show_storage()
Definition: psimrcc/blas.cc:444
std::vector< std::pair< std::string, std::string > > diis_matrices
Definition: psimrcc/blas.h:121
DiskOpt
Definition: matrixtmp.h:42
int delta(const int i, const int j)
Definition: bend.cc:176
ArrayVec buffer
Definition: psimrcc/blas.h:133
void allocate_work()
Definition: psimrcc/blas.cc:82
void add_index(const char *cstr)
Definition: blas_interface.cc:49
CCMatIrTmp get_MatIrTmp(std::string str, int reference, int irrep, DiskOpt disk_option)
Definition: blas_interface.cc:134
void allocate_matrices_in_core()
void append_zero_two_diagonal(const char *cstr)
Definition: blas_solve.cc:233
void add_Matrix(const char *cstr)
Definition: blas_interface.cc:59
void add_Matrix_ref(std::string &str)
Definition: blas_interface.cc:74
void add_matrix_ref(std::string &str)
void zero(const char *cstr)
Definition: blas_algorithms.cc:47
int parse(std::string &str)
Definition: blas_parser.cc:48
CCBLAS * blas
Definition: psimrcc/main.cc:78
ArrayVec work
Definition: psimrcc/blas.h:132
indices
Definition: libdpd/dpd.h:246
void free_sortmap()
Definition: psimrcc/blas.cc:138
void zero_non_external(const char *cstr)
Definition: blas_algorithms.cc:89
IndexMap indices
Definition: psimrcc/blas.h:130
void free_work()
Definition: psimrcc/blas.cc:147
void make_space(size_t memory_required)
Definition: blas_interface.cc:278
void expand_spaces(const char *out, const char *in)
Definition: blas_algorithms.cc:194
void zero_left_four_diagonal(const char *cstr)
CCMatTmp get_MatTmp(std::string str, int reference, DiskOpt disk_option)
Definition: blas_interface.cc:115
void compute()
Definition: blas_solve.cc:108
DiisType
Definition: psimrcc/blas.h:56