Repository navigation
Try: safe scaling xNRM2 - #514
weslleyspereira merged 3 commits into
Conversation
Codecov Report
@@ Coverage Diff @@
## master #514 +/- ##
==========================================
- Coverage 83.36% 83.35% -0.01%
==========================================
Files 1820 1820
Lines 185545 185545
==========================================
- Hits 154673 154660 -13
- Misses 30872 30885 +13
Continue to review full report at Codecov.
|
|
These new routines propagate Infs and NaNs. Check with the following code: program testCornerCasesIn_xNRM2
implicit none
integer, parameter :: wp = kind(1.e0)
real(wp), external :: snrm2
real(wp), parameter :: zero = 0
real(wp), parameter :: pinf = 2*huge(zero)
real(wp), parameter :: ninf = -pinf-1
real(wp) :: aNaN
integer, parameter :: n = 3
real(wp) x(n)
real(wp) r
x = (/ 1,2,3 /)
aNaN = zero
aNaN = zero/aNaN
! Tests for NaN
print *, "aNaN = ", aNaN
print *, "(aNaN > 0) = ", (aNaN > 0)
print *, "(aNaN > +inf) = ", (aNaN > pinf)
print *, "(aNaN < +inf) = ", (aNaN < pinf)
print *, "(aNaN > -inf) = ", (aNaN > ninf)
print *, "(aNaN < -inf) = ", (aNaN < ninf)
print *, "(aNaN /= aNaN) = ", (aNaN /= aNaN)
print *, " "
! Test without NaN
r = snrm2(n, x, 1)
print *, "x = ", x
print *, "nrm2(x) = ", r
print *, " "
! Test with Infs
x(3) = pinf
print *, "x = ", x
r = snrm2(n, x, 1)
print *, "nrm2(x) = ", r
print *, " "
x(2) = ninf
print *, "x = ", x
r = snrm2(n, x, 1)
print *, "nrm2(x) = ", r
print *, " "
x(1) = pinf
print *, "x = ", x
r = snrm2(n, x, 1)
print *, "nrm2(x) = ", r
print *, " "
! Test with NaN
x(3) = aNaN
print *, "x = ", x
r = snrm2(n, x, 1)
print *, "nrm2(x) = ", r
print *, " "
x(3) = pinf
x(2) = aNaN
print *, "x = ", x
r = snrm2(n, x, 1)
print *, "nrm2(x) = ", r
end program testCornerCasesIn_xNRM2Results: |
langou
left a comment
There was a problem hiding this comment.
This is great. We will wait for 3.10.0 to release this. Part of Ed Anderson's contributions. I like the fact that you hard-coded la_constants.f90 in this file for now. I am not sure we want to introduce la_constants.f90 in BLAS. (Whereas it is great in LAPACK.) BLAS does not seem to need these constants much. There are in NRM2(), and probably ROT(). Note: Weslley only pushed Ed's contributions to BLAS/NRM2() and LAPACK/ROT() but not BLAS/ROT().
|
Some comments about the implementation:
|
510ac6f to
0791c22
Compare
…2-from-Ed-Anderson Try: safe scaling xNRM2
Edward Anderson stated in his paper https://doi.org/10.1145/3061665:
The square root of a sum of squares is well known to be prone to overflow and underflow. Ad hoc scaling
of intermediate results, as has been done in numerical software such as the BLAS and LAPACK, mostly
avoids the problem, but it can still occur at extreme values in the range of representable numbers. More
careful scaling, as has been implemented in recent versions of the standard algorithms, may come at the
expense of performance or clarity. This work reimplements the vector 2-norm and the generation of Givens
rotations from the Level 1 BLAS to improve their performance and design. In addition, support for negative
increments is extended to the Level 1 BLAS operations on a single vector, and a comprehensive test suite
for all the Level 1 BLAS is included.
This PR replaces the original xNRM2 routines with Edward's safe scaling codes plus some minor modifications.
Since the codes were written in the Fortran90 standard, I removed
from the
CMakeLists.txt. The compiler now determines the Fortran layout by the file extension.