From 91d0616819d5ac8f841dc1e3cd21cb77366b95e3 Mon Sep 17 00:00:00 2001 From: tyd <3307915720@qq.com> Date: Tue, 17 Mar 2026 22:14:03 -0700 Subject: [PATCH] =?UTF-8?q?2026PKUCourseHW5:=E6=A1=88=E4=BE=8B=E4=B8=80?= =?UTF-8?q?=E5=B0=86=E9=AD=94=E6=95=B010000=E5=AE=9A=E4=B9=89=E4=B8=BA?= =?UTF-8?q?=E5=91=BD=E5=90=8D=E5=B8=B8=E9=87=8FRANK=5FSEED=5FOFFSET-=20?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=B3=A8=E9=87=8A=E8=AF=B4=E6=98=8E=E5=B8=B8?= =?UTF-8?q?=E9=87=8F=E7=9A=84=E7=94=A8=E9=80=94-=20=E5=B0=86C=E9=A3=8E?= =?UTF-8?q?=E6=A0=BC=E5=BC=BA=E5=88=B6=E8=BD=AC=E6=8D=A2(unsigned)?= =?UTF-8?q?=E6=9B=BF=E6=8D=A2=E4=B8=BAstatic=5Fcast-=20=E6=8F=90?= =?UTF-8?q?=E9=AB=98=E4=BB=A3=E7=A0=81=E5=8F=AF=E8=AF=BB=E6=80=A7=E5=92=8C?= =?UTF-8?q?=E5=AE=89=E5=85=A8=E6=80=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/source_pw/module_stodft/sto_wf.cpp | 10 +++++----- source/source_pw/module_stodft/sto_wf.h | 6 +++++- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/source/source_pw/module_stodft/sto_wf.cpp b/source/source_pw/module_stodft/sto_wf.cpp index e844503a11..d2e9c5113d 100644 --- a/source/source_pw/module_stodft/sto_wf.cpp +++ b/source/source_pw/module_stodft/sto_wf.cpp @@ -68,11 +68,13 @@ void Stochastic_WF::init_sto_orbitals(const int seed_in) { if (seed_in == 0 || seed_in == -1) { - srand((unsigned)time(nullptr) + GlobalV::MY_RANK * 10000); // GlobalV global variables are reserved + srand(static_cast(time(nullptr)) + + GlobalV::MY_RANK * GlobalConst::RANDOM_SEED_OFFSET); // GlobalV global variables are reserved } else { - srand((unsigned)std::abs(seed_in) + (GlobalV::MY_BNDGROUP * GlobalV::NPROC_IN_BNDGROUP + GlobalV::RANK_IN_BPGROUP) * 10000); + srand((unsigned)std::abs(seed_in) + + (GlobalV::MY_BNDGROUP * GlobalV::NPROC_IN_BNDGROUP + GlobalV::RANK_IN_BPGROUP) * 10000); } this->allocate_chi0(); @@ -374,9 +376,7 @@ void Stochastic_WF::sync_chi0() Device* ctx = {}; if (base_device::get_device_type(ctx) == base_device::GpuDevice) { - syncmem_h2d_op()(this->chi0->get_pointer(), - this->chi0_cpu->get_pointer(), - this->chi0_cpu->size()); + syncmem_h2d_op()(this->chi0->get_pointer(), this->chi0_cpu->get_pointer(), this->chi0_cpu->size()); } } diff --git a/source/source_pw/module_stodft/sto_wf.h b/source/source_pw/module_stodft/sto_wf.h index 5146ff7f56..db5e0f2558 100644 --- a/source/source_pw/module_stodft/sto_wf.h +++ b/source/source_pw/module_stodft/sto_wf.h @@ -9,6 +9,10 @@ // Generate stochastic wave functions //---------------------------------------------- template +namespace GlobalConst +{ + constexpr int RANDOM_SEED_OFFSET = 10000; +} class Stochastic_WF { public: @@ -33,7 +37,7 @@ class Stochastic_WF int npwx = 0; ///< max ngk[ik] in all processors int nbands_diag = 0; ///< number of bands obtained from diagonalization int nbands_total = 0; ///< number of bands in total, nbands_total=nchi+nbands_diag; - std::vector ngk; ///< ngk in klist + std::vector ngk; ///< ngk in klist public: // Tn(H)|chi> psi::Psi* chiallorder = nullptr;