PLASMA  2.4.5
PLASMA - Parallel Linear Algebra for Scalable Multi-core Architectures
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups
cgeequ.f
Go to the documentation of this file.
1  SUBROUTINE cgeequ( M, N, A, LDA, R, C, ROWCND, COLCND, AMAX,
2  $ info )
3 *
4 * -- LAPACK routine (version 3.2) --
5 * Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd..
6 * November 2006
7 *
8 * .. Scalar Arguments ..
9  INTEGER info, lda, m, n
10  REAL amax, colcnd, rowcnd
11 * ..
12 * .. Array Arguments ..
13  REAL c( * ), r( * )
14  COMPLEX a( lda, * )
15 * ..
16 *
17 * Purpose
18 * =======
19 *
20 * CGEEQU computes row and column scalings intended to equilibrate an
21 * M-by-N matrix A and reduce its condition number. R returns the row
22 * scale factors and C the column scale factors, chosen to try to make
23 * the largest element in each row and column of the matrix B with
24 * elements B(i,j)=R(i)*A(i,j)*C(j) have absolute value 1.
25 *
26 * R(i) and C(j) are restricted to be between SMLNUM = smallest safe
27 * number and BIGNUM = largest safe number. Use of these scaling
28 * factors is not guaranteed to reduce the condition number of A but
29 * works well in practice.
30 *
31 * Arguments
32 * =========
33 *
34 * M (input) INTEGER
35 * The number of rows of the matrix A. M >= 0.
36 *
37 * N (input) INTEGER
38 * The number of columns of the matrix A. N >= 0.
39 *
40 * A (input) COMPLEX array, dimension (LDA,N)
41 * The M-by-N matrix whose equilibration factors are
42 * to be computed.
43 *
44 * LDA (input) INTEGER
45 * The leading dimension of the array A. LDA >= max(1,M).
46 *
47 * R (output) REAL array, dimension (M)
48 * If INFO = 0 or INFO > M, R contains the row scale factors
49 * for A.
50 *
51 * C (output) REAL array, dimension (N)
52 * If INFO = 0, C contains the column scale factors for A.
53 *
54 * ROWCND (output) REAL
55 * If INFO = 0 or INFO > M, ROWCND contains the ratio of the
56 * smallest R(i) to the largest R(i). If ROWCND >= 0.1 and
57 * AMAX is neither too large nor too small, it is not worth
58 * scaling by R.
59 *
60 * COLCND (output) REAL
61 * If INFO = 0, COLCND contains the ratio of the smallest
62 * C(i) to the largest C(i). If COLCND >= 0.1, it is not
63 * worth scaling by C.
64 *
65 * AMAX (output) REAL
66 * Absolute value of largest matrix element. If AMAX is very
67 * close to overflow or very close to underflow, the matrix
68 * should be scaled.
69 *
70 * INFO (output) INTEGER
71 * = 0: successful exit
72 * < 0: if INFO = -i, the i-th argument had an illegal value
73 * > 0: if INFO = i, and i is
74 * <= M: the i-th row of A is exactly zero
75 * > M: the (i-M)-th column of A is exactly zero
76 *
77 * =====================================================================
78 *
79 * .. Parameters ..
80  REAL one, zero
81  parameter( one = 1.0e+0, zero = 0.0e+0 )
82 * ..
83 * .. Local Scalars ..
84  INTEGER i, j
85  REAL bignum, rcmax, rcmin, smlnum
86  COMPLEX zdum
87 * ..
88 * .. External Functions ..
89  REAL slamch
90  EXTERNAL slamch
91 * ..
92 * .. External Subroutines ..
93  EXTERNAL xerbla
94 * ..
95 * .. Intrinsic Functions ..
96  INTRINSIC abs, aimag, max, min, real
97 * ..
98 * .. Statement Functions ..
99  REAL cabs1
100 * ..
101 * .. Statement Function definitions ..
102  cabs1( zdum ) = abs( REAL( ZDUM ) ) + abs( aimag( zdum ) )
103 * ..
104 * .. Executable Statements ..
105 *
106 * Test the input parameters.
107 *
108  info = 0
109  IF( m.LT.0 ) THEN
110  info = -1
111  ELSE IF( n.LT.0 ) THEN
112  info = -2
113  ELSE IF( lda.LT.max( 1, m ) ) THEN
114  info = -4
115  END IF
116  IF( info.NE.0 ) THEN
117  CALL xerbla( 'CGEEQU', -info )
118  return
119  END IF
120 *
121 * Quick return if possible
122 *
123  IF( m.EQ.0 .OR. n.EQ.0 ) THEN
124  rowcnd = one
125  colcnd = one
126  amax = zero
127  return
128  END IF
129 *
130 * Get machine constants.
131 *
132  smlnum = slamch( 'S' )
133  bignum = one / smlnum
134 *
135 * Compute row scale factors.
136 *
137  DO 10 i = 1, m
138  r( i ) = zero
139  10 continue
140 *
141 * Find the maximum element in each row.
142 *
143  DO 30 j = 1, n
144  DO 20 i = 1, m
145  r( i ) = max( r( i ), cabs1( a( i, j ) ) )
146  20 continue
147  30 continue
148 *
149 * Find the maximum and minimum scale factors.
150 *
151  rcmin = bignum
152  rcmax = zero
153  DO 40 i = 1, m
154  rcmax = max( rcmax, r( i ) )
155  rcmin = min( rcmin, r( i ) )
156  40 continue
157  amax = rcmax
158 *
159  IF( rcmin.EQ.zero ) THEN
160 *
161 * Find the first zero scale factor and return an error code.
162 *
163  DO 50 i = 1, m
164  IF( r( i ).EQ.zero ) THEN
165  info = i
166  return
167  END IF
168  50 continue
169  ELSE
170 *
171 * Invert the scale factors.
172 *
173  DO 60 i = 1, m
174  r( i ) = one / min( max( r( i ), smlnum ), bignum )
175  60 continue
176 *
177 * Compute ROWCND = min(R(I)) / max(R(I))
178 *
179  rowcnd = max( rcmin, smlnum ) / min( rcmax, bignum )
180  END IF
181 *
182 * Compute column scale factors
183 *
184  DO 70 j = 1, n
185  c( j ) = zero
186  70 continue
187 *
188 * Find the maximum element in each column,
189 * assuming the row scaling computed above.
190 *
191  DO 90 j = 1, n
192  DO 80 i = 1, m
193  c( j ) = max( c( j ), cabs1( a( i, j ) )*r( i ) )
194  80 continue
195  90 continue
196 *
197 * Find the maximum and minimum scale factors.
198 *
199  rcmin = bignum
200  rcmax = zero
201  DO 100 j = 1, n
202  rcmin = min( rcmin, c( j ) )
203  rcmax = max( rcmax, c( j ) )
204  100 continue
205 *
206  IF( rcmin.EQ.zero ) THEN
207 *
208 * Find the first zero scale factor and return an error code.
209 *
210  DO 110 j = 1, n
211  IF( c( j ).EQ.zero ) THEN
212  info = m + j
213  return
214  END IF
215  110 continue
216  ELSE
217 *
218 * Invert the scale factors.
219 *
220  DO 120 j = 1, n
221  c( j ) = one / min( max( c( j ), smlnum ), bignum )
222  120 continue
223 *
224 * Compute COLCND = min(C(J)) / max(C(J))
225 *
226  colcnd = max( rcmin, smlnum ) / min( rcmax, bignum )
227  END IF
228 *
229  return
230 *
231 * End of CGEEQU
232 *
233  END