@@ -721,7 +721,9 @@ void ESolver_KS_LCAO<TK, TR>::iter_finish(UnitCell& ucell, const int istep, int&
721721 // Fallback: if inner loop is inactive (nscf==0), use gradient descent
722722 deltap_update_lambda (ucell, iter);
723723
724- // Print status with phase indicator
724+ // Print status with phase indicator (rank 0 only)
725+ if (GlobalV::MY_RANK == 0 )
726+ {
725727 auto * dp = static_cast <deltap::DeltaP*>(dp_scf_);
726728 // Diagnostic: raw gamma (pre-branch) for Born effective charge
727729 {
@@ -803,6 +805,7 @@ void ESolver_KS_LCAO<TK, TR>::iter_finish(UnitCell& ucell, const int istep, int&
803805 double E_eff_V_per_A = E_eff_au * 51.422 ; // V/Å
804806 std::cout << " [E-field] E_eff=" << std::scientific << std::setprecision (3 )
805807 << E_eff_V_per_A << " V/Angstrom (λ_avg=" << lam_avg << " Ry)" << std::endl;
808+ } // rank 0 scope
806809 }
807810 else
808811 {
@@ -954,6 +957,7 @@ void ESolver_KS_LCAO<TK, TR>::deltap_init(UnitCell& ucell)
954957 ifs >> total_target;
955958 for (int iat = 0 ; iat < ucell.nat ; ++iat)
956959 deltap_target_[iat] = total_target / ucell.nat ;
960+ if (GlobalV::MY_RANK == 0 )
957961 std::cout << " [DeltaP] Loaded total target Σγ=" << total_target
958962 << " → per-atom=" << total_target / ucell.nat << std::endl;
959963 }
@@ -962,6 +966,7 @@ void ESolver_KS_LCAO<TK, TR>::deltap_init(UnitCell& ucell)
962966 deltap_target_.assign (ucell.nat , 0.0 );
963967 for (int iat = 0 ; iat < ucell.nat ; ++iat)
964968 ifs >> deltap_target_[iat];
969+ if (GlobalV::MY_RANK == 0 )
965970 std::cout << " [DeltaP] Loaded target from " << PARAM .inp .deltap_target_file << std::endl;
966971 }
967972 }
@@ -976,9 +981,11 @@ void ESolver_KS_LCAO<TK, TR>::deltap_init(UnitCell& ucell)
976981 if (deltap_constrain_[iat] != 0 && deltap_target_[iat] != 0.0 )
977982 has_any_target = true ;
978983 if (has_any_target)
979- std::cout << " [DeltaP] Loaded targets from STRU (dp_target/dp_constrain)" << std::endl;
984+ if (GlobalV::MY_RANK == 0 )
985+ std::cout << " [DeltaP] Loaded targets from STRU (dp_target/dp_constrain)" << std::endl;
980986 else
981- std::cout << " [DeltaP] No targets specified; γ measured without constraint" << std::endl;
987+ if (GlobalV::MY_RANK == 0 )
988+ std::cout << " [DeltaP] No targets specified; γ measured without constraint" << std::endl;
982989 }
983990 // When no target is specified, leave deltap_target_ empty.
984991 // This allows ground-state γ determination without target-aware
@@ -1008,7 +1015,8 @@ void ESolver_KS_LCAO<TK, TR>::deltap_init(UnitCell& ucell)
10081015 deltap_constraint_lambda_.assign (m, PARAM .inp .deltap_lambda_init );
10091016 static_cast <deltap::DeltaP*>(dp_scf_)->set_constraint_matrix (
10101017 deltap_constraint_matrix_, deltap_constraint_target_);
1011- std::cout << " [DeltaP] Loaded constraint matrix " << m << " x" << n
1018+ if (GlobalV::MY_RANK == 0 )
1019+ std::cout << " [DeltaP] Loaded constraint matrix " << m << " x" << n
10121020 << " from " << PARAM .inp .deltap_constraint_matrix << std::endl;
10131021 }
10141022 else
@@ -1132,7 +1140,8 @@ void ESolver_KS_LCAO<TK, TR>::deltap_inner_loop(UnitCell& ucell, const int iter,
11321140
11331141 hsolver::HSolverLCAO<TK > hsolver_lcao_obj (&(this ->pv ), PARAM .inp .ks_solver );
11341142
1135- std::cout << " [DeltaP] inner loop start: nscf=" << nscf
1143+ if (GlobalV::MY_RANK == 0 )
1144+ std::cout << " [DeltaP] inner loop start: nscf=" << nscf
11361145 << " rms=" << std::scientific << std::setprecision (4 )
11371146 << bfgs.get_rms () << std::endl;
11381147
@@ -1189,7 +1198,8 @@ void ESolver_KS_LCAO<TK, TR>::deltap_inner_loop(UnitCell& ucell, const int iter,
11891198 double alpha_opt = bfgs.accept_trial (residual);
11901199 lambda_inner = lam_trial;
11911200
1192- std::cout << " [DeltaP] inner=" << inner
1201+ if (GlobalV::MY_RANK == 0 )
1202+ std::cout << " [DeltaP] inner=" << inner
11931203 << " rms=" << std::scientific << std::setprecision (4 )
11941204 << bfgs.get_rms () << " alpha_opt=" << alpha_opt << std::endl;
11951205 }
@@ -1214,10 +1224,13 @@ void ESolver_KS_LCAO<TK, TR>::deltap_inner_loop(UnitCell& ucell, const int iter,
12141224 dp_op->set_hk_correction (hk_corr_final);
12151225 skip_solve = true ; // inner loop already solved
12161226
1217- std::cout << " [DeltaP] inner loop done: final" ;
1218- for (int iat = 0 ; iat < ucell.nat ; ++iat)
1219- std::cout << " l" << iat << " =" << lam_final[iat];
1220- std::cout << std::endl;
1227+ if (GlobalV::MY_RANK == 0 )
1228+ {
1229+ std::cout << " [DeltaP] inner loop done: final" ;
1230+ for (int iat = 0 ; iat < ucell.nat ; ++iat)
1231+ std::cout << " l" << iat << " =" << lam_final[iat];
1232+ std::cout << std::endl;
1233+ }
12211234 deltap_inner_loop_done_ = true ;
12221235 }
12231236}
@@ -1364,6 +1377,19 @@ void ESolver_KS_LCAO<TK, TR>::deltap_update_lambda(UnitCell& ucell, const int it
13641377 }
13651378
13661379 dp_op->set_lambda (lambda);
1380+
1381+ // MPI: broadcast lambda to ensure consistency across ranks
1382+ // (gamma is synced in compute_gamma_scf; lambda must be too)
1383+ #ifdef __MPI
1384+ if (this ->pv .comm () != MPI_COMM_NULL )
1385+ {
1386+ int nproc = 1 ;
1387+ MPI_Comm_size (this ->pv .comm (), &nproc);
1388+ if (nproc > 1 )
1389+ MPI_Bcast (lambda.data (), ucell.nat , MPI_DOUBLE , 0 , this ->pv .comm ());
1390+ }
1391+ #endif
1392+
13671393 dp->start_cooldown (1 );
13681394
13691395 // Reset charge mixing history: Broyden's approximate Jacobian
@@ -1374,9 +1400,10 @@ void ESolver_KS_LCAO<TK, TR>::deltap_update_lambda(UnitCell& ucell, const int it
13741400 this ->p_chgmix ->mix_reset ();
13751401
13761402 // Phase 2 transition: print summary
1377- std::cout << " [DeltaP P2] iter=" << iter << " drho=" << std::scientific
1378- << std::setprecision (2 ) << this ->drho << " < " << PARAM .inp .deltap_inner_thr
1379- << " → λ updated, mix_reset()\n " ;
1403+ if (GlobalV::MY_RANK == 0 )
1404+ std::cout << " [DeltaP P2] iter=" << iter << " drho=" << std::scientific
1405+ << std::setprecision (2 ) << this ->drho << " < " << PARAM .inp .deltap_inner_thr
1406+ << " → λ updated, mix_reset()\n " ;
13801407 }
13811408
13821409 // Always recompute HK correction with latest wavefunctions
0 commit comments