Break out of potentially infinite rescaling loops in xLARGV, xLARTG and xLARTGP - #419
Conversation
|
PR looks fine to me. The only thing I would recommend changing is whether this fixes #411. Although this PR will remove the deadlock, it will result in inf values. That issue should remain open untill the overflow has been fixed. |
|
PR comment changed to reflect this, thanks. |
Codecov Report
@@ Coverage Diff @@
## master #419 +/- ##
==========================================
+ Coverage 83.24% 83.31% +0.06%
==========================================
Files 1808 1808
Lines 170197 170873 +676
==========================================
+ Hits 141681 142362 +681
+ Misses 28516 28511 -5
Continue to review full report at Codecov.
|
|
@langou if we're releasing soon, i'd include this PR too. Judging by the amount of times i've personally run into this issue, there are probably a lot of people that suffer from it without even realising. |
|
Hi @thijssteel, thanks for helping out in what to release and what not. Much appreciated. |
|
Quick review of ZLARTG. Throwing some comments here.
|
|
@langou I've spent quite a lot of time looking into the scaling. (my research code spends up to 30% of its time in that routine, so it really matters for me). I don't fully understand it, but i can say that the scaling does matter. Disabling it significantly increases the backward error (almost factor 2 in some cases). |
|
Hi @thijssteel, Super. Good to know. Thanks for letting us know. By a factor of 2 in backward error, do you mean from from 1e-12 to 2e-12 for example? (Or from 1e-12 to 1e-6?) I am assuming the former. On our end, we are looking at various papers right now to try to understand better. Here is some of the literature on scaling we are looking at. Julien.
|
|
Thanks for those references. It was indeed the first case. In a full run of the double complex QR algorithm (single shifted) the relative backward error went from 3.1E-15 to 4.3E-15 in the worst case, sometimes there is no difference. Small note though, this is an edited version of ZLARTG, because i needed another normalization of the phase. The same problems might not be present in the current implementation. I haven't had time to read all the references, but if you're worried about the performance impact of the do loop to scale, perhaps it can be replaced with direct calculations using |
|
Hi @thijssteel, Not worried at all of the performance impact of this DO-LOOP. I think what worries us with this loop is part of the general concerns: [ ranked from major concern, to less major concern ] (1) the potential infinite loop in the presence of NaN, or Infinity, and (2) the creation of NaN while scaling, and (3) the non-propagation of NaN. The performance impact of this loop does not worry me for the least. The iteration COUNT at 20 is fine with me, though it seems that for any input (SINGLE or DOUBLE) the max number for COUNT is at most 3. I am glad that there is hard limit (20 is a fine number) in case things go eery. I would like to understand all this better. Related: Ed Anderson sent us some codes recently with patches that goes in the same vein. Note: I do not understand why scaling improves accuracy. This is a tat weird to me. We scale with powers of 2 on purpose so as to keep the base-2 computation the same. But I am not surprised to read that base-2 computation are not exactly the same after a scaling. A few threshold here and there might be absolute and not relative. Might hit denorm faster, etc.
Which normalization do you need? We already have LAPACK/ZLARTG and BLAS/ZROTG. A third one? Argh. Yes, we have a couple of routines to generate Householder reflections for a similar reason. I can see we need a few to generate Givens rotations. |
|
In the current routine, the phase of R is taken as the phase of F. I needed it to be G, this also meant that C needed to be complex and S could be real. And then ZROT also needed to be changed... Probably not worth including in the library as its a very very specific case. I'll try to find out the exact parameters that resulted in the increased error. |
|
Thanks for explaining. No need to explain for now more on my end. J. |
|
Comment: @weslleyspereira is working on another PR with some codes from Ed Anderson. (Spoiler Alert: There will be a lots of Fortran 90.) We would like to see how the community reacts to these Fortran 90 codes. Ed provided us a lots of routines (all the family the norm computation routines: xLANxx for example, but more). Ed has a new xLARGV so @weslleyspereira will prepare a PR based on this. And we will see what people think about the F90 thing. |
|
Hi all, I think I am going to merge this pull request. Last round of opinion, polling: Cheers, |
|
Have to abstain as it is "my" PR, but this trivial fix has been distributed with OpenBLAS since June... |
|
I am OK with merging the current state of this PR. I just want to let some math registered here. It is about @langou's comment:
In the standard IEEE arithmetic:
which means we need only 2 iterations in the loops. In a generic IEEE float type:
I am OK with merging the current state of this PR. |
Break out of potentially infinite rescaling loops in xLARGV, xLARTG and xLARTGP
avoids the hang seen in #411 in the same trivial manner as used for xLARFG in #196 but does not address the related topic of overflows in the caller that led to the appearance of Inf arguments