Skip to content

Commit a30cae7

Browse files
committed
Merge branch 'develop' of https://github.com/mohanchen/abacus-mc into develop
2 parents 7ac520f + aee5691 commit a30cae7

File tree

170 files changed

+1215
-936
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

170 files changed

+1215
-936
lines changed

docs/advanced/input_files/input-main.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -599,7 +599,7 @@ These variables are used to control general system parameters.
599599
- nao: from numerical atomic orbitals. If they are not enough, other wave functions are initialized with random numbers.
600600
- nao+random: add small random numbers on numerical atomic orbitals
601601

602-
> Only the `file` option is useful for the lcao basis set, which is mostly used when [calculation](#calculation) is set to `set_wf` and `get_pchg`. See more details in [out_wfc_lcao](#out_wfc_lcao).
602+
> Only the `file` option is useful for the lcao basis set, which is mostly used when [calculation](#calculation) is set to `get_wf` and `get_pchg`. See more details in [out_wfc_lcao](#out_wfc_lcao).
603603
- **Default**: atomic
604604

605605
### init_chg
@@ -1928,7 +1928,7 @@ The band (KS orbital) energy for each (k-point, spin, band) will be printed in t
19281928
### if_separate_k
19291929

19301930
- **Type**: Boolean
1931-
- **Availability**: Only for LCAO, used only when `calculation = get_pchg` and `gamma_only` is turned off.
1931+
- **Availability**: For both PW and LCAO. When `basis_type = pw`, used if `out_pchg` is set. When `basis_type = lcao`, used only when `calculation = get_pchg` and `gamma_only` is turned off.
19321932
- **Description**: Specifies whether to write the partial charge densities for all k-points to individual files or merge them. **Warning**: Enabling symmetry may produce incorrect results due to incorrect k-point weights. Therefore, when calculating partial charge densities, it is strongly recommended to set `symmetry = -1`.
19331933
- **Default**: false
19341934

source/module_elecstate/module_charge/symmetry_rho.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ void Symmetry_rho::psymm(double* rho_part,
9797
rhotot.resize(rho_basis->nxyz);
9898
ModuleBase::GlobalFunc::ZEROS(rhotot.data(), rho_basis->nxyz);
9999
}
100-
Pgrid.reduce(rhotot.data(), rho_part);
100+
Pgrid.reduce(rhotot.data(), rho_part, false);
101101

102102
// (2)
103103
if (GlobalV::MY_RANK == 0)

source/module_esolver/esolver_fp.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33

44
#include "esolver.h"
55

6+
#ifndef __MPI
7+
#include <chrono>
8+
#endif
9+
610
//! plane wave basis
711
#include "module_basis/module_pw/pw_basis.h"
812

@@ -98,6 +102,12 @@ class ESolver_FP: public ESolver
98102

99103
int pw_rho_flag = false; ///< flag for pw_rho, 0: not initialized, 1: initialized
100104

105+
//! the start time of scf iteration
106+
#ifdef __MPI
107+
double iter_time;
108+
#else
109+
std::chrono::system_clock::time_point iter_time;
110+
#endif
101111
};
102112
} // namespace ModuleESolver
103113

source/module_esolver/esolver_ks.h

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,6 @@
11
#ifndef ESOLVER_KS_H
22
#define ESOLVER_KS_H
33

4-
#ifdef __MPI
5-
#include <mpi.h>
6-
#else
7-
#include <chrono>
8-
#endif
9-
104
#include <cstring>
115
//#include <fstream>
126

@@ -79,13 +73,6 @@ class ESolver_KS : public ESolver_FP
7973
//! Electronic wavefunctions
8074
psi::Psi<T>* psi = nullptr;
8175

82-
//! the start time of scf iteration
83-
#ifdef __MPI
84-
double iter_time;
85-
#else
86-
std::chrono::system_clock::time_point iter_time;
87-
#endif
88-
8976
std::string basisname; //! esolver_ks_lcao.cpp
9077
double esolver_KS_ne = 0.0; //! number of electrons
9178
double diag_ethr; //! the threshold for diagonalization

source/module_esolver/esolver_ks_pw.cpp

Lines changed: 44 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -645,14 +645,24 @@ void ESolver_KS_PW<T, Device>::iter_finish(UnitCell& ucell, const int istep, int
645645
//----------------------------------------------------------
646646
// 3) Print out electronic wavefunctions in pw basis
647647
//----------------------------------------------------------
648-
if (iter % PARAM.inp.out_freq_elec == 0 || iter == PARAM.inp.scf_nmax || conv_esolver)
649-
{
650-
ModuleIO::write_wfc_pw(GlobalV::KPAR, GlobalV::MY_POOL, GlobalV::MY_RANK,
651-
PARAM.inp.nbands, PARAM.inp.nspin, PARAM.globalv.npol,
652-
GlobalV::RANK_IN_POOL, GlobalV::NPROC_IN_POOL,
653-
PARAM.inp.out_wfc_pw, PARAM.inp.ecutwfc, PARAM.globalv.global_out_dir,
654-
this->psi[0], this->kv, this->pw_wfc, GlobalV::ofs_running);
655-
}
648+
if (iter % PARAM.inp.out_freq_elec == 0 || iter == PARAM.inp.scf_nmax || conv_esolver)
649+
{
650+
ModuleIO::write_wfc_pw(GlobalV::KPAR,
651+
GlobalV::MY_POOL,
652+
GlobalV::MY_RANK,
653+
PARAM.inp.nbands,
654+
PARAM.inp.nspin,
655+
PARAM.globalv.npol,
656+
GlobalV::RANK_IN_POOL,
657+
GlobalV::NPROC_IN_POOL,
658+
PARAM.inp.out_wfc_pw,
659+
PARAM.inp.ecutwfc,
660+
PARAM.globalv.global_out_dir,
661+
this->psi[0],
662+
this->kv,
663+
this->pw_wfc,
664+
GlobalV::ofs_running);
665+
}
656666

657667
//----------------------------------------------------------
658668
// 4) check if oscillate for delta_spin method
@@ -718,11 +728,6 @@ void ESolver_KS_PW<T, Device>::after_scf(UnitCell& ucell, const int istep, const
718728
this->pw_rhod->ny,
719729
this->pw_rhod->nz,
720730
this->pw_rhod->nxyz,
721-
this->kv.get_nks(),
722-
this->kv.isk,
723-
this->kv.wk,
724-
this->pw_big->bz,
725-
this->pw_big->nbz,
726731
this->chr.ngmc,
727732
&ucell,
728733
this->psi,
@@ -731,16 +736,29 @@ void ESolver_KS_PW<T, Device>::after_scf(UnitCell& ucell, const int istep, const
731736
this->ctx,
732737
this->Pgrid,
733738
PARAM.globalv.global_out_dir,
734-
PARAM.inp.if_separate_k);
739+
PARAM.inp.if_separate_k,
740+
this->kv,
741+
GlobalV::KPAR,
742+
GlobalV::MY_POOL,
743+
&this->chr);
735744
}
736745

737-
738-
// tmp 2025-05-17, mohan note
739-
ModuleIO::write_wfc_pw(GlobalV::KPAR, GlobalV::MY_POOL, GlobalV::MY_RANK,
740-
PARAM.inp.nbands, PARAM.inp.nspin, PARAM.globalv.npol,
741-
GlobalV::RANK_IN_POOL, GlobalV::NPROC_IN_POOL,
742-
PARAM.inp.out_wfc_pw, PARAM.inp.ecutwfc, PARAM.globalv.global_out_dir,
743-
this->psi[0], this->kv, this->pw_wfc, GlobalV::ofs_running);
746+
// tmp 2025-05-17, mohan note
747+
ModuleIO::write_wfc_pw(GlobalV::KPAR,
748+
GlobalV::MY_POOL,
749+
GlobalV::MY_RANK,
750+
PARAM.inp.nbands,
751+
PARAM.inp.nspin,
752+
PARAM.globalv.npol,
753+
GlobalV::RANK_IN_POOL,
754+
GlobalV::NPROC_IN_POOL,
755+
PARAM.inp.out_wfc_pw,
756+
PARAM.inp.ecutwfc,
757+
PARAM.globalv.global_out_dir,
758+
this->psi[0],
759+
this->kv,
760+
this->pw_wfc,
761+
GlobalV::ofs_running);
744762

745763
//------------------------------------------------------------------
746764
//! 5) calculate Wannier functions in pw basis
@@ -931,7 +949,7 @@ void ESolver_KS_PW<T, Device>::after_all_runners(UnitCell& ucell)
931949
//----------------------------------------------------------
932950

933951
//----------------------------------------------------------
934-
//! The write_psi_r_1 interface will be removed in the very
952+
//! The write_psi_r_1 interface will be removed in the very
935953
//! near future. Don't use it!
936954
//----------------------------------------------------------
937955
// if (PARAM.inp.out_wfc_r == 1) // Peize Lin add 2021.11.21
@@ -951,19 +969,15 @@ void ESolver_KS_PW<T, Device>::after_all_runners(UnitCell& ucell)
951969
this->pw_rhod->ny,
952970
this->pw_rhod->nz,
953971
this->pw_rhod->nxyz,
954-
this->kv.get_nks(),
955-
this->kv.isk,
956-
this->kv.wk,
957-
this->pw_big->bz,
958-
this->pw_big->nbz,
959-
this->chr.ngmc,
960972
&ucell,
961973
this->psi,
962-
this->pw_rhod,
963974
this->pw_wfc,
964975
this->ctx,
965976
this->Pgrid,
966-
PARAM.globalv.global_out_dir);
977+
PARAM.globalv.global_out_dir,
978+
this->kv,
979+
GlobalV::KPAR,
980+
GlobalV::MY_POOL);
967981
}
968982

969983
//----------------------------------------------------------

source/module_esolver/esolver_of.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,8 +164,12 @@ void ESolver_OF::runner(UnitCell& ucell, const int istep)
164164
if (PARAM.inp.of_ml_local_test) this->ml_->localTest(this->chr.rho, this->pw_rho);
165165
#endif
166166

167-
168167
bool conv_esolver = false; // this conv_esolver is added by mohan 20250302
168+
#ifdef __MPI
169+
this->iter_time = MPI_Wtime();
170+
#else
171+
this->iter_time = std::chrono::system_clock::now();
172+
#endif
169173

170174
while (true)
171175
{

source/module_esolver/esolver_of_tool.cpp

Lines changed: 29 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -390,38 +390,32 @@ void ESolver_OF::print_info(const bool conv_esolver)
390390
{
391391
if (this->iter_ == 0)
392392
{
393-
std::cout << "============================== Running OFDFT "
393+
std::cout << " ============================= Running OFDFT "
394394
"=============================="
395395
<< std::endl;
396-
std::cout << "Iter Etot(Ha) Mu(Ha) Theta "
397-
"PotNorm deltaE(Ha)"
396+
std::cout << " ITER ETOT/eV EDIFF/eV EFERMI/eV POTNORM TIME/s"
398397
<< std::endl;
399-
// cout << "======================================== Running OFDFT
400-
// ========================================" << endl; cout << "Iter
401-
// Etot(Ha) Theta PotNorm min/max(den)
402-
// min/max(dE/dPhi)" << endl;
403398
}
404-
// ============ used to compare with PROFESS3.0 ================
405-
// double minDen = this->chr.rho[0][0];
406-
// double maxDen = this->chr.rho[0][0];
407-
// double minPot = this->pdEdphi_[0][0];
408-
// double maxPot = this->pdEdphi_[0][0];
409-
// for (int i = 0; i < this->pw_rho->nrxx; ++i)
410-
// {
411-
// if (this->chr.rho[0][i] < minDen) minDen =
412-
// this->chr.rho[0][i]; if (this->chr.rho[0][i] > maxDen)
413-
// maxDen = this->chr.rho[0][i]; if (this->pdEdphi_[0][i] < minPot)
414-
// minPot = this->pdEdphi_[0][i]; if (this->pdEdphi_[0][i] > maxPot)
415-
// maxPot = this->pdEdphi_[0][i];
416-
// }
417-
std::cout << std::setw(6) << this->iter_ << std::setw(22) << std::scientific << std::setprecision(12)
418-
<< this->energy_current_ / 2. << std::setw(12) << std::setprecision(3) << this->pelec->eferm.get_efval(0) / 2.
419-
<< std::setw(12) << this->theta_[0] << std::setw(12) << this->normdLdphi_ << std::setw(12)
420-
<< (this->energy_current_ - this->energy_last_) / 2. << std::endl;
421-
// ============ used to compare with PROFESS3.0 ================
422-
// << setw(10) << minDen << "/ " << setw(12) << maxDen
423-
// << setw(10) << minPot << "/ " << setw(10) << maxPot << endl;
424-
// =============================================================
399+
400+
std::map<std::string, std::string> prefix_map = {
401+
{"cg1", "CG"},
402+
{"cg2", "CG"},
403+
{"tn", "TN"}
404+
};
405+
std::string iteration = prefix_map[PARAM.inp.of_method] + std::to_string(this->iter_);
406+
#ifdef __MPI
407+
double duration = (double)(MPI_Wtime() - this->iter_time);
408+
#else
409+
double duration
410+
= (std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::system_clock::now() - this->iter_time)).count()
411+
/ static_cast<double>(1e6);
412+
#endif
413+
std::cout << " " << std::setw(8) << iteration
414+
<< std::setw(18) << std::scientific << std::setprecision(8) << this->energy_current_ * ModuleBase::Ry_to_eV
415+
<< std::setw(18) << (this->energy_current_ - this->energy_last_) * ModuleBase::Ry_to_eV
416+
<< std::setw(13) << std::setprecision(4) << this->pelec->eferm.get_efval(0) * ModuleBase::Ry_to_eV
417+
<< std::setw(13) << std::setprecision(4) << this->normdLdphi_
418+
<< std::setw(6) << std::fixed << std::setprecision(2) << duration << std::endl;
425419

426420
GlobalV::ofs_running << std::setprecision(12);
427421
GlobalV::ofs_running << std::setiosflags(std::ios::right);
@@ -533,5 +527,12 @@ void ESolver_OF::print_info(const bool conv_esolver)
533527
/*formats=*/{"%20s", "%20.12f", "%20.12f"}, 0);
534528
table << titles << energies_Ry << energies_eV;
535529
GlobalV::ofs_running << table.str() << std::endl;
530+
531+
// reset the iter_time for the next iteration
532+
#ifdef __MPI
533+
this->iter_time = MPI_Wtime();
534+
#else
535+
this->iter_time = std::chrono::system_clock::now();
536+
#endif
536537
}
537538
} // namespace ModuleESolver

0 commit comments

Comments
 (0)