00001
00002
00003
00004
00005
00006 #include "blas.h"
00007 #include "debugging.h"
00008 #include "memory_manager.h"
00009 #include "moinfo.h"
00010 #include "utilities.h"
00011 #include <libciomr/libciomr.h>
00012 #include <libqt/qt.h>
00013
00014 extern FILE *infile, *outfile;
00015
00016 namespace psi{ namespace psimrcc{
00017
00018 using namespace std;
00019
00020 void CCBLAS::add_index(char* cstr)
00021 {
00022
00023 string str(cstr);
00024 to_lower(str);
00025 if(indices.find(str)==indices.end()){
00026 indices.insert(make_pair(str,new CCIndex(str)));
00027 }
00028 }
00029
00030 void CCBLAS::add_Matrix(char* cstr)
00031 {
00032 string str(cstr);
00033 vector<string> names = moinfo->get_matrix_names(str);
00034 for(int n=0;n<names.size();n++)
00035 add_Matrix_ref(names[n]);
00036 }
00037
00038 void CCBLAS::add_Matrix(string str)
00039 {
00040 vector<string> names = moinfo->get_matrix_names(str);
00041 for(int n=0;n<names.size();n++)
00042 add_Matrix_ref(names[n]);
00043 }
00044
00045 void CCBLAS::add_Matrix_ref(std::string& str)
00046 {
00047
00048 MatrixMap::iterator iter = matrices.find(str);
00049 if(iter==matrices.end()){
00050 CCIndex* index_pointer[2];
00051
00052 index_pointer[0]=get_index("[]");
00053 index_pointer[1]=get_index("[]");
00054 vector<string> index_string_vec = split_indices(str);
00055 for(int i=0;i<index_string_vec.size();++i)
00056 index_pointer[i]=get_index(index_string_vec[i]);
00057 matrices.insert(make_pair(str,new CCMatrix(str,index_pointer[0],index_pointer[1])));
00058 }
00059 }
00060
00061 CCIndex* CCBLAS::get_index(char* cstr)
00062 {
00063 string str(cstr);
00064 to_lower(str);
00065
00066 IndexMap::iterator iter = indices.find(str);
00067 if(iter!=indices.end()){
00068 return(indices[str]);
00069 }
00070 string err("\nCCBLAS::get_index() couldn't find index " + str);
00071 print_error(err,__FILE__,__LINE__);
00072 return(NULL);
00073 }
00074
00075 CCIndex* CCBLAS::get_index(string& str)
00076 {
00077 to_lower(str);
00078
00079 IndexMap::iterator iter = indices.find(str);
00080 if(iter!=indices.end()){
00081 return(indices[str]);
00082 }
00083 string err("\nCCBLAS::get_index() couldn't find index " + str);
00084 print_error(err,__FILE__,__LINE__);
00085 return(NULL);
00086 }
00087
00088 CCMatTmp CCBLAS::get_MatTmp(std::string str, int reference, DiskOpt disk_option)
00089 {
00090 append_reference(str,reference);
00091 load(get_Matrix(str));
00092 return(CCMatTmp(get_Matrix(str),disk_option));
00093 }
00094
00095 CCMatTmp CCBLAS::get_MatTmp(std::string str, DiskOpt disk_option)
00096 {
00097 load(get_Matrix(str));
00098 return(CCMatTmp(get_Matrix(str),disk_option));
00099 }
00100
00101 CCMatTmp CCBLAS::get_MatTmp(CCMatrix* Matrix, DiskOpt disk_option)
00102 {
00103 load(Matrix);
00104 return(CCMatTmp(Matrix,disk_option));
00105 }
00106
00107 CCMatIrTmp CCBLAS::get_MatIrTmp(std::string str, int reference, int irrep, DiskOpt disk_option)
00108 {
00109 append_reference(str,reference);
00110 load_irrep(get_Matrix(str),irrep);
00111 return(CCMatIrTmp(get_Matrix(str),irrep,disk_option));
00112 }
00113
00114 CCMatIrTmp CCBLAS::get_MatIrTmp(std::string str, int irrep, DiskOpt disk_option)
00115 {
00116 load_irrep(get_Matrix(str),irrep);
00117 return(CCMatIrTmp(get_Matrix(str),irrep,disk_option));
00118 }
00119
00120 CCMatIrTmp CCBLAS::get_MatIrTmp(CCMatrix* Matrix, int irrep, DiskOpt disk_option)
00121 {
00122 load_irrep(Matrix,irrep);
00123 return(CCMatIrTmp(Matrix,irrep,disk_option));
00124 }
00125
00126 CCMatrix* CCBLAS::get_Matrix(char* cstr, int reference)
00127 {
00128 string str(cstr);
00129 append_reference(str,reference);
00130 return(get_Matrix(str));
00131 }
00132
00133 CCMatrix* CCBLAS::get_Matrix(char* cstr)
00134 {
00135 string str(cstr);
00136 return(get_Matrix(str));
00137 }
00138
00139 CCMatrix* CCBLAS::get_Matrix(string& str)
00140 {
00141
00142 MatrixMap::iterator iter = matrices.find(str);
00143 if(iter!=matrices.end())
00144 return(matrices[str]);
00145 string err("\nCCBLAS::get_matrix() couldn't find matrix " + str);
00146 print_error(err,__FILE__,__LINE__);
00147 return(NULL);
00148 }
00149
00150 CCMatrix* CCBLAS::get_Matrix(string& str, string& expression)
00151 {
00152
00153 MatrixMap::iterator iter = matrices.find(str);
00154 if(iter!=matrices.end()){
00155 return(matrices[str]);
00156 }
00157 fprintf(outfile,"\n\nCCBLAS::parse() couldn't find matrix %s in the CCMatrix list\n\nwhile parsing the string:\n\t%s\n\n",str.c_str(),expression.c_str());
00158 fflush(outfile);
00159 exit(1);
00160 }
00161
00162 void CCBLAS::set_scalar(char* cstr,int reference,double value)
00163 {
00164 string str(cstr);
00165 set_scalar(str,reference,value);
00166 }
00167
00168 void CCBLAS::set_scalar(string& str,int reference,double value)
00169 {
00170 string matrix_str = add_reference(str,reference);
00171
00172 MatrixMap::iterator iter = matrices.find(matrix_str);
00173 if(iter!=matrices.end()){
00174 load(iter->second);
00175 iter->second->set_scalar(value);
00176 return;
00177 }
00178 string err("\nCCBLAS::set_scalar() couldn't find matrix " + matrix_str);
00179 print_error(err.c_str(),__FILE__,__LINE__);
00180 }
00181
00182 double CCBLAS::get_scalar(char* cstr,int reference)
00183 {
00184 string str(cstr);
00185 return(get_scalar(str,reference));
00186 }
00187
00188 double CCBLAS::get_scalar(string& str,int reference)
00189 {
00190 string matrix_str(str);
00191 append_reference(matrix_str,reference);
00192
00193 MatrixMap::iterator iter = matrices.find(matrix_str);
00194 if(iter!=matrices.end()){
00195 load(iter->second);
00196 return(iter->second->get_scalar());
00197 }
00198 string err("\nCCBLAS::get_scalar() couldn't find matrix " + matrix_str);
00199 print_error(err.c_str(),__FILE__,__LINE__);
00200 return (0.0);
00201 }
00202
00203 double CCBLAS::get_scalar(string str)
00204 {
00205
00206 MatrixMap::iterator iter = matrices.find(str);
00207 if(iter!=matrices.end()){
00208 load(iter->second);
00209 return(iter->second->get_scalar());
00210 }
00211 string err("\nCCBLAS::get_scalar() couldn't find matrix " + str);
00212 print_error(err.c_str(),__FILE__,__LINE__);
00213 return (0.0);
00214 }
00215
00216 void CCBLAS::load(CCMatrix* Matrix)
00217 {
00218 if(Matrix->is_allocated()){
00219 DEBUGGING(2,
00220 fprintf(outfile,"\nCCBLAS::load(%s): matrix is in core.",Matrix->get_label().c_str());
00221 );
00222 }else{
00223 DEBUGGING(2,
00224 fprintf(outfile,"\nCCBLAS::load(%s): matrix is not in core. Loading it :[",Matrix->get_label().c_str());
00225 );
00226
00227 double memory_required = Matrix->get_memory();
00228 make_space(memory_required);
00229 Matrix->load();
00230 DEBUGGING(2,
00231 fprintf(outfile,"\n] <- done.");
00232 );
00233 }
00234 }
00235
00236 void CCBLAS::load_irrep(CCMatrix* Matrix,int h)
00237 {
00238 if(Matrix->is_block_allocated(h)){
00239 DEBUGGING(2,
00240 fprintf(outfile,"\nCCBLAS::load_irrep(%s,%d): matrix block is in core.",Matrix->get_label().c_str(),h);
00241 )
00242 }else{
00243 DEBUGGING(2,
00244 fprintf(outfile,"\nCCBLAS::load_irrep(%s,%d): matrix block is not in core. Loading it : [",Matrix->get_label().c_str(),h);
00245 )
00246
00247 double memory_required = Matrix->get_memorypi(h);
00248 make_space(memory_required);
00249 Matrix->load_irrep(h);
00250 DEBUGGING(2,
00251 fprintf(outfile,"\n] <- done.");
00252 )
00253 }
00254 }
00255
00256 void CCBLAS::make_space(double memory_required)
00257 {
00258 if(memory_required < mem->get_free_memory())
00259 return;
00260 else{
00261 fprintf(outfile,"\nCCBLAS::make_space() not implemented yet!!!");
00262
00263
00264
00265 }
00266 }
00267
00268
00269
00270
00271
00272
00273
00274
00275
00276
00277
00278
00279
00280
00281
00282
00283
00284
00285
00286
00287
00288
00289
00290
00291 }}