Skip to content

Commit 860b6e6

Browse files
authored
Fix: a mpi bug in DeePKS. (#7485)
* Fix a mpi bug in DeePKS. * Fix the mpi bug and update the reference value in tests. * Update DeePKS UT.
1 parent 93454a3 commit 860b6e6

6 files changed

Lines changed: 13 additions & 3 deletions

File tree

source/source_lcao/module_deepks/LCAO_deepks_interface.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -629,7 +629,7 @@ void LCAO_Deepks_Interface<TK, TR>::out_deepks_labels(const double& etot,
629629
int R_size = DeePKS_domain::get_R_size(*h_deltaR);
630630
torch::Tensor overlap_out;
631631
torch::Tensor iRmat;
632-
DeePKS_domain::prepare_phialpha_iRmat(nlocal, R_size, deepks_param, phialpha, ucell, orb, GridD, overlap_out, iRmat);
632+
DeePKS_domain::prepare_phialpha_iRmat(nlocal, R_size, deepks_param, phialpha, ucell, orb, *ParaV, GridD, overlap_out, iRmat);
633633
const std::string file_overlap = PARAM.globalv.global_out_dir + "deepks_phialpha_r.npy";
634634
LCAO_deepks_io::save_tensor2npy<double>(file_overlap, overlap_out, rank);
635635
const std::string file_iRmat = PARAM.globalv.global_out_dir + "deepks_iRmat.npy";

source/source_lcao/module_deepks/deepks_vdrpre.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ void DeePKS_domain::prepare_phialpha_iRmat(const int nlocal,
1919
const std::vector<hamilt::HContainer<double>*> phialpha,
2020
const UnitCell& ucell,
2121
const LCAO_Orbitals& orb,
22+
const Parallel_Orbitals& pv,
2223
const Grid_Driver& GridD,
2324
torch::Tensor& overlap,
2425
torch::Tensor& iRmat)
@@ -81,6 +82,10 @@ void DeePKS_domain::prepare_phialpha_iRmat(const int nlocal,
8182

8283
for (int ix = 0; ix < nw_tot; ix++)
8384
{
85+
if (pv.global2local_row(start + ix) < 0 || pv.global2local_col(start + ix) < 0)
86+
{
87+
continue;
88+
}
8489
for (int iy = 0; iy < deepks_param.des_per_atom; iy++)
8590
{
8691
overlap_accessor[iat][nnmax_vec[iat]][start + ix][iy] = overlap_mat->get_value(ix, iy);
@@ -89,6 +94,9 @@ void DeePKS_domain::prepare_phialpha_iRmat(const int nlocal,
8994
nnmax_vec[iat]++;
9095
}
9196
);
97+
#ifdef __MPI
98+
Parallel_Reduce::reduce_all(overlap.data_ptr<double>(), overlap.numel());
99+
#endif
92100
iRmat = mapping_R(dRmat_tmp.unsqueeze(1) - dRmat_tmp.unsqueeze(2));
93101
ModuleBase::timer::end("DeePKS_domain", "prepare_phialpha_iRmat");
94102
return;

source/source_lcao/module_deepks/deepks_vdrpre.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ void prepare_phialpha_iRmat(const int nlocal,
3535
const std::vector<hamilt::HContainer<double>*> phialpha,
3636
const UnitCell& ucell,
3737
const LCAO_Orbitals& orb,
38+
const Parallel_Orbitals& pv,
3839
const Grid_Driver& GridD,
3940
torch::Tensor& overlap,
4041
torch::Tensor& iRmat);

source/source_lcao/module_deepks/test/LCAO_deepks_test.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,7 @@ void test_deepks<T>::check_vdrpre()
308308
this->ld.phialpha,
309309
ucell,
310310
ORB,
311+
ParaO,
311312
Test_Deepks::GridD,
312313
overlap_out,
313314
iRmat);

tests/09_DeePKS/22_NO_GO_deepks_vdelta_r_2/result.ref

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@ deepks_e_label 17.126764505645642
66
deepks_edelta 0.09815855485768665
77
deepks_hr_label_pass 0
88
deepks_vdelta_r_pass 0
9-
deepks_phialpha_r 40.10770566607966
9+
deepks_phialpha_r 73.40481582340394
1010
deepks_gevdm 54.0
1111
totaltimeref 1.81

tests/09_DeePKS/24_NO_KP_deepks_vdelta_r_2/result.ref

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@ deepks_e_label 17.12676450564565
66
deepks_edelta 0.09815855485768665
77
deepks_hr_label_pass 0
88
deepks_vdelta_r_pass 0
9-
deepks_phialpha_r 40.10770566607966
9+
deepks_phialpha_r 73.40481582340394
1010
deepks_gevdm 54.0
1111
totaltimeref 1.81

0 commit comments

Comments
 (0)