Skip to content

Commit 72b04c0

Browse files
author
abacus_fixer
committed
refactor(klist): pass my_rank/my_pool into mpi_k
Remove the GlobalV::MY_RANK/MY_POOL dependency from K_Vectors::mpi_k by taking them as parameters; the single caller (set()) passes the GlobalV values. Private signature only, no public interface change. global_dependency count in klist.cpp drops by 5. Verified: cmake --build build_max_para_test -j30 (exit 0, __MPI on) and ctest -R "MODULE_CELL_(klist|reciprocal_grid|qlist)" -> 5/5.
1 parent 919c560 commit 72b04c0

2 files changed

Lines changed: 8 additions & 8 deletions

File tree

source/source_cell/klist.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ void K_Vectors::set(const UnitCell& ucell,
174174
nspin_in); // assign k points to several process pools
175175
#ifdef __MPI
176176
// distribute K point data to the corresponding process
177-
this->mpi_k(ofs);
177+
this->mpi_k(ofs, GlobalV::MY_RANK, GlobalV::MY_POOL);
178178
#endif
179179

180180
// set the k vectors for the up and down spin
@@ -681,7 +681,7 @@ void K_Vectors::set_after_vc(const ModuleBase::Matrix3& G, std::ofstream& ofs_ru
681681
}
682682

683683
#ifdef __MPI
684-
void K_Vectors::mpi_k(std::ofstream& ofs_running)
684+
void K_Vectors::mpi_k(std::ofstream& ofs_running, const int my_rank, const int my_pool)
685685
{
686686
ModuleBase::TITLE("K_Vectors", "mpi_k");
687687

@@ -702,7 +702,7 @@ void K_Vectors::mpi_k(std::ofstream& ofs_running)
702702

703703
Parallel_Common::bcast_double(this->koffset, 3);
704704

705-
this->nks = this->para_k.nks_pool[GlobalV::MY_POOL];
705+
this->nks = this->para_k.nks_pool[my_pool];
706706

707707
ofs_running << std::endl;
708708
ModuleBase::GlobalFunc::OUT(ofs_running, "Number of k-points in this process", this->nks);
@@ -726,7 +726,7 @@ void K_Vectors::mpi_k(std::ofstream& ofs_running)
726726
std::vector<double> kvec_c_full_aux(this->nkstot_full * 3);
727727

728728
// collect and process in rank 0
729-
if (GlobalV::MY_RANK == 0)
729+
if (my_rank == 0)
730730
{
731731
KListIO::pack_kpts(this->isk,
732732
this->wk,
@@ -759,7 +759,7 @@ void K_Vectors::mpi_k(std::ofstream& ofs_running)
759759
kvec_d_aux,
760760
kvec_c_full_aux,
761761
this->nks,
762-
this->para_k.startk_pool[GlobalV::MY_POOL],
762+
this->para_k.startk_pool[my_pool],
763763
this->isk,
764764
this->wk,
765765
this->kvec_c,
@@ -779,7 +779,7 @@ void K_Vectors::mpi_k(std::ofstream& ofs_running)
779779
{
780780
int isym = 0;
781781
ModuleBase::Vector3<double> ks_vec(0, 0, 0);
782-
if (GlobalV::MY_RANK == 0)
782+
if (my_rank == 0)
783783
{
784784
isym = ks->first;
785785
ks_vec = ks->second;
@@ -789,7 +789,7 @@ void K_Vectors::mpi_k(std::ofstream& ofs_running)
789789
Parallel_Common::bcast_double(ks_vec.x);
790790
Parallel_Common::bcast_double(ks_vec.y);
791791
Parallel_Common::bcast_double(ks_vec.z);
792-
if (GlobalV::MY_RANK != 0)
792+
if (my_rank != 0)
793793
{
794794
this->kstars[ikibz].insert(std::make_pair(isym, ks_vec));
795795
}

source/source_cell/klist.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,7 @@ class K_Vectors : public ModuleCell::ReciprocalGrid
336336
* @note Assumes nkstot > 0 and quits if some process ends up with
337337
* no k-points.
338338
*/
339-
void mpi_k(std::ofstream& ofs_running);
339+
void mpi_k(std::ofstream& ofs_running, const int my_rank, const int my_pool);
340340
#endif
341341
};
342342
#endif // KVECT_H

0 commit comments

Comments
 (0)