Skip to content

Commit 477b4b5

Browse files
authored
(#291) Improved FPE in g2g.
* Added some NaN checks in g2g. * Changed tolerance for Ec/Fockc calculation.
1 parent 86e0256 commit 477b4b5

File tree

4 files changed

+26
-22
lines changed

4 files changed

+26
-22
lines changed

.gitignore

+2-2
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,6 @@ test/integration_test/iteration/main_gpu
7171
###########################################################
7272
test/tests_engine/*.pyc
7373
###########################################################
74-
# Profiling
74+
# Others
7575
###########################################################
76-
test/profiling/*
76+
.vscode

g2g/init.cpp

+2-8
Original file line numberDiff line numberDiff line change
@@ -319,18 +319,12 @@ void g2g_iteration(bool compute_energy, double* fort_energy_ptr,
319319
double* fort_forces_ptr) {
320320
Timers timers;
321321
#ifdef _DEBUG
322-
feenableexcept(FE_INVALID);
323-
feenableexcept(FE_DIVBYZERO);
324-
//feenableexcept(FE_UNDERFLOW);
325-
feenableexcept(FE_OVERFLOW);
322+
feenableexcept(FE_INVALID | FE_DIVBYZERO | FE_OVERFLOW);
326323
#endif
327324
partition.solve(timers, compute_rmm, lda, compute_forces, compute_energy,
328325
fort_energy_ptr, fort_forces_ptr, fortran_vars.OPEN);
329326
#ifdef _DEBUG
330-
fedisableexcept(FE_INVALID);
331-
fedisableexcept(FE_DIVBYZERO);
332-
//fedisableexcept(FE_UNDERFLOW);
333-
fedisableexcept(FE_OVERFLOW);
327+
fedisableexcept(FE_INVALID | FE_DIVBYZERO | FE_OVERFLOW);
334328
#endif
335329
}
336330

g2g/pointxc/pbeOS_corr.h

+9-2
Original file line numberDiff line numberDiff line change
@@ -234,8 +234,15 @@ __host__ __device__ void pbeOS_corr(scalar_type rho, scalar_type rs,
234234
scalar_type PREF = hz - GZ * T2 * hT / G;
235235
scalar_type FACT5 = GZ * ((scalar_type)2.0f * hT + t * hTT) / G;
236236
COMM = COMM - PREF * zet - uu * hTT - vv * hT - ww * (hZT - FACT5);
237-
// if ( COMM != COMM ) { printf("NaN in COMM2 - hRS %E hRST %E T2 %E hT %E hTT %E \n",
238-
// hRS, hRST, T2, hT, hTT); };
237+
238+
#ifdef _DEBUG
239+
if ( COMM != COMM ) {
240+
printf("NaN in COMM2 - hRS %E hRST %E T2 %E hT %E hTT %E \n", hRS, hRST, T2, hT, hTT);
241+
printf("hTT: G3 %E t %E B %E Q8 %E Q9 %E FACT3 %E \n", G3, t, B, Q8, Q9, FACT3);
242+
printf("hRST: rsthrd %E T2 %E hBT %E BEC %E ECRS %E \n", rsthrd, T2, hBT, BEC, ECRS);
243+
printf("Q8: Q4 %E Q5 %E T2 %E \n", Q4, Q5, T2);
244+
};
245+
#endif
239246
dvc_a = COMM + PREF;
240247
dvc_b = COMM - PREF;
241248
// PBE POTENTIAL DONE !!!!!

g2g/pointxc/pbeOS_main.h

+13-10
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ __host__ __device__ void pbeOS_main(
5656
// The limit 1e-18 is the one set in PBE's original paper, which
5757
// works in double precision. For single precision, we take 1e-12
5858
// so that rho^3 is still within precision.
59+
// For Ec calculation, the limit is a bit lower (1e-10).
5960
#if FULL_DOUBLE
6061
const scalar_type MINIMUM_DENSITY_VALUE = (scalar_type) 1e-18;
6162
#else
@@ -72,7 +73,7 @@ __host__ __device__ void pbeOS_main(
7273
vxpbe_a = (scalar_type)0.0f;
7374
vxpbe_b = (scalar_type)0.0f;
7475

75-
76+
7677
scalar_type twodens = (scalar_type)2.0f * dens_a;
7778
if (twodens > MINIMUM_DENSITY_VALUE) {
7879
twodens2 = twodens * twodens;
@@ -117,7 +118,7 @@ __host__ __device__ void pbeOS_main(
117118
// Construct total density and contribution to Ex
118119
scalar_type rho = dens_a + dens_b;
119120
expbe = (expbe_a * (dens_a / rho) + expbe_b * (dens_b/rho));
120-
if (rho < MINIMUM_DENSITY_VALUE) { return; };
121+
if (rho < (MINIMUM_DENSITY_VALUE * (scalar_type) 1E5)) { return; };
121122

122123
/*-------------------------------------------------------------//
123124
// PBE correlation
@@ -187,14 +188,16 @@ __host__ __device__ void pbeOS_main(
187188
vcpbe_a = vc_a + dvc_a;
188189
vcpbe_b = vc_b + dvc_b;
189190

190-
// if (expbe_a != expbe_a) { printf("NaN in expbe_a \n");};
191-
// if (expbe_b != expbe_b) { printf("NaN in expbe_b \n");};
192-
// if (ec != ec) { printf("NaN in ec \n");};
193-
// if (h != h) { printf("NaN in h \n");};
194-
// if (vc_a != vc_a) { printf("NaN in vc_a \n");};
195-
// if (dvc_a != dvc_a) { printf("NaN in dvc_a \n");};
196-
// if (vc_b != vc_b) { printf("NaN in vc_b \n");};
197-
// if (dvc_b!= dvc_b) { printf("NaN in dvc_b \n");};
191+
#ifdef _DEBUG
192+
if (expbe_a != expbe_a) { printf("NaN in expbe_a \n");};
193+
if (expbe_b != expbe_b) { printf("NaN in expbe_b \n");};
194+
if (ec != ec) { printf("NaN in ec \n");};
195+
if (h != h) { printf("NaN in h \n");};
196+
if (vc_a != vc_a) { printf("NaN in vc_a \n");};
197+
if (dvc_a != dvc_a) { printf("NaN in dvc_a \n");};
198+
if (vc_b != vc_b) { printf("NaN in vc_b \n");};
199+
if (dvc_b!= dvc_b) { printf("NaN in dvc_b \n");};
200+
#endif
198201
} // pbeOS_main
199202

200203
#undef EASYPBE_PI

0 commit comments

Comments
 (0)