@@ -437,7 +437,7 @@ void ESolver_KS<T, Device>::runner(UnitCell& ucell, const int istep)
437437 ModuleBase::GlobalFunc::DONE (GlobalV::ofs_running, " INIT SCF" );
438438
439439 // 4) SCF iterations
440- this -> conv_esolver = false ;
440+ bool conv_esolver = false ;
441441 this ->niter = this ->maxniter ;
442442 this ->diag_ethr = PARAM.inp .pw_diag_thr ;
443443 for (int iter = 1 ; iter <= this ->maxniter ; ++iter)
@@ -449,10 +449,10 @@ void ESolver_KS<T, Device>::runner(UnitCell& ucell, const int istep)
449449 this ->hamilt2density (ucell, istep, iter, diag_ethr);
450450
451451 // 7) finish scf iterations
452- this ->iter_finish (ucell, istep, iter);
452+ this ->iter_finish (ucell, istep, iter, conv_esolver );
453453
454454 // 8) check convergence
455- if (this -> conv_esolver || this ->oscillate_esolver )
455+ if (conv_esolver || this ->oscillate_esolver )
456456 {
457457 this ->niter = iter;
458458 if (this ->oscillate_esolver )
@@ -464,7 +464,7 @@ void ESolver_KS<T, Device>::runner(UnitCell& ucell, const int istep)
464464 } // end scf iterations
465465
466466 // 9) after scf
467- this ->after_scf (ucell, istep);
467+ this ->after_scf (ucell, istep, conv_esolver );
468468
469469 ModuleBase::timer::tick (this ->classname , " runner" );
470470 return ;
@@ -524,7 +524,7 @@ void ESolver_KS<T, Device>::iter_init(UnitCell& ucell, const int istep, const in
524524}
525525
526526template <typename T, typename Device>
527- void ESolver_KS<T, Device>::iter_finish(UnitCell& ucell, const int istep, int & iter)
527+ void ESolver_KS<T, Device>::iter_finish(UnitCell& ucell, const int istep, int & iter, bool &conv_esolver )
528528{
529529 if (PARAM.inp .out_bandgap )
530530 {
@@ -578,30 +578,30 @@ void ESolver_KS<T, Device>::iter_finish(UnitCell& ucell, const int istep, int& i
578578 }
579579#endif
580580
581- this -> conv_esolver = (drho < this ->scf_thr && not_restart_step && is_U_converged);
581+ conv_esolver = (drho < this ->scf_thr && not_restart_step && is_U_converged);
582582
583583 // add energy threshold for SCF convergence
584584 if (this ->scf_ene_thr > 0.0 )
585585 {
586586 // calculate energy of output charge density
587- this ->update_pot (ucell, istep, iter);
587+ this ->update_pot (ucell, istep, iter, conv_esolver );
588588 this ->pelec ->cal_energies (2 ); // 2 means Kohn-Sham functional
589589 // now, etot_old is the energy of input density, while etot is the energy of output density
590590 this ->pelec ->f_en .etot_delta = this ->pelec ->f_en .etot - this ->pelec ->f_en .etot_old ;
591591 // output etot_delta
592592 GlobalV::ofs_running << " DeltaE_womix = " << this ->pelec ->f_en .etot_delta * ModuleBase::Ry_to_eV << " eV"
593593 << std::endl;
594- if (iter > 1 && this -> conv_esolver == 1 ) // only check when density is converged
594+ if (iter > 1 && conv_esolver == 1 ) // only check when density is converged
595595 {
596596 // update the convergence flag
597- this -> conv_esolver
597+ conv_esolver
598598 = (std::abs (this ->pelec ->f_en .etot_delta * ModuleBase::Ry_to_eV) < this ->scf_ene_thr );
599599 }
600600 }
601601
602602 // If drho < hsolver_error in the first iter or drho < scf_thr, we
603603 // do not change rho.
604- if (drho < hsolver_error || this -> conv_esolver || PARAM.inp .calculation == " nscf" )
604+ if (drho < hsolver_error || conv_esolver || PARAM.inp .calculation == " nscf" )
605605 {
606606 if (drho < hsolver_error)
607607 {
@@ -635,14 +635,16 @@ void ESolver_KS<T, Device>::iter_finish(UnitCell& ucell, const int istep, int& i
635635
636636#ifdef __MPI
637637 MPI_Bcast (&drho, 1 , MPI_DOUBLE, 0 , BP_WORLD);
638- MPI_Bcast (&this ->conv_esolver , 1 , MPI_DOUBLE, 0 , BP_WORLD);
638+
639+ // be careful! conv_esolver is bool, not double !! Maybe a bug 20250302 by mohan
640+ MPI_Bcast (&conv_esolver, 1 , MPI_DOUBLE, 0 , BP_WORLD);
639641 MPI_Bcast (pelec->charge ->rho [0 ], this ->pw_rhod ->nrxx , MPI_DOUBLE, 0 , BP_WORLD);
640642#endif
641643
642644 // update potential
643645 // Hamilt should be used after it is constructed.
644646 // this->phamilt->update(conv_esolver);
645- this ->update_pot (ucell, istep, iter);
647+ this ->update_pot (ucell, istep, iter, conv_esolver );
646648
647649 // 1 means Harris-Foulkes functional
648650 // 2 means Kohn-Sham functional
@@ -671,7 +673,7 @@ void ESolver_KS<T, Device>::iter_finish(UnitCell& ucell, const int istep, int& i
671673 dkin = p_chgmix->get_dkin (pelec->charge , PARAM.inp .nelec );
672674 }
673675
674- this ->pelec ->print_etot (ucell.magnet ,this -> conv_esolver , iter, drho, dkin, duration, PARAM.inp .printe , diag_ethr);
676+ this ->pelec ->print_etot (ucell.magnet ,conv_esolver, iter, drho, dkin, duration, PARAM.inp .printe , diag_ethr);
675677
676678 // Json, need to be moved to somewhere else
677679#ifdef __RAPIDJSON
@@ -691,17 +693,17 @@ void ESolver_KS<T, Device>::iter_finish(UnitCell& ucell, const int istep, int& i
691693 std::cout << " SCF restart after this step!" << std::endl;
692694 }
693695
694- ESolver_FP::iter_finish (ucell, istep, iter);
696+ ESolver_FP::iter_finish (ucell, istep, iter, conv_esolver );
695697}
696698
697699// ! Something to do after SCF iterations when SCF is converged or comes to the max iter step.
698700template <typename T, typename Device>
699- void ESolver_KS<T, Device>::after_scf(UnitCell& ucell, const int istep)
701+ void ESolver_KS<T, Device>::after_scf(UnitCell& ucell, const int istep, const bool conv_esolver )
700702{
701703 ModuleBase::TITLE (" ESolver_KS" , " after_scf" );
702704
703705 // 1) call after_scf() of ESolver_FP
704- ESolver_FP::after_scf (ucell, istep);
706+ ESolver_FP::after_scf (ucell, istep, conv_esolver );
705707
706708 // 2) write eigenvalues
707709 if (istep % PARAM.inp .out_interval == 0 )
0 commit comments