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