From a1151552c160a6dd30325e2d4c57a558a7bdb94e Mon Sep 17 00:00:00 2001 From: Qianrui Liu <76200646+Qianruipku@users.noreply.github.com> Date: Thu, 11 Jul 2024 17:38:27 +0800 Subject: [PATCH 1/2] Fix: compile failure of main.cpp (#4638) * Fix: compile failure of main.cpp * change the order of CMake * Update CMakeLists.txt --------- Co-authored-by: Chun Cai --- CMakeLists.txt | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 89cda44bca..8092be9d1d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -142,13 +142,14 @@ set(ABACUS_BIN_PATH ${CMAKE_CURRENT_BINARY_DIR}/${ABACUS_BIN_NAME}) include_directories(${ABACUS_SOURCE_DIR}) include_directories(${ABACUS_SOURCE_DIR}/module_base/module_container) +set(CMAKE_CXX_STANDARD 11) +set(CMAKE_CXX_STANDARD_REQUIRED ON) + add_executable(${ABACUS_BIN_NAME} source/main.cpp) if(ENABLE_COVERAGE) add_coverage(${ABACUS_BIN_NAME}) endif() -set(CMAKE_CXX_STANDARD 11) -set(CMAKE_CXX_STANDARD_REQUIRED ON) macro(set_if_higher VARIABLE VALUE) if(${VARIABLE} LESS ${VALUE}) set(${VARIABLE} ${VALUE}) From 41c3f5d51c60675843bed8197cd2d12fd2b8a8de Mon Sep 17 00:00:00 2001 From: Ying Zhang <130237439+jwsyzy@users.noreply.github.com> Date: Thu, 11 Jul 2024 17:40:58 +0800 Subject: [PATCH 2/2] test to merge (#4640) * 123wxr * wxr_code_sh * new_wxr * wxrwxr * nks_public_to_private_wxr * set_get_nks_wxr * new_test_wxr * test_wxr * wxr * nnn * qqq * zy * wxr * add note * annotation * complie * delete_sh * refine_klist * fix_cmake_error * test * fix * remove_nproc_pool * remove * wwww * aada * change * remove_nproc * remove_start * refine_ibz * kpar * vector * vector_new * startpro_vector * Global_remove * Global * add_get_startpro * to_private * to_private * startpro_pool_to_private * add_annotation * [pre-commit.ci lite] apply automatic fixes --------- Co-authored-by: ChaoxiWXR <2100011182@stu.pku.edu.cn> Co-authored-by: Mohan Chen Co-authored-by: pre-commit-ci-lite[bot] <117423508+pre-commit-ci-lite[bot]@users.noreply.github.com> --- source/module_cell/klist.cpp | 3 ++- source/module_cell/parallel_kpoints.cpp | 30 +++++++++++++++++++++++-- source/module_cell/parallel_kpoints.h | 2 ++ source/module_io/numerical_basis.cpp | 1 + 4 files changed, 33 insertions(+), 3 deletions(-) diff --git a/source/module_cell/klist.cpp b/source/module_cell/klist.cpp index 223de760b9..b54cb80f4b 100644 --- a/source/module_cell/klist.cpp +++ b/source/module_cell/klist.cpp @@ -608,6 +608,7 @@ void K_Vectors::ibz_kpoint(const ModuleSymmetry::Symmetry& symm, if (use_symm) { // bravais type of reciprocal lattice and k-lattice + double recip_vec_const[6]; double recip_vec0_const[6]; double k_vec_const[6]; @@ -636,7 +637,7 @@ void K_Vectors::ibz_kpoint(const ModuleSymmetry::Symmetry& symm, false, nullptr); GlobalV::ofs_running << "(for reciprocal lattice: )" << std::endl; - ModuleBase::GlobalFunc::OUT(GlobalV::ofs_running, "BRAVAIS TYPE", recip_brav_type); + ModuleBase::GlobalFunc::OUT(GlobalV::ofs_running, "BRAVAIS TYPE", recip_brav_type); ModuleBase::GlobalFunc::OUT(GlobalV::ofs_running, "BRAVAIS LATTICE NAME", recip_brav_name); ModuleBase::GlobalFunc::OUT(GlobalV::ofs_running, "ibrav", recip_brav_type); diff --git a/source/module_cell/parallel_kpoints.cpp b/source/module_cell/parallel_kpoints.cpp index fa65317dd3..518ba96c01 100644 --- a/source/module_cell/parallel_kpoints.cpp +++ b/source/module_cell/parallel_kpoints.cpp @@ -20,6 +20,7 @@ void Parallel_Kpoints::kinfo(int& nkstot_in, const int& nspin_in) { #ifdef __MPI + this->kpar = kpar_in; // number of pools this->my_pool = my_pool_in; this->rank_in_pool = rank_in_pool_in; @@ -34,15 +35,18 @@ void Parallel_Kpoints::kinfo(int& nkstot_in, this->set_startpro_pool(); // get the start processor index for each pool this->nkstot_np = nkstot_in; + this->nks_np = this->nks_pool[this->my_pool]; // number of k-points in this pool #else this->kpar = 1; this->my_pool = 0; this->rank_in_pool = 0; this->nproc = 1; + this->nspin = nspin_in; this->nkstot_np = nkstot_in; this->nks_np = nkstot_in; + #endif return; } @@ -55,6 +59,7 @@ void Parallel_Kpoints::get_whichpool(const int& nkstot) // std::cout << " calculate : whichpool" << std::endl; // std::cout << " nkstot is " << nkstot << std::endl; + for (int i = 0; i < this->kpar; i++) { for (int ik = 0; ik < this->nks_pool[i]; ik++) @@ -80,6 +85,7 @@ void Parallel_Kpoints::get_nks_pool(const int& nkstot) // ofs_running << "\n nks_ave = " << nks_ave; for (int i = 0; i < this->kpar; i++) + { this->nks_pool[i] = nks_ave; if (i < remain) @@ -94,10 +100,12 @@ void Parallel_Kpoints::get_nks_pool(const int& nkstot) void Parallel_Kpoints::get_startk_pool(const int& nkstot) { startk_pool.resize(this->kpar, 0); + // const int remain = nkstot%this->kpar; startk_pool[0] = 0; for (int i = 1; i < this->kpar; i++) + { startk_pool[i] = startk_pool[i - 1] + nks_pool[i - 1]; // ofs_running << "\n startk_pool[i] = " << startk_pool[i]; @@ -105,7 +113,7 @@ void Parallel_Kpoints::get_startk_pool(const int& nkstot) return; } -void Parallel_Kpoints::set_startpro_pool(void) +void Parallel_Kpoints::set_startpro_pool() { startpro_pool.resize(this->kpar, 0); @@ -125,6 +133,7 @@ void Parallel_Kpoints::set_startpro_pool(void) return; } + // gather kpoints from all processor pools, only need to be called by the first processor of each pool. void Parallel_Kpoints::gatherkvec(const std::vector>& vec_local, std::vector>& vec_global) const @@ -132,11 +141,13 @@ void Parallel_Kpoints::gatherkvec(const std::vector> vec_global.resize(this->nkstot_np, ModuleBase::Vector3(0.0, 0.0, 0.0)); for (int i = 0; i < this->nks_np; ++i) { + if (this->rank_in_pool == 0) { vec_global[i + startk_pool[this->my_pool]] = vec_local[i]; } // vec_global[i + startk_pool[MY_POOL]] = vec_local[i] / double(NPROC_IN_POOL); + } MPI_Allreduce(MPI_IN_PLACE, &vec_global[0], 3 * this->nkstot_np, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD); @@ -147,6 +158,7 @@ void Parallel_Kpoints::gatherkvec(const std::vector> void Parallel_Kpoints::pool_collection(double& value, const double* wk, const int& ik) { #ifdef __MPI + const int ik_now = ik - this->startk_pool[this->my_pool]; // ofs_running << "\n\n ik=" << ik << " ik_now=" << ik_now; @@ -157,28 +169,35 @@ void Parallel_Kpoints::pool_collection(double& value, const double* wk, const in if (this->my_pool == 0) { if (pool == 0) + { value = wk[ik_now]; } else { + // ofs_running << " receive data."; MPI_Status ierror; MPI_Recv(&value, 1, MPI_DOUBLE, this->startpro_pool[pool], ik, MPI_COMM_WORLD, &ierror); + } } else { if (this->my_pool == pool) { + // ofs_running << " send data."; + MPI_Send(&wk[ik_now], 1, MPI_DOUBLE, 0, ik, MPI_COMM_WORLD); } } } else { + // ofs_running << "\n do nothing."; + } MPI_Barrier(MPI_COMM_WORLD); @@ -201,8 +220,10 @@ void Parallel_Kpoints::pool_collection(double* value_re, assert(re.getBound3() == im.getBound3()); assert(re.getBound4() == im.getBound4()); const int dim = dim2 * dim3 * dim4; + pool_collection_aux(value_re, re, dim, ik); pool_collection_aux(value_im, im, dim, ik); + return; } @@ -220,18 +241,23 @@ void Parallel_Kpoints::pool_collection_aux(T* value, const V& w, const int& dim, { #ifdef __MPI const int ik_now = ik - this->startk_pool[this->my_pool]; + const int begin = ik_now * dim; T* p = &w.ptr[begin]; // temprary restrict kpar=1 for NSPIN=2 case for generating_orbitals int pool = 0; - if (this->nspin != 2) + if (this->nspin != 2) { pool = this->whichpool[ik]; +} + // ofs_running << "\n ik=" << ik; + if (this->rank_in_pool == 0) { if (this->my_pool == 0) + { if (pool == 0) { diff --git a/source/module_cell/parallel_kpoints.h b/source/module_cell/parallel_kpoints.h index e715901a72..4f22bd1053 100644 --- a/source/module_cell/parallel_kpoints.h +++ b/source/module_cell/parallel_kpoints.h @@ -57,11 +57,13 @@ class Parallel_Kpoints // get the first processor in the pool int get_startpro_pool(const int& pool) const + { return startpro_pool[pool]; } private: + int kpar = 0; // number of pools int my_pool = 0; // the pool index of the present processor int rank_in_pool = 0; // the rank in the present pool diff --git a/source/module_io/numerical_basis.cpp b/source/module_io/numerical_basis.cpp index c4bc701388..4b6249f2fe 100644 --- a/source/module_io/numerical_basis.cpp +++ b/source/module_io/numerical_basis.cpp @@ -648,6 +648,7 @@ void Numerical_Basis::output_k(std::ofstream& ofs, const K_Vectors& kv) } else { + int startpro_pool = GlobalC::Pkpoints.get_startpro_pool(pool); MPI_Status ierror; MPI_Recv(&kx, 1, MPI_DOUBLE, startpro_pool, ik * 4, MPI_COMM_WORLD, &ierror);