KTH framework for Nek5000 toolboxes; testing version  0.0.1
zlatrs.f
Go to the documentation of this file.
1  SUBROUTINE zlatrs( UPLO, TRANS, DIAG, NORMIN, N, A, LDA, X, SCALE,
2  $ CNORM, INFO )
3 *
4 * -- LAPACK auxiliary routine (version 3.0) --
5 * Univ. of Tennessee, Univ. of California Berkeley, NAG Ltd.,
6 * Courant Institute, Argonne National Lab, and Rice University
7 * June 30, 1992
8 *
9 * .. Scalar Arguments ..
10  CHARACTER DIAG, NORMIN, TRANS, UPLO
11  INTEGER INFO, LDA, N
12  DOUBLE PRECISION SCALE
13 * ..
14 * .. Array Arguments ..
15  DOUBLE PRECISION CNORM( * )
16  COMPLEX*16 A( LDA, * ), X( * )
17 * ..
18 *
19 * Purpose
20 * =======
21 *
22 * ZLATRS solves one of the triangular systems
23 *
24 * A * x = s*b, A**T * x = s*b, or A**H * x = s*b,
25 *
26 * with scaling to prevent overflow. Here A is an upper or lower
27 * triangular matrix, A**T denotes the transpose of A, A**H denotes the
28 * conjugate transpose of A, x and b are n-element vectors, and s is a
29 * scaling factor, usually less than or equal to 1, chosen so that the
30 * components of x will be less than the overflow threshold. If the
31 * unscaled problem will not cause overflow, the Level 2 BLAS routine
32 * ZTRSV is called. If the matrix A is singular (A(j,j) = 0 for some j),
33 * then s is set to 0 and a non-trivial solution to A*x = 0 is returned.
34 *
35 * Arguments
36 * =========
37 *
38 * UPLO (input) CHARACTER*1
39 * Specifies whether the matrix A is upper or lower triangular.
40 * = 'U': Upper triangular
41 * = 'L': Lower triangular
42 *
43 * TRANS (input) CHARACTER*1
44 * Specifies the operation applied to A.
45 * = 'N': Solve A * x = s*b (No transpose)
46 * = 'T': Solve A**T * x = s*b (Transpose)
47 * = 'C': Solve A**H * x = s*b (Conjugate transpose)
48 *
49 * DIAG (input) CHARACTER*1
50 * Specifies whether or not the matrix A is unit triangular.
51 * = 'N': Non-unit triangular
52 * = 'U': Unit triangular
53 *
54 * NORMIN (input) CHARACTER*1
55 * Specifies whether CNORM has been set or not.
56 * = 'Y': CNORM contains the column norms on entry
57 * = 'N': CNORM is not set on entry. On exit, the norms will
58 * be computed and stored in CNORM.
59 *
60 * N (input) INTEGER
61 * The order of the matrix A. N >= 0.
62 *
63 * A (input) COMPLEX*16 array, dimension (LDA,N)
64 * The triangular matrix A. If UPLO = 'U', the leading n by n
65 * upper triangular part of the array A contains the upper
66 * triangular matrix, and the strictly lower triangular part of
67 * A is not referenced. If UPLO = 'L', the leading n by n lower
68 * triangular part of the array A contains the lower triangular
69 * matrix, and the strictly upper triangular part of A is not
70 * referenced. If DIAG = 'U', the diagonal elements of A are
71 * also not referenced and are assumed to be 1.
72 *
73 * LDA (input) INTEGER
74 * The leading dimension of the array A. LDA >= max (1,N).
75 *
76 * X (input/output) COMPLEX*16 array, dimension (N)
77 * On entry, the right hand side b of the triangular system.
78 * On exit, X is overwritten by the solution vector x.
79 *
80 * SCALE (output) DOUBLE PRECISION
81 * The scaling factor s for the triangular system
82 * A * x = s*b, A**T * x = s*b, or A**H * x = s*b.
83 * If SCALE = 0, the matrix A is singular or badly scaled, and
84 * the vector x is an exact or approximate solution to A*x = 0.
85 *
86 * CNORM (input or output) DOUBLE PRECISION array, dimension (N)
87 *
88 * If NORMIN = 'Y', CNORM is an input argument and CNORM(j)
89 * contains the norm of the off-diagonal part of the j-th column
90 * of A. If TRANS = 'N', CNORM(j) must be greater than or equal
91 * to the infinity-norm, and if TRANS = 'T' or 'C', CNORM(j)
92 * must be greater than or equal to the 1-norm.
93 *
94 * If NORMIN = 'N', CNORM is an output argument and CNORM(j)
95 * returns the 1-norm of the offdiagonal part of the j-th column
96 * of A.
97 *
98 * INFO (output) INTEGER
99 * = 0: successful exit
100 * < 0: if INFO = -k, the k-th argument had an illegal value
101 *
102 * Further Details
103 * ======= =======
104 *
105 * A rough bound on x is computed; if that is less than overflow, ZTRSV
106 * is called, otherwise, specific code is used which checks for possible
107 * overflow or divide-by-zero at every operation.
108 *
109 * A columnwise scheme is used for solving A*x = b. The basic algorithm
110 * if A is lower triangular is
111 *
112 * x[1:n] := b[1:n]
113 * for j = 1, ..., n
114 * x(j) := x(j) / A(j,j)
115 * x[j+1:n] := x[j+1:n] - x(j) * A[j+1:n,j]
116 * end
117 *
118 * Define bounds on the components of x after j iterations of the loop:
119 * M(j) = bound on x[1:j]
120 * G(j) = bound on x[j+1:n]
121 * Initially, let M(0) = 0 and G(0) = max{x(i), i=1,...,n}.
122 *
123 * Then for iteration j+1 we have
124 * M(j+1) <= G(j) / | A(j+1,j+1) |
125 * G(j+1) <= G(j) + M(j+1) * | A[j+2:n,j+1] |
126 * <= G(j) ( 1 + CNORM(j+1) / | A(j+1,j+1) | )
127 *
128 * where CNORM(j+1) is greater than or equal to the infinity-norm of
129 * column j+1 of A, not counting the diagonal. Hence
130 *
131 * G(j) <= G(0) product ( 1 + CNORM(i) / | A(i,i) | )
132 * 1<=i<=j
133 * and
134 *
135 * |x(j)| <= ( G(0) / |A(j,j)| ) product ( 1 + CNORM(i) / |A(i,i)| )
136 * 1<=i< j
137 *
138 * Since |x(j)| <= M(j), we use the Level 2 BLAS routine ZTRSV if the
139 * reciprocal of the largest M(j), j=1,..,n, is larger than
140 * max(underflow, 1/overflow).
141 *
142 * The bound on x(j) is also used to determine when a step in the
143 * columnwise method can be performed without fear of overflow. If
144 * the computed bound is greater than a large constant, x is scaled to
145 * prevent overflow, but if the bound overflows, x is set to 0, x(j) to
146 * 1, and scale to 0, and a non-trivial solution to A*x = 0 is found.
147 *
148 * Similarly, a row-wise scheme is used to solve A**T *x = b or
149 * A**H *x = b. The basic algorithm for A upper triangular is
150 *
151 * for j = 1, ..., n
152 * x(j) := ( b(j) - A[1:j-1,j]' * x[1:j-1] ) / A(j,j)
153 * end
154 *
155 * We simultaneously compute two bounds
156 * G(j) = bound on ( b(i) - A[1:i-1,i]' * x[1:i-1] ), 1<=i<=j
157 * M(j) = bound on x(i), 1<=i<=j
158 *
159 * The initial values are G(0) = 0, M(0) = max{b(i), i=1,..,n}, and we
160 * add the constraint G(j) >= G(j-1) and M(j) >= M(j-1) for j >= 1.
161 * Then the bound on x(j) is
162 *
163 * M(j) <= M(j-1) * ( 1 + CNORM(j) ) / | A(j,j) |
164 *
165 * <= M(0) * product ( ( 1 + CNORM(i) ) / |A(i,i)| )
166 * 1<=i<=j
167 *
168 * and we can safely call ZTRSV if 1/M(n) and 1/G(n) are both greater
169 * than max(underflow, 1/overflow).
170 *
171 * =====================================================================
172 *
173 * .. Parameters ..
174  DOUBLE PRECISION ZERO, HALF, ONE, TWO
175  parameter( zero = 0.0d+0, half = 0.5d+0, one = 1.0d+0,
176  $ two = 2.0d+0 )
177 * ..
178 * .. Local Scalars ..
179  LOGICAL NOTRAN, NOUNIT, UPPER
180  INTEGER I, IMAX, J, JFIRST, JINC, JLAST
181  DOUBLE PRECISION BIGNUM, GROW, REC, SMLNUM, TJJ, TMAX, TSCAL,
182  $ xbnd, xj, xmax
183  COMPLEX*16 CSUMJ, TJJS, USCAL, ZDUM
184 * ..
185 * .. External Functions ..
186  LOGICAL LSAME
187  INTEGER IDAMAX, IZAMAX
188  DOUBLE PRECISION DLAMCH, DZASUM
189  COMPLEX*16 ZDOTC, ZDOTU, ZLADIV
190  EXTERNAL lsame, idamax, izamax, dlamch, dzasum, zdotc,
191  $ zdotu, zladiv
192 * ..
193 * .. External Subroutines ..
194  EXTERNAL dscal, xerbla, zaxpy, zdscal, ztrsv
195 * ..
196 * .. Intrinsic Functions ..
197  INTRINSIC abs, dble, dcmplx, dconjg, dimag, max, min
198 * ..
199 * .. Statement Functions ..
200  DOUBLE PRECISION CABS1, CABS2
201 * ..
202 * .. Statement Function definitions ..
203  cabs1( zdum ) = abs( dble( zdum ) ) + abs( dimag( zdum ) )
204  cabs2( zdum ) = abs( dble( zdum ) / 2.d0 ) +
205  $ abs( dimag( zdum ) / 2.d0 )
206 * ..
207 * .. Executable Statements ..
208 *
209  info = 0
210  upper = lsame( uplo, 'U' )
211  notran = lsame( trans, 'N' )
212  nounit = lsame( diag, 'N' )
213 *
214 * Test the input parameters.
215 *
216  IF( .NOT.upper .AND. .NOT.lsame( uplo, 'L' ) ) THEN
217  info = -1
218  ELSE IF( .NOT.notran .AND. .NOT.lsame( trans, 'T' ) .AND. .NOT.
219  $ lsame( trans, 'C' ) ) THEN
220  info = -2
221  ELSE IF( .NOT.nounit .AND. .NOT.lsame( diag, 'U' ) ) THEN
222  info = -3
223  ELSE IF( .NOT.lsame( normin, 'Y' ) .AND. .NOT.
224  $ lsame( normin, 'N' ) ) THEN
225  info = -4
226  ELSE IF( n.LT.0 ) THEN
227  info = -5
228  ELSE IF( lda.LT.max( 1, n ) ) THEN
229  info = -7
230  END IF
231  IF( info.NE.0 ) THEN
232  CALL xerbla( 'ZLATRS', -info )
233  RETURN
234  END IF
235 *
236 * Quick return if possible
237 *
238  IF( n.EQ.0 )
239  $ RETURN
240 *
241 * Determine machine dependent parameters to control overflow.
242 *
243  smlnum = dlamch( 'Safe minimum' )
244  bignum = one / smlnum
245  CALL dlabad( smlnum, bignum )
246  smlnum = smlnum / dlamch( 'Precision' )
247  bignum = one / smlnum
248  scale = one
249 *
250  IF( lsame( normin, 'N' ) ) THEN
251 *
252 * Compute the 1-norm of each column, not including the diagonal.
253 *
254  IF( upper ) THEN
255 *
256 * A is upper triangular.
257 *
258  DO 10 j = 1, n
259  cnorm( j ) = dzasum( j-1, a( 1, j ), 1 )
260  10 CONTINUE
261  ELSE
262 *
263 * A is lower triangular.
264 *
265  DO 20 j = 1, n - 1
266  cnorm( j ) = dzasum( n-j, a( j+1, j ), 1 )
267  20 CONTINUE
268  cnorm( n ) = zero
269  END IF
270  END IF
271 *
272 * Scale the column norms by TSCAL if the maximum element in CNORM is
273 * greater than BIGNUM/2.
274 *
275  imax = idamax( n, cnorm, 1 )
276  tmax = cnorm( imax )
277  IF( tmax.LE.bignum*half ) THEN
278  tscal = one
279  ELSE
280  tscal = half / ( smlnum*tmax )
281  CALL dscal( n, tscal, cnorm, 1 )
282  END IF
283 *
284 * Compute a bound on the computed solution vector to see if the
285 * Level 2 BLAS routine ZTRSV can be used.
286 *
287  xmax = zero
288  DO 30 j = 1, n
289  xmax = max( xmax, cabs2( x( j ) ) )
290  30 CONTINUE
291  xbnd = xmax
292 *
293  IF( notran ) THEN
294 *
295 * Compute the growth in A * x = b.
296 *
297  IF( upper ) THEN
298  jfirst = n
299  jlast = 1
300  jinc = -1
301  ELSE
302  jfirst = 1
303  jlast = n
304  jinc = 1
305  END IF
306 *
307  IF( tscal.NE.one ) THEN
308  grow = zero
309  GO TO 60
310  END IF
311 *
312  IF( nounit ) THEN
313 *
314 * A is non-unit triangular.
315 *
316 * Compute GROW = 1/G(j) and XBND = 1/M(j).
317 * Initially, G(0) = max{x(i), i=1,...,n}.
318 *
319  grow = half / max( xbnd, smlnum )
320  xbnd = grow
321  DO 40 j = jfirst, jlast, jinc
322 *
323 * Exit the loop if the growth factor is too small.
324 *
325  IF( grow.LE.smlnum )
326  $ GO TO 60
327 *
328  tjjs = a( j, j )
329  tjj = cabs1( tjjs )
330 *
331  IF( tjj.GE.smlnum ) THEN
332 *
333 * M(j) = G(j-1) / abs(A(j,j))
334 *
335  xbnd = min( xbnd, min( one, tjj )*grow )
336  ELSE
337 *
338 * M(j) could overflow, set XBND to 0.
339 *
340  xbnd = zero
341  END IF
342 *
343  IF( tjj+cnorm( j ).GE.smlnum ) THEN
344 *
345 * G(j) = G(j-1)*( 1 + CNORM(j) / abs(A(j,j)) )
346 *
347  grow = grow*( tjj / ( tjj+cnorm( j ) ) )
348  ELSE
349 *
350 * G(j) could overflow, set GROW to 0.
351 *
352  grow = zero
353  END IF
354  40 CONTINUE
355  grow = xbnd
356  ELSE
357 *
358 * A is unit triangular.
359 *
360 * Compute GROW = 1/G(j), where G(0) = max{x(i), i=1,...,n}.
361 *
362  grow = min( one, half / max( xbnd, smlnum ) )
363  DO 50 j = jfirst, jlast, jinc
364 *
365 * Exit the loop if the growth factor is too small.
366 *
367  IF( grow.LE.smlnum )
368  $ GO TO 60
369 *
370 * G(j) = G(j-1)*( 1 + CNORM(j) )
371 *
372  grow = grow*( one / ( one+cnorm( j ) ) )
373  50 CONTINUE
374  END IF
375  60 CONTINUE
376 *
377  ELSE
378 *
379 * Compute the growth in A**T * x = b or A**H * x = b.
380 *
381  IF( upper ) THEN
382  jfirst = 1
383  jlast = n
384  jinc = 1
385  ELSE
386  jfirst = n
387  jlast = 1
388  jinc = -1
389  END IF
390 *
391  IF( tscal.NE.one ) THEN
392  grow = zero
393  GO TO 90
394  END IF
395 *
396  IF( nounit ) THEN
397 *
398 * A is non-unit triangular.
399 *
400 * Compute GROW = 1/G(j) and XBND = 1/M(j).
401 * Initially, M(0) = max{x(i), i=1,...,n}.
402 *
403  grow = half / max( xbnd, smlnum )
404  xbnd = grow
405  DO 70 j = jfirst, jlast, jinc
406 *
407 * Exit the loop if the growth factor is too small.
408 *
409  IF( grow.LE.smlnum )
410  $ GO TO 90
411 *
412 * G(j) = max( G(j-1), M(j-1)*( 1 + CNORM(j) ) )
413 *
414  xj = one + cnorm( j )
415  grow = min( grow, xbnd / xj )
416 *
417  tjjs = a( j, j )
418  tjj = cabs1( tjjs )
419 *
420  IF( tjj.GE.smlnum ) THEN
421 *
422 * M(j) = M(j-1)*( 1 + CNORM(j) ) / abs(A(j,j))
423 *
424  IF( xj.GT.tjj )
425  $ xbnd = xbnd*( tjj / xj )
426  ELSE
427 *
428 * M(j) could overflow, set XBND to 0.
429 *
430  xbnd = zero
431  END IF
432  70 CONTINUE
433  grow = min( grow, xbnd )
434  ELSE
435 *
436 * A is unit triangular.
437 *
438 * Compute GROW = 1/G(j), where G(0) = max{x(i), i=1,...,n}.
439 *
440  grow = min( one, half / max( xbnd, smlnum ) )
441  DO 80 j = jfirst, jlast, jinc
442 *
443 * Exit the loop if the growth factor is too small.
444 *
445  IF( grow.LE.smlnum )
446  $ GO TO 90
447 *
448 * G(j) = ( 1 + CNORM(j) )*G(j-1)
449 *
450  xj = one + cnorm( j )
451  grow = grow / xj
452  80 CONTINUE
453  END IF
454  90 CONTINUE
455  END IF
456 *
457  IF( ( grow*tscal ).GT.smlnum ) THEN
458 *
459 * Use the Level 2 BLAS solve if the reciprocal of the bound on
460 * elements of X is not too small.
461 *
462  CALL ztrsv( uplo, trans, diag, n, a, lda, x, 1 )
463  ELSE
464 *
465 * Use a Level 1 BLAS solve, scaling intermediate results.
466 *
467  IF( xmax.GT.bignum*half ) THEN
468 *
469 * Scale X so that its components are less than or equal to
470 * BIGNUM in absolute value.
471 *
472  scale = ( bignum*half ) / xmax
473  CALL zdscal( n, scale, x, 1 )
474  xmax = bignum
475  ELSE
476  xmax = xmax*two
477  END IF
478 *
479  IF( notran ) THEN
480 *
481 * Solve A * x = b
482 *
483  DO 120 j = jfirst, jlast, jinc
484 *
485 * Compute x(j) = b(j) / A(j,j), scaling x if necessary.
486 *
487  xj = cabs1( x( j ) )
488  IF( nounit ) THEN
489  tjjs = a( j, j )*tscal
490  ELSE
491  tjjs = tscal
492  IF( tscal.EQ.one )
493  $ GO TO 110
494  END IF
495  tjj = cabs1( tjjs )
496  IF( tjj.GT.smlnum ) THEN
497 *
498 * abs(A(j,j)) > SMLNUM:
499 *
500  IF( tjj.LT.one ) THEN
501  IF( xj.GT.tjj*bignum ) THEN
502 *
503 * Scale x by 1/b(j).
504 *
505  rec = one / xj
506  CALL zdscal( n, rec, x, 1 )
507  scale = scale*rec
508  xmax = xmax*rec
509  END IF
510  END IF
511  x( j ) = zladiv( x( j ), tjjs )
512  xj = cabs1( x( j ) )
513  ELSE IF( tjj.GT.zero ) THEN
514 *
515 * 0 < abs(A(j,j)) <= SMLNUM:
516 *
517  IF( xj.GT.tjj*bignum ) THEN
518 *
519 * Scale x by (1/abs(x(j)))*abs(A(j,j))*BIGNUM
520 * to avoid overflow when dividing by A(j,j).
521 *
522  rec = ( tjj*bignum ) / xj
523  IF( cnorm( j ).GT.one ) THEN
524 *
525 * Scale by 1/CNORM(j) to avoid overflow when
526 * multiplying x(j) times column j.
527 *
528  rec = rec / cnorm( j )
529  END IF
530  CALL zdscal( n, rec, x, 1 )
531  scale = scale*rec
532  xmax = xmax*rec
533  END IF
534  x( j ) = zladiv( x( j ), tjjs )
535  xj = cabs1( x( j ) )
536  ELSE
537 *
538 * A(j,j) = 0: Set x(1:n) = 0, x(j) = 1, and
539 * scale = 0, and compute a solution to A*x = 0.
540 *
541  DO 100 i = 1, n
542  x( i ) = zero
543  100 CONTINUE
544  x( j ) = one
545  xj = one
546  scale = zero
547  xmax = zero
548  END IF
549  110 CONTINUE
550 *
551 * Scale x if necessary to avoid overflow when adding a
552 * multiple of column j of A.
553 *
554  IF( xj.GT.one ) THEN
555  rec = one / xj
556  IF( cnorm( j ).GT.( bignum-xmax )*rec ) THEN
557 *
558 * Scale x by 1/(2*abs(x(j))).
559 *
560  rec = rec*half
561  CALL zdscal( n, rec, x, 1 )
562  scale = scale*rec
563  END IF
564  ELSE IF( xj*cnorm( j ).GT.( bignum-xmax ) ) THEN
565 *
566 * Scale x by 1/2.
567 *
568  CALL zdscal( n, half, x, 1 )
569  scale = scale*half
570  END IF
571 *
572  IF( upper ) THEN
573  IF( j.GT.1 ) THEN
574 *
575 * Compute the update
576 * x(1:j-1) := x(1:j-1) - x(j) * A(1:j-1,j)
577 *
578  CALL zaxpy( j-1, -x( j )*tscal, a( 1, j ), 1, x,
579  $ 1 )
580  i = izamax( j-1, x, 1 )
581  xmax = cabs1( x( i ) )
582  END IF
583  ELSE
584  IF( j.LT.n ) THEN
585 *
586 * Compute the update
587 * x(j+1:n) := x(j+1:n) - x(j) * A(j+1:n,j)
588 *
589  CALL zaxpy( n-j, -x( j )*tscal, a( j+1, j ), 1,
590  $ x( j+1 ), 1 )
591  i = j + izamax( n-j, x( j+1 ), 1 )
592  xmax = cabs1( x( i ) )
593  END IF
594  END IF
595  120 CONTINUE
596 *
597  ELSE IF( lsame( trans, 'T' ) ) THEN
598 *
599 * Solve A**T * x = b
600 *
601  DO 170 j = jfirst, jlast, jinc
602 *
603 * Compute x(j) = b(j) - sum A(k,j)*x(k).
604 * k<>j
605 *
606  xj = cabs1( x( j ) )
607  uscal = tscal
608  rec = one / max( xmax, one )
609  IF( cnorm( j ).GT.( bignum-xj )*rec ) THEN
610 *
611 * If x(j) could overflow, scale x by 1/(2*XMAX).
612 *
613  rec = rec*half
614  IF( nounit ) THEN
615  tjjs = a( j, j )*tscal
616  ELSE
617  tjjs = tscal
618  END IF
619  tjj = cabs1( tjjs )
620  IF( tjj.GT.one ) THEN
621 *
622 * Divide by A(j,j) when scaling x if A(j,j) > 1.
623 *
624  rec = min( one, rec*tjj )
625  uscal = zladiv( uscal, tjjs )
626  END IF
627  IF( rec.LT.one ) THEN
628  CALL zdscal( n, rec, x, 1 )
629  scale = scale*rec
630  xmax = xmax*rec
631  END IF
632  END IF
633 *
634  csumj = zero
635  IF( uscal.EQ.dcmplx( one ) ) THEN
636 *
637 * If the scaling needed for A in the dot product is 1,
638 * call ZDOTU to perform the dot product.
639 *
640  IF( upper ) THEN
641  csumj = zdotu( j-1, a( 1, j ), 1, x, 1 )
642  ELSE IF( j.LT.n ) THEN
643  csumj = zdotu( n-j, a( j+1, j ), 1, x( j+1 ), 1 )
644  END IF
645  ELSE
646 *
647 * Otherwise, use in-line code for the dot product.
648 *
649  IF( upper ) THEN
650  DO 130 i = 1, j - 1
651  csumj = csumj + ( a( i, j )*uscal )*x( i )
652  130 CONTINUE
653  ELSE IF( j.LT.n ) THEN
654  DO 140 i = j + 1, n
655  csumj = csumj + ( a( i, j )*uscal )*x( i )
656  140 CONTINUE
657  END IF
658  END IF
659 *
660  IF( uscal.EQ.dcmplx( tscal ) ) THEN
661 *
662 * Compute x(j) := ( x(j) - CSUMJ ) / A(j,j) if 1/A(j,j)
663 * was not used to scale the dotproduct.
664 *
665  x( j ) = x( j ) - csumj
666  xj = cabs1( x( j ) )
667  IF( nounit ) THEN
668  tjjs = a( j, j )*tscal
669  ELSE
670  tjjs = tscal
671  IF( tscal.EQ.one )
672  $ GO TO 160
673  END IF
674 *
675 * Compute x(j) = x(j) / A(j,j), scaling if necessary.
676 *
677  tjj = cabs1( tjjs )
678  IF( tjj.GT.smlnum ) THEN
679 *
680 * abs(A(j,j)) > SMLNUM:
681 *
682  IF( tjj.LT.one ) THEN
683  IF( xj.GT.tjj*bignum ) THEN
684 *
685 * Scale X by 1/abs(x(j)).
686 *
687  rec = one / xj
688  CALL zdscal( n, rec, x, 1 )
689  scale = scale*rec
690  xmax = xmax*rec
691  END IF
692  END IF
693  x( j ) = zladiv( x( j ), tjjs )
694  ELSE IF( tjj.GT.zero ) THEN
695 *
696 * 0 < abs(A(j,j)) <= SMLNUM:
697 *
698  IF( xj.GT.tjj*bignum ) THEN
699 *
700 * Scale x by (1/abs(x(j)))*abs(A(j,j))*BIGNUM.
701 *
702  rec = ( tjj*bignum ) / xj
703  CALL zdscal( n, rec, x, 1 )
704  scale = scale*rec
705  xmax = xmax*rec
706  END IF
707  x( j ) = zladiv( x( j ), tjjs )
708  ELSE
709 *
710 * A(j,j) = 0: Set x(1:n) = 0, x(j) = 1, and
711 * scale = 0 and compute a solution to A**T *x = 0.
712 *
713  DO 150 i = 1, n
714  x( i ) = zero
715  150 CONTINUE
716  x( j ) = one
717  scale = zero
718  xmax = zero
719  END IF
720  160 CONTINUE
721  ELSE
722 *
723 * Compute x(j) := x(j) / A(j,j) - CSUMJ if the dot
724 * product has already been divided by 1/A(j,j).
725 *
726  x( j ) = zladiv( x( j ), tjjs ) - csumj
727  END IF
728  xmax = max( xmax, cabs1( x( j ) ) )
729  170 CONTINUE
730 *
731  ELSE
732 *
733 * Solve A**H * x = b
734 *
735  DO 220 j = jfirst, jlast, jinc
736 *
737 * Compute x(j) = b(j) - sum A(k,j)*x(k).
738 * k<>j
739 *
740  xj = cabs1( x( j ) )
741  uscal = tscal
742  rec = one / max( xmax, one )
743  IF( cnorm( j ).GT.( bignum-xj )*rec ) THEN
744 *
745 * If x(j) could overflow, scale x by 1/(2*XMAX).
746 *
747  rec = rec*half
748  IF( nounit ) THEN
749  tjjs = dconjg( a( j, j ) )*tscal
750  ELSE
751  tjjs = tscal
752  END IF
753  tjj = cabs1( tjjs )
754  IF( tjj.GT.one ) THEN
755 *
756 * Divide by A(j,j) when scaling x if A(j,j) > 1.
757 *
758  rec = min( one, rec*tjj )
759  uscal = zladiv( uscal, tjjs )
760  END IF
761  IF( rec.LT.one ) THEN
762  CALL zdscal( n, rec, x, 1 )
763  scale = scale*rec
764  xmax = xmax*rec
765  END IF
766  END IF
767 *
768  csumj = zero
769  IF( uscal.EQ.dcmplx( one ) ) THEN
770 *
771 * If the scaling needed for A in the dot product is 1,
772 * call ZDOTC to perform the dot product.
773 *
774  IF( upper ) THEN
775  csumj = zdotc( j-1, a( 1, j ), 1, x, 1 )
776  ELSE IF( j.LT.n ) THEN
777  csumj = zdotc( n-j, a( j+1, j ), 1, x( j+1 ), 1 )
778  END IF
779  ELSE
780 *
781 * Otherwise, use in-line code for the dot product.
782 *
783  IF( upper ) THEN
784  DO 180 i = 1, j - 1
785  csumj = csumj + ( dconjg( a( i, j ) )*uscal )*
786  $ x( i )
787  180 CONTINUE
788  ELSE IF( j.LT.n ) THEN
789  DO 190 i = j + 1, n
790  csumj = csumj + ( dconjg( a( i, j ) )*uscal )*
791  $ x( i )
792  190 CONTINUE
793  END IF
794  END IF
795 *
796  IF( uscal.EQ.dcmplx( tscal ) ) THEN
797 *
798 * Compute x(j) := ( x(j) - CSUMJ ) / A(j,j) if 1/A(j,j)
799 * was not used to scale the dotproduct.
800 *
801  x( j ) = x( j ) - csumj
802  xj = cabs1( x( j ) )
803  IF( nounit ) THEN
804  tjjs = dconjg( a( j, j ) )*tscal
805  ELSE
806  tjjs = tscal
807  IF( tscal.EQ.one )
808  $ GO TO 210
809  END IF
810 *
811 * Compute x(j) = x(j) / A(j,j), scaling if necessary.
812 *
813  tjj = cabs1( tjjs )
814  IF( tjj.GT.smlnum ) THEN
815 *
816 * abs(A(j,j)) > SMLNUM:
817 *
818  IF( tjj.LT.one ) THEN
819  IF( xj.GT.tjj*bignum ) THEN
820 *
821 * Scale X by 1/abs(x(j)).
822 *
823  rec = one / xj
824  CALL zdscal( n, rec, x, 1 )
825  scale = scale*rec
826  xmax = xmax*rec
827  END IF
828  END IF
829  x( j ) = zladiv( x( j ), tjjs )
830  ELSE IF( tjj.GT.zero ) THEN
831 *
832 * 0 < abs(A(j,j)) <= SMLNUM:
833 *
834  IF( xj.GT.tjj*bignum ) THEN
835 *
836 * Scale x by (1/abs(x(j)))*abs(A(j,j))*BIGNUM.
837 *
838  rec = ( tjj*bignum ) / xj
839  CALL zdscal( n, rec, x, 1 )
840  scale = scale*rec
841  xmax = xmax*rec
842  END IF
843  x( j ) = zladiv( x( j ), tjjs )
844  ELSE
845 *
846 * A(j,j) = 0: Set x(1:n) = 0, x(j) = 1, and
847 * scale = 0 and compute a solution to A**H *x = 0.
848 *
849  DO 200 i = 1, n
850  x( i ) = zero
851  200 CONTINUE
852  x( j ) = one
853  scale = zero
854  xmax = zero
855  END IF
856  210 CONTINUE
857  ELSE
858 *
859 * Compute x(j) := x(j) / A(j,j) - CSUMJ if the dot
860 * product has already been divided by 1/A(j,j).
861 *
862  x( j ) = zladiv( x( j ), tjjs ) - csumj
863  END IF
864  xmax = max( xmax, cabs1( x( j ) ) )
865  220 CONTINUE
866  END IF
867  scale = scale / tscal
868  END IF
869 *
870 * Scale the column norms by 1/TSCAL for return.
871 *
872  IF( tscal.NE.one ) THEN
873  CALL dscal( n, one / tscal, cnorm, 1 )
874  END IF
875 *
876  RETURN
877 *
878 * End of ZLATRS
879 *
880  END
subroutine dlabad(SMALL, LARGE)
Definition: dlabad.f:2
subroutine dscal(n, da, dx, incx)
Definition: dscal.f:2
subroutine xerbla(SRNAME, INFO)
Definition: xerbla.f:2
subroutine zaxpy(n, za, zx, incx, zy, incy)
Definition: zaxpy.f:2
subroutine zdscal(n, da, zx, incx)
Definition: zdscal.f:2
subroutine zlatrs(UPLO, TRANS, DIAG, NORMIN, N, A, LDA, X, SCALE, CNORM, INFO)
Definition: zlatrs.f:3
subroutine ztrsv(UPLO, TRANS, DIAG, N, A, LDA, X, INCX)
Definition: ztrsv.f:2