Skip to content

Commit 59483e3

Browse files
authored
Refactor: Standardize OFDFT screen output to match KSDFT format (#6249)
* Refactor: Standardize OFDFT screen output to match KSDFT format * Fix: Fix the compile error
1 parent 6c460fd commit 59483e3

File tree

4 files changed

+44
-42
lines changed

4 files changed

+44
-42
lines changed

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_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)