Skip to content

Commit 9cfddf3

Browse files
authored
Add use sw and fix Floating point exception (#6372)
* remove float error in sunway * fix ig=0 * add the sw * change the make_dir * unify the gg use * fix compile bug * add init * temporarily remove the sunway define * add the pesduo * fix compile bug * fix bug in the betar * modify the test
1 parent 3f312e8 commit 9cfddf3

File tree

23 files changed

+145
-78
lines changed

23 files changed

+145
-78
lines changed

CMakeLists.txt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ option(USE_CUDA_MPI "Enable CUDA-aware MPI" OFF)
1717
option(USE_CUDA_ON_DCU "Enable CUDA on DCU" OFF)
1818
option(USE_ROCM "Enable ROCm" OFF)
1919
option(USE_DSP "Enable DSP" OFF)
20+
option(USE_SW "Enable SW Architecture" OFF)
2021

2122
option(USE_ABACUS_LIBM "Build libmath from source to speed up" OFF)
2223
option(ENABLE_LIBXC "Enable using the LibXC package" OFF)
@@ -281,6 +282,18 @@ if (USE_DSP)
281282
target_link_libraries(${ABACUS_BIN_NAME} ${MT_HOST_DIR}/hthreads/lib/libhthread_device.a)
282283
target_link_libraries(${ABACUS_BIN_NAME} ${MT_HOST_DIR}/hthreads/lib/libhthread_host.a)
283284
endif()
285+
if (USE_SW)
286+
add_compile_definitions(__SW)
287+
set(SW ON)
288+
include_directories(${SW_MATH}/include)
289+
include_directories(${SW_FFT}/include)
290+
291+
target_link_libraries(${ABACUS_BIN_NAME} ${SW_FFT}/lib/libfftw3.a)
292+
target_link_libraries(${ABACUS_BIN_NAME} ${SW_MATH}/libswfft.a)
293+
target_link_libraries(${ABACUS_BIN_NAME} ${SW_MATH}/libswscalapack.a)
294+
target_link_libraries(${ABACUS_BIN_NAME} ${SW_MATH}/libswlapack.a)
295+
target_link_libraries(${ABACUS_BIN_NAME} ${SW_MATH}/libswblas.a)
296+
endif()
284297

285298
find_package(Threads REQUIRED)
286299
target_link_libraries(${ABACUS_BIN_NAME} Threads::Threads)
@@ -459,6 +472,9 @@ if(MKLROOT)
459472
if(CMAKE_CXX_COMPILER_ID MATCHES Intel)
460473
list(APPEND math_libs ifcore)
461474
endif()
475+
elseif(USE_SW)
476+
list(APPEND math_libs gfortran)
477+
# SW architecture can only use its own math library
462478
else()
463479
find_package(FFTW3 REQUIRED)
464480
find_package(Lapack REQUIRED)

source/source_base/global_function.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ void OUT(std::ofstream &ofs, const std::string &name)
6161
void MAKE_DIR(const std::string &fn)
6262
{
6363
// ModuleBase::TITLE("global_function","MAKE_DIR");
64+
#ifndef __SW
6465
if (GlobalV::MY_RANK == 0)
6566
{
6667
std::stringstream ss;
@@ -73,6 +74,7 @@ void MAKE_DIR(const std::string &fn)
7374
ModuleBase::WARNING_QUIT("MAKE_DIR", fn);
7475
}
7576
}
77+
#endif
7678
return;
7779
}
7880

source/source_basis/module_pw/pw_basis.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ void PW_Basis::collect_local_pw()
144144
delete[] this->gcar; this->gcar = new ModuleBase::Vector3<double>[this->npw];
145145

146146
ModuleBase::Vector3<double> f;
147+
int gamma_num = 0;
147148
for(int ig = 0 ; ig < this-> npw ; ++ig)
148149
{
149150
int isz = this->ig2isz[ig];
@@ -173,6 +174,12 @@ void PW_Basis::collect_local_pw()
173174
if(this->gg[ig] < 1e-8)
174175
{
175176
this->ig_gge0 = ig;
177+
++gamma_num;
178+
if (gamma_num > 1)
179+
{
180+
ModuleBase::WARNING_QUIT("PW_Basis::collect_local_pw",
181+
"More than one gamma point found in the plane wave basis set.\n");
182+
}
176183
}
177184
}
178185
return;

source/source_basis/module_pw/pw_gatherscatter.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ void PW_Basis::gathers_scatterp(std::complex<T>* in, std::complex<T>* out) const
123123
outp[iz] = inp[iz];
124124
}
125125
}
126-
ModuleBase::timer::tick(this->classname, "gathers_scatterp");
126+
// ModuleBase::timer::tick(this->classname, "gathers_scatterp");
127127
return;
128128
}
129129
#ifdef __MPI

source/source_cell/module_symmetry/symm_rho.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ void Symmetry::rhog_symmetry(std::complex<double> *rhogtot,
285285
//assert(rot_count<=nrotk);
286286
}//end if section
287287
}//end c_index loop
288-
sum /= rot_count;
288+
if (rot_count!=0) sum/= rot_count;
289289
for (int isym = 0; isym < rot_count; ++isym)
290290
{
291291
rhogtot[ipw_record[isym]] = sum/gphase_record[isym];

source/source_cell/pseudo.cpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,34 @@ pseudo::~pseudo()
99
{
1010
}
1111

12+
void pseudo::check_betar()
13+
{
14+
bool min_flag = false;
15+
for (int ib = 0; ib < nbeta; ib++)
16+
{
17+
for (int ir = 0; ir < mesh; ir++)
18+
{
19+
// Get the bit representation of the double
20+
uint64_t bits = *(uint64_t*)&betar(ib, ir);
21+
// Extract exponent field (bits 52-62)
22+
uint64_t exponent = (bits >> 52) & 0x7FF;
23+
// Define exponent threshold for 1e-30
24+
// Calculated as: bias + floor(log2(1e-30))
25+
// Where bias = 1023 and log2(1e-30) ≈ -99.657
26+
// Thus threshold is approximately 923
27+
if ((exponent <= 923))
28+
{
29+
min_flag = true;
30+
betar(ib, ir) = 0.0;
31+
}
32+
}
33+
}
34+
if (min_flag)
35+
{
36+
std::cout << "WARNING: some of potential function is set to zero cause of less than 1e-30.\n";
37+
}
38+
}
39+
1240
void pseudo::print_pseudo(std::ofstream& ofs)
1341
{
1442
print_pseudo_vl(ofs);

source/source_cell/pseudo.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,12 @@ class pseudo
7474
// uspp
7575
ModuleBase::realArray qfuncl; // qfuncl(2*lmax+1,nbeta*(nbeta+1)/2,mesh) Q_{mu,nu}(|r|) function for |r|> r_L
7676
ModuleBase::matrix qqq; // qqq(nbeta,nbeta) q_{mu,nu}
77+
/**
78+
* @brief Check the input data for non-normal numbers in the betar.
79+
* Subsequent values following non-normal numbers will be reset to zero
80+
* to prevent potential computational issues arising from invalid data.
81+
*/
82+
void check_betar();
7783

7884
void print_pseudo_h(std::ofstream& ofs);
7985
void print_pseudo_atom(std::ofstream& ofs);

source/source_cell/read_pp_upf100.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,8 @@ void Pseudopot_upf::read_pseudo_nl(std::ifstream& ifs, Atom_pseudo& pp)
319319
ModuleBase::GlobalFunc::SCAN_END(ifs, "</PP_BETA>");
320320
pp.kkbeta = (this->kbeta[i] > pp.kkbeta) ? this->kbeta[i] : pp.kkbeta;
321321
}
322-
322+
//check the betar for non-normal number
323+
pp.check_betar();
323324
// DIJ
324325
ModuleBase::GlobalFunc::SCAN_BEGIN(ifs, "<PP_DIJ>", false);
325326
ModuleBase::GlobalFunc::READ_VALUE(ifs, this->nd); // nl_4

source/source_cell/read_pp_upf201.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -530,7 +530,8 @@ void Pseudopot_upf::read_pseudo_upf201_nonlocal(std::ifstream& ifs, Atom_pseudo&
530530
word = "</PP_BETA." + std::to_string(ib + 1) + ">";
531531
ModuleBase::GlobalFunc::SCAN_END(ifs, word);
532532
}
533-
533+
//check the betar for non-normal number
534+
pp.check_betar();
534535
// Read the hamiltonian terms D_ij
535536
if (ModuleBase::GlobalFunc::SCAN_BEGIN(ifs, "<PP_DIJ", true, false))
536537
{

source/source_estate/module_charge/charge.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -279,8 +279,11 @@ void Charge::atomic_rho(const int spin_number_need,
279279
for (int ir = 0; ir < mesh; ++ir)
280280
{
281281
double r2 = atom->ncpp.r[ir] * atom->ncpp.r[ir];
282-
rhoatm[ir] = atom->ncpp.rho_at[ir] / ModuleBase::FOUR_PI / r2;
283-
}
282+
if (r2!=0)
283+
{
284+
rhoatm[ir] = atom->ncpp.rho_at[ir] / ModuleBase::FOUR_PI / r2;
285+
}
286+
}
284287
rhoatm[0]
285288
= pow((rhoatm[2] / rhoatm[1]), atom->ncpp.r[1] / (atom->ncpp.r[2] - atom->ncpp.r[1])); // zws add, sunliang updated 2024-03-04
286289
if (rhoatm[0] < 1e-12)

0 commit comments

Comments
 (0)