Skip to content

Commit

Permalink
Merge branch 'develop' into lapack_unit_test_and_document
Browse files Browse the repository at this point in the history
  • Loading branch information
Critsium-xy authored Jul 11, 2024
2 parents 21525b0 + 41c3f5d commit aa14ed2
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 5 deletions.
5 changes: 3 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -141,13 +141,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})
Expand Down
3 changes: 2 additions & 1 deletion source/module_cell/klist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down Expand Up @@ -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);

Expand Down
30 changes: 28 additions & 2 deletions source/module_cell/parallel_kpoints.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
}
Expand All @@ -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++)
Expand All @@ -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)
Expand All @@ -94,18 +100,20 @@ 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];
}
return;
}

void Parallel_Kpoints::set_startpro_pool(void)
void Parallel_Kpoints::set_startpro_pool()
{
startpro_pool.resize(this->kpar, 0);

Expand All @@ -125,18 +133,21 @@ 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<ModuleBase::Vector3<double>>& vec_local,
std::vector<ModuleBase::Vector3<double>>& vec_global) const
{
vec_global.resize(this->nkstot_np, ModuleBase::Vector3<double>(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);
Expand All @@ -147,6 +158,7 @@ void Parallel_Kpoints::gatherkvec(const std::vector<ModuleBase::Vector3<double>>
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;

Expand All @@ -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);
Expand All @@ -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;
}

Expand All @@ -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)
{
Expand Down
2 changes: 2 additions & 0 deletions source/module_cell/parallel_kpoints.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions source/module_io/numerical_basis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit aa14ed2

Please sign in to comment.