Skip to content

Commit e26d42a

Browse files
author
dyzheng
committed
Refactor: Replace magic number and C-style cast in sto_wf.cpp
1 parent 2f59a6f commit e26d42a

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

source/source_pw/module_stodft/sto_wf.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,13 +66,15 @@ void Stochastic_WF<T, Device>::clean_chiallorder()
6666
template <typename T, typename Device>
6767
void Stochastic_WF<T, Device>::init_sto_orbitals(const int seed_in)
6868
{
69+
const unsigned int RANK_SEED_FACTOR = 10000; // 用于区分不同进程/组的随机种子偏移量
70+
6971
if (seed_in == 0 || seed_in == -1)
7072
{
71-
srand((unsigned)time(nullptr) + GlobalV::MY_RANK * 10000); // GlobalV global variables are reserved
73+
srand(static_cast<unsigned>(time(nullptr)) + GlobalV::MY_RANK * RANK_SEED_FACTOR);
7274
}
7375
else
7476
{
75-
srand((unsigned)std::abs(seed_in) + (GlobalV::MY_BNDGROUP * GlobalV::NPROC_IN_BNDGROUP + GlobalV::RANK_IN_BPGROUP) * 10000);
77+
srand(static_cast<unsigned>(std::abs(seed_in)) + (GlobalV::MY_BNDGROUP * GlobalV::NPROC_IN_BNDGROUP + GlobalV::RANK_IN_BPGROUP) * RANK_SEED_FACTOR);
7678
}
7779

7880
this->allocate_chi0();

0 commit comments

Comments
 (0)