LAPACK 3.12.1
LAPACK: Linear Algebra PACKage
Loading...
Searching...
No Matches

◆ clatrs3()

subroutine clatrs3 ( character uplo,
character trans,
character diag,
character normin,
integer n,
integer nrhs,
complex, dimension( lda, * ) a,
integer lda,
complex, dimension( ldx, * ) x,
integer ldx,
real, dimension( * ) scale,
real, dimension( * ) cnorm,
real, dimension( * ) work,
integer lwork,
integer info )

CLATRS3 solves a triangular system of equations with the scale factors set to prevent overflow.

Purpose:
!>
!> CLATRS3 solves one of the triangular systems
!>
!>    A * X = B * diag(scale),  A**T * X = B * diag(scale), or
!>    A**H * X = B * diag(scale)
!>
!> with scaling to prevent overflow.  Here A is an upper or lower
!> triangular matrix, A**T denotes the transpose of A, A**H denotes the
!> conjugate transpose of A. X and B are n-by-nrhs matrices and scale
!> is an nrhs-element vector of scaling factors. A scaling factor scale(j)
!> is usually less than or equal to 1, chosen such that X(:,j) is less
!> than the overflow threshold. If the matrix A is singular (A(j,j) = 0
!> for some j), then a non-trivial solution to A*X = 0 is returned. If
!> the system is so badly scaled that the solution cannot be represented
!> as (1/scale(k))*X(:,k), then x(:,k) = 0 and scale(k) is returned.
!>
!> This is a BLAS-3 version of LATRS for solving several right
!> hand sides simultaneously.
!>
!> 
Parameters
[in]UPLO
!>          UPLO is CHARACTER*1
!>          Specifies whether the matrix A is upper or lower triangular.
!>          = 'U':  Upper triangular
!>          = 'L':  Lower triangular
!> 
[in]TRANS
!>          TRANS is CHARACTER*1
!>          Specifies the operation applied to A.
!>          = 'N':  Solve A * x = s*b  (No transpose)
!>          = 'T':  Solve A**T* x = s*b  (Transpose)
!>          = 'C':  Solve A**T* x = s*b  (Conjugate transpose)
!> 
[in]DIAG
!>          DIAG is CHARACTER*1
!>          Specifies whether or not the matrix A is unit triangular.
!>          = 'N':  Non-unit triangular
!>          = 'U':  Unit triangular
!> 
[in]NORMIN
!>          NORMIN is CHARACTER*1
!>          Specifies whether CNORM has been set or not.
!>          = 'Y':  CNORM contains the column norms on entry
!>          = 'N':  CNORM is not set on entry.  On exit, the norms will
!>                  be computed and stored in CNORM.
!> 
[in]N
!>          N is INTEGER
!>          The order of the matrix A.  N >= 0.
!> 
[in]NRHS
!>          NRHS is INTEGER
!>          The number of columns of X.  NRHS >= 0.
!> 
[in]A
!>          A is COMPLEX array, dimension (LDA,N)
!>          The triangular matrix A.  If UPLO = 'U', the leading n by n
!>          upper triangular part of the array A contains the upper
!>          triangular matrix, and the strictly lower triangular part of
!>          A is not referenced.  If UPLO = 'L', the leading n by n lower
!>          triangular part of the array A contains the lower triangular
!>          matrix, and the strictly upper triangular part of A is not
!>          referenced.  If DIAG = 'U', the diagonal elements of A are
!>          also not referenced and are assumed to be 1.
!> 
[in]LDA
!>          LDA is INTEGER
!>          The leading dimension of the array A.  LDA >= max (1,N).
!> 
[in,out]X
!>          X is COMPLEX array, dimension (LDX,NRHS)
!>          On entry, the right hand side B of the triangular system.
!>          On exit, X is overwritten by the solution matrix X.
!> 
[in]LDX
!>          LDX is INTEGER
!>          The leading dimension of the array X.  LDX >= max (1,N).
!> 
[out]SCALE
!>          SCALE is REAL array, dimension (NRHS)
!>          The scaling factor s(k) is for the triangular system
!>          A * x(:,k) = s(k)*b(:,k)  or  A**T* x(:,k) = s(k)*b(:,k).
!>          If SCALE = 0, the matrix A is singular or badly scaled.
!>          If A(j,j) = 0 is encountered, a non-trivial vector x(:,k)
!>          that is an exact or approximate solution to A*x(:,k) = 0
!>          is returned. If the system so badly scaled that solution
!>          cannot be presented as x(:,k) * 1/s(k), then x(:,k) = 0
!>          is returned.
!> 
[in,out]CNORM
!>          CNORM is REAL array, dimension (N)
!>
!>          If NORMIN = 'Y', CNORM is an input argument and CNORM(j)
!>          contains the norm of the off-diagonal part of the j-th column
!>          of A.  If TRANS = 'N', CNORM(j) must be greater than or equal
!>          to the infinity-norm, and if TRANS = 'T' or 'C', CNORM(j)
!>          must be greater than or equal to the 1-norm.
!>
!>          If NORMIN = 'N', CNORM is an output argument and CNORM(j)
!>          returns the 1-norm of the offdiagonal part of the j-th column
!>          of A.
!> 
[out]WORK
!>          WORK is REAL array, dimension (MAX(1,LWORK)).
!>          On exit, if INFO = 0, WORK(1) returns the optimal size of
!>          WORK.
!> 
[in]LWORK
!>          LWORK is INTEGER
!>          The dimension of the array WORK.
!>
!>          If MIN(N,NRHS) = 0, LWORK >= 1, else
!>          LWORK >= MAX(1, 2*NBA * MAX(NBA, MIN(NRHS, 32)), where
!>          NBA = (N + NB - 1)/NB and NB is the optimal block size.
!>
!>          If LWORK = -1, then a workspace query is assumed; the routine
!>          only calculates the optimal dimensions of the WORK array, returns
!>          this value as the first entry of the WORK array, and no error
!>          message related to LWORK is issued by XERBLA.
!> 
[out]INFO
!>          INFO is INTEGER
!>          = 0:  successful exit
!>          < 0:  if INFO = -k, the k-th argument had an illegal value
!> 
Author
Univ. of Tennessee
Univ. of California Berkeley
Univ. of Colorado Denver
NAG Ltd.
Further Details:

Definition at line 233 of file clatrs3.f.

235 IMPLICIT NONE
236*
237* .. Scalar Arguments ..
238 CHARACTER DIAG, TRANS, NORMIN, UPLO
239 INTEGER INFO, LDA, LWORK, LDX, N, NRHS
240* ..
241* .. Array Arguments ..
242 COMPLEX A( LDA, * ), X( LDX, * )
243 REAL CNORM( * ), SCALE( * ), WORK( * )
244* ..
245*
246* =====================================================================
247*
248* .. Parameters ..
249 REAL ZERO, ONE
250 parameter( zero = 0.0e+0, one = 1.0e+0 )
251 COMPLEX CZERO, CONE
252 parameter( czero = ( 0.0e+0, 0.0e+0 ) )
253 parameter( cone = ( 1.0e+0, 0.0e+0 ) )
254 INTEGER NBMAX, NBMIN, NBRHS, NRHSMIN
255 parameter( nrhsmin = 2, nbrhs = 32 )
256 parameter( nbmin = 8, nbmax = 64 )
257* ..
258* .. Local Arrays ..
259 REAL W( NBMAX ), XNRM( NBRHS )
260* ..
261* .. Local Scalars ..
262 LOGICAL LQUERY, NOTRAN, NOUNIT, UPPER
263 INTEGER AWRK, I, IFIRST, IINC, ILAST, II, I1, I2, J,
264 $ JFIRST, JINC, JLAST, J1, J2, K, KK, K1, K2,
265 $ LANRM, LDS, LSCALE, NB, NBA, NBX, RHS, LWMIN
266 REAL ANRM, BIGNUM, BNRM, RSCAL, SCAL, SCALOC,
267 $ SCAMIN, SMLNUM, TMAX
268* ..
269* .. External Functions ..
270 LOGICAL LSAME
271 INTEGER ILAENV
272 REAL SLAMCH, CLANGE, SLARMM,
273 $ SROUNDUP_LWORK
274 EXTERNAL ilaenv, lsame, slamch,
276* ..
277* .. External Subroutines ..
278 EXTERNAL clatrs, csscal, xerbla
279* ..
280* .. Intrinsic Functions ..
281 INTRINSIC abs, max, min
282* ..
283* .. Executable Statements ..
284*
285 info = 0
286 upper = lsame( uplo, 'U' )
287 notran = lsame( trans, 'N' )
288 nounit = lsame( diag, 'N' )
289 lquery = ( lwork.EQ.-1 )
290*
291* Partition A and X into blocks.
292*
293 nb = max( nbmin, ilaenv( 1, 'CLATRS', '', n, n, -1, -1 ) )
294 nb = min( nbmax, nb )
295 nba = max( 1, (n + nb - 1) / nb )
296 nbx = max( 1, (nrhs + nbrhs - 1) / nbrhs )
297*
298* Compute the workspace
299*
300* The workspace comprises two parts.
301* The first part stores the local scale factors. Each simultaneously
302* computed right-hand side requires one local scale factor per block
303* row. WORK( I + KK * LDS ) is the scale factor of the vector
304* segment associated with the I-th block row and the KK-th vector
305* in the block column.
306*
307 lscale = nba * max( nba, min( nrhs, nbrhs ) )
308 lds = nba
309*
310* The second part stores upper bounds of the triangular A. There are
311* a total of NBA x NBA blocks, of which only the upper triangular
312* part or the lower triangular part is referenced. The upper bound of
313* the block A( I, J ) is stored as WORK( AWRK + I + J * NBA ).
314*
315 lanrm = nba * nba
316 awrk = lscale
317*
318 IF( min( n, nrhs ).EQ.0 ) THEN
319 lwmin = 1
320 ELSE
321 lwmin = lscale + lanrm
322 END IF
323 work( 1 ) = sroundup_lwork( lwmin )
324*
325* Test the input parameters.
326*
327 IF( .NOT.upper .AND. .NOT.lsame( uplo, 'L' ) ) THEN
328 info = -1
329 ELSE IF( .NOT.notran .AND. .NOT.lsame( trans, 'T' ) .AND. .NOT.
330 $ lsame( trans, 'C' ) ) THEN
331 info = -2
332 ELSE IF( .NOT.nounit .AND. .NOT.lsame( diag, 'U' ) ) THEN
333 info = -3
334 ELSE IF( .NOT.lsame( normin, 'Y' ) .AND. .NOT.
335 $ lsame( normin, 'N' ) ) THEN
336 info = -4
337 ELSE IF( n.LT.0 ) THEN
338 info = -5
339 ELSE IF( nrhs.LT.0 ) THEN
340 info = -6
341 ELSE IF( lda.LT.max( 1, n ) ) THEN
342 info = -8
343 ELSE IF( ldx.LT.max( 1, n ) ) THEN
344 info = -10
345 ELSE IF( .NOT.lquery .AND. lwork.LT.lwmin ) THEN
346 info = -14
347 END IF
348 IF( info.NE.0 ) THEN
349 CALL xerbla( 'CLATRS3', -info )
350 RETURN
351 ELSE IF( lquery ) THEN
352 RETURN
353 END IF
354*
355* Initialize scaling factors
356*
357 DO kk = 1, nrhs
358 scale( kk ) = one
359 END DO
360*
361* Quick return if possible
362*
363 IF( min( n, nrhs ).EQ.0 )
364 $ RETURN
365*
366* Determine machine dependent constant to control overflow.
367*
368 bignum = slamch( 'Overflow' )
369 smlnum = slamch( 'Safe Minimum' )
370*
371* Use unblocked code for small problems
372*
373 IF( nrhs.LT.nrhsmin ) THEN
374 CALL clatrs( uplo, trans, diag, normin, n, a, lda, x( 1,
375 $ 1 ),
376 $ scale( 1 ), cnorm, info )
377 DO k = 2, nrhs
378 CALL clatrs( uplo, trans, diag, 'Y', n, a, lda, x( 1,
379 $ k ),
380 $ scale( k ), cnorm, info )
381 END DO
382 RETURN
383 END IF
384*
385* Compute norms of blocks of A excluding diagonal blocks and find
386* the block with the largest norm TMAX.
387*
388 tmax = zero
389 DO j = 1, nba
390 j1 = (j-1)*nb + 1
391 j2 = min( j*nb, n ) + 1
392 IF ( upper ) THEN
393 ifirst = 1
394 ilast = j - 1
395 ELSE
396 ifirst = j + 1
397 ilast = nba
398 END IF
399 DO i = ifirst, ilast
400 i1 = (i-1)*nb + 1
401 i2 = min( i*nb, n ) + 1
402*
403* Compute upper bound of A( I1:I2-1, J1:J2-1 ).
404*
405 IF( notran ) THEN
406 anrm = clange( 'I', i2-i1, j2-j1, a( i1, j1 ), lda,
407 $ w )
408 work( awrk + i+(j-1)*nba ) = anrm
409 ELSE
410 anrm = clange( '1', i2-i1, j2-j1, a( i1, j1 ), lda,
411 $ w )
412 work( awrk + j+(i-1)*nba ) = anrm
413 END IF
414 tmax = max( tmax, anrm )
415 END DO
416 END DO
417*
418 IF( .NOT. tmax.LE.slamch('Overflow') ) THEN
419*
420* Some matrix entries have huge absolute value. At least one upper
421* bound norm( A(I1:I2-1, J1:J2-1), 'I') is not a valid floating-point
422* number, either due to overflow in LANGE or due to Inf in A.
423* Fall back to LATRS. Set normin = 'N' for every right-hand side to
424* force computation of TSCAL in LATRS to avoid the likely overflow
425* in the computation of the column norms CNORM.
426*
427 DO k = 1, nrhs
428 CALL clatrs( uplo, trans, diag, 'N', n, a, lda, x( 1,
429 $ k ),
430 $ scale( k ), cnorm, info )
431 END DO
432 RETURN
433 END IF
434*
435* Every right-hand side requires workspace to store NBA local scale
436* factors. To save workspace, X is computed successively in block columns
437* of width NBRHS, requiring a total of NBA x NBRHS space. If sufficient
438* workspace is available, larger values of NBRHS or NBRHS = NRHS are viable.
439 DO k = 1, nbx
440* Loop over block columns (index = K) of X and, for column-wise scalings,
441* over individual columns (index = KK).
442* K1: column index of the first column in X( J, K )
443* K2: column index of the first column in X( J, K+1 )
444* so the K2 - K1 is the column count of the block X( J, K )
445 k1 = (k-1)*nbrhs + 1
446 k2 = min( k*nbrhs, nrhs ) + 1
447*
448* Initialize local scaling factors of current block column X( J, K )
449*
450 DO kk = 1, k2-k1
451 DO i = 1, nba
452 work( i+kk*lds ) = one
453 END DO
454 END DO
455*
456 IF( notran ) THEN
457*
458* Solve A * X(:, K1:K2-1) = B * diag(scale(K1:K2-1))
459*
460 IF( upper ) THEN
461 jfirst = nba
462 jlast = 1
463 jinc = -1
464 ELSE
465 jfirst = 1
466 jlast = nba
467 jinc = 1
468 END IF
469 ELSE
470*
471* Solve op(A) * X(:, K1:K2-1) = B * diag(scale(K1:K2-1))
472* where op(A) = A**T or op(A) = A**H
473*
474 IF( upper ) THEN
475 jfirst = 1
476 jlast = nba
477 jinc = 1
478 ELSE
479 jfirst = nba
480 jlast = 1
481 jinc = -1
482 END IF
483 END IF
484
485 DO j = jfirst, jlast, jinc
486* J1: row index of the first row in A( J, J )
487* J2: row index of the first row in A( J+1, J+1 )
488* so that J2 - J1 is the row count of the block A( J, J )
489 j1 = (j-1)*nb + 1
490 j2 = min( j*nb, n ) + 1
491*
492* Solve op(A( J, J )) * X( J, RHS ) = SCALOC * B( J, RHS )
493*
494 DO kk = 1, k2-k1
495 rhs = k1 + kk - 1
496 IF( kk.EQ.1 ) THEN
497 CALL clatrs( uplo, trans, diag, 'N', j2-j1,
498 $ a( j1, j1 ), lda, x( j1, rhs ),
499 $ scaloc, cnorm, info )
500 ELSE
501 CALL clatrs( uplo, trans, diag, 'Y', j2-j1,
502 $ a( j1, j1 ), lda, x( j1, rhs ),
503 $ scaloc, cnorm, info )
504 END IF
505* Find largest absolute value entry in the vector segment
506* X( J1:J2-1, RHS ) as an upper bound for the worst case
507* growth in the linear updates.
508 xnrm( kk ) = clange( 'I', j2-j1, 1, x( j1, rhs ),
509 $ ldx, w )
510*
511 IF( scaloc .EQ. zero ) THEN
512* LATRS found that A is singular through A(j,j) = 0.
513* Reset the computation x(1:n) = 0, x(j) = 1, SCALE = 0
514* and compute op(A)*x = 0. Note that X(J1:J2-1, KK) is
515* set by LATRS.
516 scale( rhs ) = zero
517 DO ii = 1, j1-1
518 x( ii, kk ) = czero
519 END DO
520 DO ii = j2, n
521 x( ii, kk ) = czero
522 END DO
523* Discard the local scale factors.
524 DO ii = 1, nba
525 work( ii+kk*lds ) = one
526 END DO
527 scaloc = one
528 ELSE IF( scaloc*work( j+kk*lds ) .EQ. zero ) THEN
529* LATRS computed a valid scale factor, but combined with
530* the current scaling the solution does not have a
531* scale factor > 0.
532*
533* Set WORK( J+KK*LDS ) to smallest valid scale
534* factor and increase SCALOC accordingly.
535 scal = work( j+kk*lds ) / smlnum
536 scaloc = scaloc * scal
537 work( j+kk*lds ) = smlnum
538* If LATRS overestimated the growth, x may be
539* rescaled to preserve a valid combined scale
540* factor WORK( J, KK ) > 0.
541 rscal = one / scaloc
542 IF( xnrm( kk )*rscal .LE. bignum ) THEN
543 xnrm( kk ) = xnrm( kk ) * rscal
544 CALL csscal( j2-j1, rscal, x( j1, rhs ), 1 )
545 scaloc = one
546 ELSE
547* The system op(A) * x = b is badly scaled and its
548* solution cannot be represented as (1/scale) * x.
549* Set x to zero. This approach deviates from LATRS
550* where a completely meaningless non-zero vector
551* is returned that is not a solution to op(A) * x = b.
552 scale( rhs ) = zero
553 DO ii = 1, n
554 x( ii, kk ) = czero
555 END DO
556* Discard the local scale factors.
557 DO ii = 1, nba
558 work( ii+kk*lds ) = one
559 END DO
560 scaloc = one
561 END IF
562 END IF
563 scaloc = scaloc * work( j+kk*lds )
564 work( j+kk*lds ) = scaloc
565 END DO
566*
567* Linear block updates
568*
569 IF( notran ) THEN
570 IF( upper ) THEN
571 ifirst = j - 1
572 ilast = 1
573 iinc = -1
574 ELSE
575 ifirst = j + 1
576 ilast = nba
577 iinc = 1
578 END IF
579 ELSE
580 IF( upper ) THEN
581 ifirst = j + 1
582 ilast = nba
583 iinc = 1
584 ELSE
585 ifirst = j - 1
586 ilast = 1
587 iinc = -1
588 END IF
589 END IF
590*
591 DO i = ifirst, ilast, iinc
592* I1: row index of the first column in X( I, K )
593* I2: row index of the first column in X( I+1, K )
594* so the I2 - I1 is the row count of the block X( I, K )
595 i1 = (i-1)*nb + 1
596 i2 = min( i*nb, n ) + 1
597*
598* Prepare the linear update to be executed with GEMM.
599* For each column, compute a consistent scaling, a
600* scaling factor to survive the linear update, and
601* rescale the column segments, if necessary. Then
602* the linear update is safely executed.
603*
604 DO kk = 1, k2-k1
605 rhs = k1 + kk - 1
606* Compute consistent scaling
607 scamin = min( work( i+kk*lds), work( j+kk*lds ) )
608*
609* Compute scaling factor to survive the linear update
610* simulating consistent scaling.
611*
612 bnrm = clange( 'I', i2-i1, 1, x( i1, rhs ), ldx,
613 $ w )
614 bnrm = bnrm*( scamin / work( i+kk*lds ) )
615 xnrm( kk ) = xnrm( kk )*( scamin / work( j+kk*lds) )
616 anrm = work( awrk + i+(j-1)*nba )
617 scaloc = slarmm( anrm, xnrm( kk ), bnrm )
618*
619* Simultaneously apply the robust update factor and the
620* consistency scaling factor to X( I, KK ) and X( J, KK ).
621*
622 scal = ( scamin / work( i+kk*lds) )*scaloc
623 IF( scal.NE.one ) THEN
624 CALL csscal( i2-i1, scal, x( i1, rhs ), 1 )
625 work( i+kk*lds ) = scamin*scaloc
626 END IF
627*
628 scal = ( scamin / work( j+kk*lds ) )*scaloc
629 IF( scal.NE.one ) THEN
630 CALL csscal( j2-j1, scal, x( j1, rhs ), 1 )
631 work( j+kk*lds ) = scamin*scaloc
632 END IF
633 END DO
634*
635 IF( notran ) THEN
636*
637* B( I, K ) := B( I, K ) - A( I, J ) * X( J, K )
638*
639 CALL cgemm( 'N', 'N', i2-i1, k2-k1, j2-j1, -cone,
640 $ a( i1, j1 ), lda, x( j1, k1 ), ldx,
641 $ cone, x( i1, k1 ), ldx )
642 ELSE IF( lsame( trans, 'T' ) ) THEN
643*
644* B( I, K ) := B( I, K ) - A( I, J )**T * X( J, K )
645*
646 CALL cgemm( 'T', 'N', i2-i1, k2-k1, j2-j1, -cone,
647 $ a( j1, i1 ), lda, x( j1, k1 ), ldx,
648 $ cone, x( i1, k1 ), ldx )
649 ELSE
650*
651* B( I, K ) := B( I, K ) - A( I, J )**H * X( J, K )
652*
653 CALL cgemm( 'C', 'N', i2-i1, k2-k1, j2-j1, -cone,
654 $ a( j1, i1 ), lda, x( j1, k1 ), ldx,
655 $ cone, x( i1, k1 ), ldx )
656 END IF
657 END DO
658 END DO
659*
660* Reduce local scaling factors
661*
662 DO kk = 1, k2-k1
663 rhs = k1 + kk - 1
664 DO i = 1, nba
665 scale( rhs ) = min( scale( rhs ), work( i+kk*lds ) )
666 END DO
667 END DO
668*
669* Realize consistent scaling
670*
671 DO kk = 1, k2-k1
672 rhs = k1 + kk - 1
673 IF( scale( rhs ).NE.one .AND. scale( rhs ).NE. zero ) THEN
674 DO i = 1, nba
675 i1 = (i-1)*nb + 1
676 i2 = min( i*nb, n ) + 1
677 scal = scale( rhs ) / work( i+kk*lds )
678 IF( scal.NE.one )
679 $ CALL csscal( i2-i1, scal, x( i1, rhs ), 1 )
680 END DO
681 END IF
682 END DO
683 END DO
684*
685 work( 1 ) = sroundup_lwork( lwmin )
686*
687 RETURN
688*
689* End of CLATRS3
690*
subroutine xerbla(srname, info)
Definition cblat2.f:3285
subroutine cgemm(transa, transb, m, n, k, alpha, a, lda, b, ldb, beta, c, ldc)
CGEMM
Definition cgemm.f:188
integer function ilaenv(ispec, name, opts, n1, n2, n3, n4)
ILAENV
Definition ilaenv.f:160
real function slamch(cmach)
SLAMCH
Definition slamch.f:68
real function clange(norm, m, n, a, lda, work)
CLANGE returns the value of the 1-norm, Frobenius norm, infinity-norm, or the largest absolute value ...
Definition clange.f:113
real function slarmm(anorm, bnorm, cnorm)
SLARMM
Definition slarmm.f:61
subroutine clatrs(uplo, trans, diag, normin, n, a, lda, x, scale, cnorm, info)
CLATRS solves a triangular system of equations with the scale factor set to prevent overflow.
Definition clatrs.f:238
logical function lsame(ca, cb)
LSAME
Definition lsame.f:48
real function sroundup_lwork(lwork)
SROUNDUP_LWORK
subroutine csscal(n, sa, cx, incx)
CSSCAL
Definition csscal.f:78
Here is the call graph for this function:
Here is the caller graph for this function: