Skip to content

Commit da7f210

Browse files
committed
Fix complex BDSQR maxit
1 parent 7a29cfe commit da7f210

File tree

2 files changed

+48
-16
lines changed

2 files changed

+48
-16
lines changed

SRC/cbdsqr.f

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,17 @@
204204
*> algorithm through its inner loop. The algorithms stops
205205
*> (and so fails to converge) if the number of passes
206206
*> through the inner loop exceeds MAXITR*N**2.
207+
*>
208+
*> \endverbatim
209+
*
210+
*> \par Note:
211+
* ===========
212+
*>
213+
*> \verbatim
214+
*> Bug report from Cezary Dendek.
215+
*> On November 3rd 2023, the INTEGER variable MAXIT = MAXITR*N**2 is
216+
*> removed since it can overflow pretty easily (for N larger or equal
217+
*> than 18,919). We instead use MAXITDIVN = MAXITR*N.
207218
*> \endverbatim
208219
*
209220
* Authors:
@@ -255,8 +266,8 @@ SUBROUTINE CBDSQR( UPLO, N, NCVT, NRU, NCC, D, E, VT, LDVT, U,
255266
* ..
256267
* .. Local Scalars ..
257268
LOGICAL LOWER, ROTATE
258-
INTEGER I, IDIR, ISUB, ITER, J, LL, LLL, M, MAXIT, NM1,
259-
$ NM12, NM13, OLDLL, OLDM
269+
INTEGER I, IDIR, ISUB, ITER, ITERDIVN, J, LL, LLL, M,
270+
$ MAXITDIVN, NM1, NM12, NM13, OLDLL, OLDM
260271
REAL ABSE, ABSS, COSL, COSR, CS, EPS, F, G, H, MU,
261272
$ OLDCS, OLDSN, R, SHIFT, SIGMN, SIGMX, SINL,
262273
$ SINR, SLL, SMAX, SMIN, SMINOA,
@@ -389,20 +400,21 @@ SUBROUTINE CBDSQR( UPLO, N, NCVT, NRU, NCC, D, E, VT, LDVT, U,
389400
40 CONTINUE
390401
50 CONTINUE
391402
SMINOA = SMINOA / SQRT( REAL( N ) )
392-
THRESH = MAX( TOL*SMINOA, MAXITR*N*N*UNFL )
403+
THRESH = MAX( TOL*SMINOA, MAXITR*(N*(N*UNFL)) )
393404
ELSE
394405
*
395406
* Absolute accuracy desired
396407
*
397-
THRESH = MAX( ABS( TOL )*SMAX, MAXITR*N*N*UNFL )
408+
THRESH = MAX( ABS( TOL )*SMAX, MAXITR*(N*(N*UNFL)) )
398409
END IF
399410
*
400411
* Prepare for main iteration loop for the singular values
401412
* (MAXIT is the maximum number of passes through the inner
402413
* loop permitted before nonconvergence signalled.)
403414
*
404-
MAXIT = MAXITR*N*N
405-
ITER = 0
415+
MAXITDIVN = MAXITR*N
416+
ITERDIVN = 0
417+
ITER = -1
406418
OLDLL = -1
407419
OLDM = -1
408420
*
@@ -418,8 +430,12 @@ SUBROUTINE CBDSQR( UPLO, N, NCVT, NRU, NCC, D, E, VT, LDVT, U,
418430
*
419431
IF( M.LE.1 )
420432
$ GO TO 160
421-
IF( ITER.GT.MAXIT )
422-
$ GO TO 200
433+
IF( ITER.GE.N ) THEN
434+
ITER = ITER - N
435+
ITERDIVN = ITERDIVN + 1
436+
IF( ITERDIVN.GE.MAXITDIVN )
437+
$ GO TO 200
438+
END IF
423439
*
424440
* Find diagonal block of matrix to work on
425441
*

SRC/zbdsqr.f

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,17 @@
204204
*> algorithm through its inner loop. The algorithms stops
205205
*> (and so fails to converge) if the number of passes
206206
*> through the inner loop exceeds MAXITR*N**2.
207+
*>
208+
*> \endverbatim
209+
*
210+
*> \par Note:
211+
* ===========
212+
*>
213+
*> \verbatim
214+
*> Bug report from Cezary Dendek.
215+
*> On November 3rd 2023, the INTEGER variable MAXIT = MAXITR*N**2 is
216+
*> removed since it can overflow pretty easily (for N larger or equal
217+
*> than 18,919). We instead use MAXITDIVN = MAXITR*N.
207218
*> \endverbatim
208219
*
209220
* Authors:
@@ -255,8 +266,8 @@ SUBROUTINE ZBDSQR( UPLO, N, NCVT, NRU, NCC, D, E, VT, LDVT, U,
255266
* ..
256267
* .. Local Scalars ..
257268
LOGICAL LOWER, ROTATE
258-
INTEGER I, IDIR, ISUB, ITER, J, LL, LLL, M, MAXIT, NM1,
259-
$ NM12, NM13, OLDLL, OLDM
269+
INTEGER I, IDIR, ISUB, ITER, ITERDIVN, J, LL, LLL, M,
270+
$ MAXITDIVN, NM1, NM12, NM13, OLDLL, OLDM
260271
DOUBLE PRECISION ABSE, ABSS, COSL, COSR, CS, EPS, F, G, H, MU,
261272
$ OLDCS, OLDSN, R, SHIFT, SIGMN, SIGMX, SINL,
262273
$ SINR, SLL, SMAX, SMIN, SMINOA,
@@ -389,20 +400,21 @@ SUBROUTINE ZBDSQR( UPLO, N, NCVT, NRU, NCC, D, E, VT, LDVT, U,
389400
40 CONTINUE
390401
50 CONTINUE
391402
SMINOA = SMINOA / SQRT( DBLE( N ) )
392-
THRESH = MAX( TOL*SMINOA, MAXITR*N*N*UNFL )
403+
THRESH = MAX( TOL*SMINOA, MAXITR*(N*(N*UNFL)) )
393404
ELSE
394405
*
395406
* Absolute accuracy desired
396407
*
397-
THRESH = MAX( ABS( TOL )*SMAX, MAXITR*N*N*UNFL )
408+
THRESH = MAX( ABS( TOL )*SMAX, MAXITR*(N*(N*UNFL)) )
398409
END IF
399410
*
400411
* Prepare for main iteration loop for the singular values
401412
* (MAXIT is the maximum number of passes through the inner
402413
* loop permitted before nonconvergence signalled.)
403414
*
404-
MAXIT = MAXITR*N*N
405-
ITER = 0
415+
MAXITDIVN = MAXITR*N
416+
ITERDIVN = 0
417+
ITER = -1
406418
OLDLL = -1
407419
OLDM = -1
408420
*
@@ -418,8 +430,12 @@ SUBROUTINE ZBDSQR( UPLO, N, NCVT, NRU, NCC, D, E, VT, LDVT, U,
418430
*
419431
IF( M.LE.1 )
420432
$ GO TO 160
421-
IF( ITER.GT.MAXIT )
422-
$ GO TO 200
433+
IF( ITER.GE.N ) THEN
434+
ITER = ITER - N
435+
ITERDIVN = ITERDIVN + 1
436+
IF( ITERDIVN.GE.MAXITDIVN )
437+
$ GO TO 200
438+
END IF
423439
*
424440
* Find diagonal block of matrix to work on
425441
*

0 commit comments

Comments
 (0)