From c1c269adee1d6a59c400ff09e54ae5707b01d1f4 Mon Sep 17 00:00:00 2001 From: linpz Date: Tue, 23 Jan 2024 18:33:58 +0800 Subject: [PATCH] Feature: add cout time for exx calculation --- source/module_ri/Exx_LRI_interface.h | 8 +++- source/module_ri/Exx_LRI_interface.hpp | 61 ++++++++++++++++---------- 2 files changed, 43 insertions(+), 26 deletions(-) diff --git a/source/module_ri/Exx_LRI_interface.h b/source/module_ri/Exx_LRI_interface.h index 8cbf481d38..a6c67a7971 100644 --- a/source/module_ri/Exx_LRI_interface.h +++ b/source/module_ri/Exx_LRI_interface.h @@ -1,4 +1,6 @@ -#pragma once +#ifndef EXX_LRI_INTERFACE_H +#define EXX_LRI_INTERFACE_H + #include "Exx_LRI.h" #include "module_ri/Mix_DMk_2D.h" #include @@ -55,4 +57,6 @@ class Exx_LRI_Interface int two_level_step = 0; }; -#include "Exx_LRI_interface.hpp" \ No newline at end of file +#include "Exx_LRI_interface.hpp" + +#endif \ No newline at end of file diff --git a/source/module_ri/Exx_LRI_interface.hpp b/source/module_ri/Exx_LRI_interface.hpp index 7297c5c43d..02ba298f20 100644 --- a/source/module_ri/Exx_LRI_interface.hpp +++ b/source/module_ri/Exx_LRI_interface.hpp @@ -1,9 +1,14 @@ +#ifndef EXX_LRI_INTERFACE_HPP +#define EXX_LRI_INTERFACE_HPP + #include "Exx_LRI_interface.h" #include "module_ri/exx_abfs-jle.h" #include "module_ri/exx_opt_orb.h" #include "module_hamilt_lcao/hamilt_lcaodft/hamilt_lcao.h" #include "module_hamilt_lcao/hamilt_lcaodft/operator_lcao/op_exx_lcao.h" +#include + template void Exx_LRI_Interface::write_Hexxs(const std::string& file_name) const { @@ -32,13 +37,9 @@ void Exx_LRI_Interface::exx_beforescf(const K_Vectors& kv, const Charg if ( GlobalC::exx_info.info_global.cal_exx ) { if (GlobalC::ucell.atoms[0].ncpp.xc_func == "HF" || GlobalC::ucell.atoms[0].ncpp.xc_func == "PBE0" || GlobalC::ucell.atoms[0].ncpp.xc_func == "HSE") - { XC_Functional::set_xc_type("pbe"); - } else if (GlobalC::ucell.atoms[0].ncpp.xc_func == "SCAN0") - { XC_Functional::set_xc_type("scan"); - } this->exx_ptr->cal_exx_ions(); } @@ -57,13 +58,9 @@ void Exx_LRI_Interface::exx_beforescf(const K_Vectors& kv, const Charg { this->mix_DMk_2D.set_nks(kv.nks, GlobalV::GAMMA_ONLY_LOCAL); if(GlobalC::exx_info.info_global.separate_loop) - { this->mix_DMk_2D.set_mixing(nullptr); - } else - { this->mix_DMk_2D.set_mixing(chgmix.mixing); - } } // for exx two_level scf this->two_level_step = 0; @@ -139,25 +136,28 @@ bool Exx_LRI_Interface::exx_after_converge( } else { - hamilt::Operator>* exx; if(GlobalV::NSPIN < 4) { - hamilt::HamiltLCAO, double>* hamilt_lcao = - dynamic_cast, double>*>(&hamilt); - exx = new hamilt::OperatorEXX, double>>(&lm, - hamilt_lcao->getHR(), - &(hamilt_lcao->getHk(&lm)), - kv); + hamilt::HamiltLCAO, double>* hamilt_lcao + = dynamic_cast, double>*>(&hamilt); + hamilt::Operator>* exx + = new hamilt::OperatorEXX, double>>( + &lm, + hamilt_lcao->getHR(), + &(hamilt_lcao->getHk(&lm)), + kv); hamilt_lcao->getOperator()->add(exx); } else { - hamilt::HamiltLCAO, std::complex>* hamilt_lcao = - dynamic_cast, std::complex>*>(&hamilt); - exx = new hamilt::OperatorEXX, std::complex>>(&lm, - hamilt_lcao->getHR(), - &(hamilt_lcao->getHk(&lm)), - kv); + hamilt::HamiltLCAO, std::complex>* hamilt_lcao + = dynamic_cast, std::complex>*>(&hamilt); + hamilt::Operator>* exx + = new hamilt::OperatorEXX, std::complex>>( + &lm, + hamilt_lcao->getHR(), + &(hamilt_lcao->getHk(&lm)), + kv); hamilt_lcao->getOperator()->add(exx); } } @@ -207,6 +207,9 @@ bool Exx_LRI_Interface::exx_after_converge( XC_Functional::set_xc_type(GlobalC::ucell.atoms[0].ncpp.xc_func); } + std::cout << " Updating EXX " << std::flush; + timeval t_start; gettimeofday(&t_start, NULL); + const bool flag_restart = (this->two_level_step == 0) ? true : false; this->mix_DMk_2D.mix(dm.get_DMK_vector(), flag_restart); @@ -217,10 +220,20 @@ bool Exx_LRI_Interface::exx_after_converge( : RI_2D_Comm::split_m2D_ktoR(*this->exx_ptr->p_kv, this->mix_DMk_2D.get_DMk_k_out(), *dm.get_paraV_pointer()); this->exx_ptr->cal_exx_elec(Ds, *dm.get_paraV_pointer()); iter = 0; - std::cout << " Updating EXX and rerun SCF" << std::endl; this->two_level_step++; + + timeval t_end; gettimeofday(&t_end, NULL); + std::cout << "and rerun SCF\t" + << std::setprecision(3) << std::setiosflags(std::ios::scientific) + << (double)(t_end.tv_sec-t_start.tv_sec) + (double)(t_end.tv_usec-t_start.tv_usec)/1000000.0 + << std::defaultfloat << " (s)" << std::endl; return false; } } - return true; -} \ No newline at end of file + else + { + return true; + } +} + +#endif \ No newline at end of file