#include <blas.h>
Public Types | |
| typedef std::vector< std::string > | strvec |
| typedef std::vector< int > | intvec |
|
typedef std::vector< std::pair < int, int > > | intpairvec |
| typedef std::deque< CCOperation > | OpDeque |
Public Member Functions | |
| void | add_Matrix (char *cstr) |
| void | add_Matrix (std::string str) |
| void | add_index (char *cstr) |
| void | solve (char *cstr) |
| void | solve (std::string str) |
| void | solve_zero_two_diagonal (char *cstr) |
| void | zero_right_four_diagonal (char *cstr) |
| void | zero_left_four_diagonal (char *cstr) |
| void | zero_non_doubly_occupied (char *cstr) |
| void | zero_non_external (char *cstr) |
| void | reduce_spaces (char *out, char *in) |
| void | append (char *cstr) |
| void | append (std::string str) |
| void | append_zero_two_diagonal (char *cstr) |
| void | compute () |
| int | compute_storage_strategy () |
| void | show_storage () |
| void | diis_add (std::string amps, std::string delta_amps) |
| void | diis_save_t_amps (int cycle) |
| void | diis (int cycle) |
| void | print (char *cstr) |
| void | print_ref (string &str) |
| void | print_memory () |
| CCIndex * | get_index (char *cstr) |
| CCIndex * | get_index (std::string &str) |
| CCMatTmp | get_MatTmp (std::string str, int reference, DiskOpt disk_option) |
| CCMatTmp | get_MatTmp (std::string str, DiskOpt disk_option) |
| CCMatTmp | get_MatTmp (CCMatrix *Matrix, DiskOpt disk_option) |
| CCMatIrTmp | get_MatIrTmp (std::string str, int reference, int irrep, DiskOpt disk_option) |
| CCMatIrTmp | get_MatIrTmp (std::string str, int irrep, DiskOpt disk_option) |
| CCMatIrTmp | get_MatIrTmp (CCMatrix *Matrix, int irrep, DiskOpt disk_option) |
| double | get_scalar (std::string str) |
| double | get_scalar (char *cstr, int reference) |
| double | get_scalar (std::string &str, int reference) |
| void | set_scalar (char *cstr, int reference, double value) |
| void | set_scalar (std::string &str, int reference, double value) |
| MatrixMap & | get_MatrixMap () |
Definition at line 38 of file blas.h.
| void psi::psimrcc::CCBLAS::solve | ( | char * | cstr | ) |
Read and compute an expression
| cstr |
Definition at line 19 of file blas_solve.cc.
00020 { 00021 string str(cstr); 00022 solve(str); 00023 }
| void psi::psimrcc::CCBLAS::solve_zero_two_diagonal | ( | char * | cstr | ) |
store a zero_two_diagonal operation and executing it
| str |
Definition at line 222 of file blas_solve.cc.
References append_zero_two_diagonal(), and compute().
00223 { 00224 append_zero_two_diagonal(cstr); 00225 compute(); 00226 }
| void psi::psimrcc::CCBLAS::append | ( | char * | cstr | ) |
Read and store expressions without computing them
| cstr |
Definition at line 39 of file blas_solve.cc.
00040 { 00041 string str(cstr); 00042 append(str); 00043 }
| void psi::psimrcc::CCBLAS::append_zero_two_diagonal | ( | char * | cstr | ) |
store a zero_two_diagonal operation without executing it
| cstr |
Definition at line 206 of file blas_solve.cc.
References psi::psimrcc::MOInfo::get_matrix_names().
Referenced by solve_zero_two_diagonal().
00207 { 00208 string str(cstr); 00209 // To zero diagonals of things like "Fae[v][v]{u}" 00210 vector<string> names = moinfo->get_matrix_names(str); 00211 for(int n=0;n<names.size();n++){ 00212 CCMatrix* Matrix = get_Matrix(names[n]); 00213 CCOperation op(0.0,"","","zero_two_diagonal",Matrix,NULL,NULL,work[0],buffer[0]); 00214 operations.push_back(op); 00215 } 00216 }
| void psi::psimrcc::CCBLAS::compute | ( | ) |
Flush the operation deque Flush the operation deque in a memory smart way!
Definition at line 81 of file blas_solve.cc.
Referenced by solve_zero_two_diagonal().
00082 { 00083 00084 // fprintf(outfile,"\n\nsmart_compute::size of current deque = %d",operations.size()); 00085 // 00086 // fprintf(outfile,"\nsmart_compute::content of the deque:"); 00087 // for(OpDeque::iterator it = operations.begin();it!=operations.end();++it){ 00088 // fprintf(outfile,"\n"); 00089 // it->print(); 00090 // } 00091 00092 // // Create a map with all the target matrices and how many times they appear 00093 // map<string,int> target_count; 00094 // for(OpDeque::iterator it = operations.begin();it!=operations.end();++it){ 00095 // if(it->get_A_Matrix()!=NULL) 00096 // target_count[it->get_A_Matrix()->get_label()]++; 00097 // } 00098 // // Create a map with all the source matrices and how many times they appear 00099 // map<string,int> source_count; 00100 // for(OpDeque::iterator it = operations.begin();it!=operations.end();++it){ 00101 // if(it->get_B_Matrix()!=NULL) 00102 // source_count[it->get_B_Matrix()->get_label()]++; 00103 // if(it->get_C_Matrix()!=NULL) 00104 // source_count[it->get_C_Matrix()->get_label()]++; 00105 // } 00106 // 00107 // // Create a map with all the intermediates defined as matrices that appear a source and target 00108 // map<string,int> intermediates_count; 00109 // for(map<string,int>::iterator it=matrix_count.begin();it!=matrix_count.end();++it){ 00110 // map<string,int>::iterator target_it = target_count.find(it->first); 00111 // map<string,int>::iterator source_it = source_count.find(it->first); 00112 // if( (target_it!=target_count.end()) && (source_it!=source_count.end())) 00113 // intermediates_count[source_it->first]=source_it->second; 00114 // } 00115 // 00116 // // Print the map for debugging purposes 00117 // fprintf(outfile,"\n\nsmart_compute::printing the matrix_count map"); 00118 // for(map<string,int>::iterator it=matrix_count.begin();it!=matrix_count.end();++it){ 00119 // fprintf(outfile,"\n %s(%d)",it->first.c_str(),it->second); 00120 // } 00121 // 00122 // // Print the map for debugging purposes 00123 // fprintf(outfile,"\n\nsmart_compute::printing the target_count map"); 00124 // for(map<string,int>::iterator it=target_count.begin();it!=target_count.end();++it){ 00125 // fprintf(outfile,"\n %s(%d)",it->first.c_str(),it->second); 00126 // } 00127 // 00128 // // Print the map for debugging purposes 00129 // fprintf(outfile,"\n\nsmart_compute::printing the source_count map"); 00130 // for(map<string,int>::iterator it=source_count.begin();it!=source_count.end();++it){ 00131 // fprintf(outfile,"\n %s(%d)",it->first.c_str(),it->second); 00132 // } 00133 // 00134 // // Print the map for debugging purposes 00135 // fprintf(outfile,"\n\nsmart_compute::printing the intermediates_count map"); 00136 // for(map<string,int>::iterator it=intermediates_count.begin();it!=intermediates_count.end();++it){ 00137 // fprintf(outfile,"\n %s(%d)",it->first.c_str(),it->second); 00138 // } 00139 00140 // map<string,bool> matrix_on_disk; 00141 // map<string,bool> matrix_in_core; 00142 // for(map<string,int>::iterator it=matrix_count.begin();it!=matrix_count.end();++it){ 00143 // if(it->first[0]=='<' 00144 // matrix_on_disk[it->first]=false; 00145 // matrix_on_disk[it->first]=false; 00146 // } 00147 00148 // for(OpDeque::iterator it = operations.begin();it!=operations.end();++it){ 00149 // 00150 // } 00151 // static int memory_for_solve = 0; 00152 // 00153 // for(OpDeque::iterator it = operations.begin();it!=operations.end();++it){ 00154 // int nop = distance(it-operations.begin()); 00155 // fprintf(outfile,"\nI will process operation #%3d",nop); 00156 // int memA=0; 00157 // if(it->get_A_Matrix()!=NULL){ 00158 // memA=it->get_A_Matrix()->get_memory(); 00159 // } 00160 // } 00161 00162 // Create a map with all the required matrices and how many times they appear 00163 00164 for(OpDeque::iterator it = operations.begin();it!=operations.end();++it){ 00165 if(it->get_A_Matrix()!=NULL){ 00166 matrices_in_deque[it->get_A_Matrix()]++; 00167 matrices_in_deque_target[it->get_A_Matrix()]++; 00168 } 00169 if(it->get_B_Matrix()!=NULL){ 00170 matrices_in_deque[it->get_B_Matrix()]++; 00171 matrices_in_deque_source[it->get_B_Matrix()]++; 00172 } 00173 if(it->get_C_Matrix()!=NULL){ 00174 matrices_in_deque[it->get_C_Matrix()]++; 00175 matrices_in_deque_source[it->get_C_Matrix()]++; 00176 } 00177 } 00178 while(!operations.empty()){ 00179 // Read the element 00180 CCOperation& op = operations.front(); 00181 // Compute the operation 00182 op.compute(); 00183 00184 // Decrease the counters for the matrices to be processed 00185 if(op.get_A_Matrix()!=NULL){ 00186 matrices_in_deque[op.get_A_Matrix()]--; 00187 matrices_in_deque_target[op.get_A_Matrix()]--; 00188 } 00189 if(op.get_B_Matrix()!=NULL){ 00190 matrices_in_deque[op.get_B_Matrix()]--; 00191 matrices_in_deque_source[op.get_B_Matrix()]--; 00192 } 00193 if(op.get_C_Matrix()!=NULL){ 00194 matrices_in_deque[op.get_C_Matrix()]--; 00195 matrices_in_deque_source[op.get_C_Matrix()]--; 00196 } 00197 // Eliminate the element 00198 operations.pop_front(); 00199 } 00200 }
| int psi::psimrcc::CCBLAS::compute_storage_strategy | ( | ) |
This routine computes which quantities have to be initially stored in memory and which on disk
Definition at line 248 of file blas.cc.
References psi::psimrcc::MOInfo::get_nirreps().
Referenced by psi::psimrcc::CCManyBody::generate_integrals().
00249 { 00250 fprintf(outfile,"\n#CC ----------------------------------"); 00251 fprintf(outfile,"\n#CC Computing Storage Strategy"); 00252 fprintf(outfile,"\n#CC ----------------------------------"); 00253 00254 double available_memory = mem->get_free_memory(); 00255 double fraction_for_in_core = 0.97; // Fraction of the total available memory that may be used 00256 double storage_memory = available_memory * fraction_for_in_core; 00257 double fully_in_core_memory = 0.0; 00258 double integrals_memory = 0.0; 00259 double fock_memory = 0.0; 00260 double others_memory = 0.0; 00261 00262 fprintf(outfile,"\n#CC Input memory = %10.2f Mb",mem->get_total_memory()); 00263 fprintf(outfile,"\n#CC Free memory = %10.2f Mb",available_memory); 00264 fprintf(outfile,"\n#CC Free memory available for matrices = %10.2f Mb (%3.0f%s of free_memory)",storage_memory,fraction_for_in_core*100.0,"%"); 00265 00266 // Gather the memory requirements for all the CCMAtrix object 00267 // and divide the integrals from all the other matrices. 00268 // At the same time compute the memory requirements for 00269 // a fully in-core algorithm. 00270 vector<pair<double,pair<CCMatrix*,int> > > integrals; 00271 vector<pair<double,pair<CCMatrix*,int> > > fock; 00272 vector<pair<double,pair<CCMatrix*,int> > > others; 00273 for(MatrixMap::iterator it=matrices.begin();it!=matrices.end();++it){ 00274 for(int h=0;h<moinfo->get_nirreps();++h){ 00275 double block_memory = it->second->get_memorypi(h); 00276 if(it->second->is_integral()){ 00277 integrals.push_back(make_pair(block_memory,make_pair(it->second,h))); 00278 integrals_memory += block_memory; 00279 }else if(it->second->is_fock()){ 00280 fock.push_back(make_pair(block_memory,make_pair(it->second,h))); 00281 fock_memory += block_memory; 00282 }else{ 00283 others.push_back(make_pair(block_memory,make_pair(it->second,h))); 00284 others_memory += block_memory; 00285 } 00286 fully_in_core_memory += block_memory; 00287 } 00288 } 00289 fprintf(outfile,"\n#CC Memory required by fock matrices = %10.2f Mb",fock_memory); 00290 fprintf(outfile,"\n#CC Memory required by integrals = %10.2f Mb",integrals_memory); 00291 fprintf(outfile,"\n#CC Memory required by other matrices = %10.2f Mb",others_memory); 00292 fprintf(outfile,"\n#CC Memory required for full in-core algorithm = %10.2f Mb",fully_in_core_memory); 00293 00294 // Check if you may use a fully in core algorithm 00295 full_in_core = false; 00296 int strategy = 0; 00297 if(fully_in_core_memory < storage_memory ){ 00298 full_in_core = true; 00299 fprintf(outfile,"\n#CC PSIMRCC will perform a full in-core computation"); 00300 strategy = 0; 00301 }else{ 00302 if(others_memory < storage_memory ){ 00303 fprintf(outfile,"\n#CC PSIMRCC will store some integrals out-of-core"); 00304 strategy = 1; 00305 }else{ 00306 fprintf(outfile,"\n#CC PSIMRCC will store all integrals and some other matrices out-of-core"); 00307 strategy = 2; 00308 fprintf(outfile,"\n#CC CCBLAS::compute_storage_strategy(): Strategy #2 is not implemented yet"); 00309 fflush(outfile); 00310 exit(1); 00311 } 00312 } 00313 sort(integrals.begin(),integrals.end()); 00314 sort(others.begin(),others.end()); 00315 for(int i=0;i<fock.size();i++){ 00316 // Store all the fock matrices in core and allocate them 00317 storage_memory -= fock[i].first; 00318 load_irrep(fock[i].second.first,fock[i].second.second); 00319 } 00320 // Let the CCBlas class worry about allocating matrices 00321 int number_of_others_on_disk = 0; 00322 for(int i=0;i<others.size();i++){ 00323 // Check if this matrix can be stored in core 00324 if(others[i].first < storage_memory){ 00325 storage_memory -= others[i].first; 00326 load_irrep(others[i].second.first,others[i].second.second); 00327 }else{ 00328 number_of_others_on_disk++; 00329 } 00330 } 00331 int number_of_integrals_on_disk = 0; 00332 for(int i=0;i<integrals.size();i++){ 00333 // Check if this matrix can be stored in core 00334 if(integrals[i].first < storage_memory){ 00335 storage_memory -= integrals[i].first; 00336 load_irrep(integrals[i].second.first,integrals[i].second.second); 00337 }else{ 00338 number_of_integrals_on_disk++; 00339 } 00340 } 00341 00342 DEBUGGING(1, 00343 fprintf(outfile,"\n#CC -------------------- Fock matrices -------------------------"); 00344 for(int i=0;i<fock.size();i++){ 00345 if(fock[i].first > 1.0e-5){ 00346 fprintf(outfile,"\n#CC %-32s irrep %d %6.2f Mb --> ",fock[i].second.first->get_label().c_str(), 00347 fock[i].second.second, 00348 fock[i].first); 00349 fprintf(outfile,"%s",fock[i].second.first->is_block_allocated(fock[i].second.second) ? "in-core" : "out-of-core"); 00350 } 00351 } 00352 fprintf(outfile,"\n#CC -------------------- Other matrices ------------------------"); 00353 for(int i=0;i<others.size();i++){ 00354 if(others[i].first > 1.0e-5){ 00355 fprintf(outfile,"\n#CC %-32s irrep %d %6.2f Mb --> ",others[i].second.first->get_label().c_str(), 00356 others[i].second.second, 00357 others[i].first); 00358 fprintf(outfile,"%s",others[i].second.first->is_block_allocated(others[i].second.second) ? "in-core" : "out-of-core"); 00359 } 00360 } 00361 fprintf(outfile,"\n#CC -------------------- Integrals -----------------------------"); 00362 for(int i=0;i<integrals.size();i++){ 00363 if(integrals[i].first > 1.0e-5){ 00364 fprintf(outfile,"\n#CC %-32s irrep %d %6.2f Mb --> ",integrals[i].second.first->get_label().c_str(), 00365 integrals[i].second.second, 00366 integrals[i].first); 00367 fprintf(outfile,"%s",integrals[i].second.first->is_block_allocated(integrals[i].second.second) ? "in-core" : "out-of-core"); 00368 } 00369 } 00370 fprintf(outfile,"\n\n"); 00371 ); 00372 00373 if(!full_in_core){ 00374 fprintf(outfile,"\n#CC Out-of-core algorithm will store %d other matrices on disk",number_of_others_on_disk); 00375 fprintf(outfile,"\n#CC Out-of-core algorithm will store %d integrals on disk",number_of_integrals_on_disk); 00376 } 00377 return(strategy); 00378 }
| void psi::psimrcc::CCBLAS::show_storage | ( | ) |
This routine computes which quantities have to be initially stored in memory and which on disk
Definition at line 383 of file blas.cc.
References psi::psimrcc::MOInfo::get_nirreps().
00384 { 00385 DEBUGGING(1, 00386 fprintf(outfile,"\n#CC ----------------------------------"); 00387 fprintf(outfile,"\n#CC Show Storage "); 00388 fprintf(outfile,"\n#CC ----------------------------------"); 00389 00390 for(MatrixMap::iterator it=matrices.begin();it!=matrices.end();++it){ 00391 for(int h=0;h<moinfo->get_nirreps();++h){ 00392 double block_memory = it->second->get_memorypi(h); 00393 fprintf(outfile,"\n#CC %-32s irrep %d %6.2f Mb",it->second->get_label().c_str(),h,block_memory); 00394 fprintf(outfile," is %s",it->second->is_block_allocated(h) ? "allocated" : "not allocated"); 00395 fprintf(outfile,"%s",it->second->is_out_of_core(h) ? "(out-of-core)" : ""); 00396 00397 } 00398 } 00399 ) 00400 }
1.5.4