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
clacn2.f
Go to the documentation of this file.
1  SUBROUTINE clacn2( N, V, X, EST, KASE, ISAVE )
2 *
3 * -- LAPACK auxiliary routine (version 3.2) --
4 * Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd..
5 * November 2006
6 *
7 * .. Scalar Arguments ..
8  INTEGER kase, n
9  REAL est
10 * ..
11 * .. Array Arguments ..
12  INTEGER isave( 3 )
13  COMPLEX v( * ), x( * )
14 * ..
15 *
16 * Purpose
17 * =======
18 *
19 * CLACN2 estimates the 1-norm of a square, complex matrix A.
20 * Reverse communication is used for evaluating matrix-vector products.
21 *
22 * Arguments
23 * =========
24 *
25 * N (input) INTEGER
26 * The order of the matrix. N >= 1.
27 *
28 * V (workspace) COMPLEX array, dimension (N)
29 * On the final return, V = A*W, where EST = norm(V)/norm(W)
30 * (W is not returned).
31 *
32 * X (input/output) COMPLEX array, dimension (N)
33 * On an intermediate return, X should be overwritten by
34 * A * X, if KASE=1,
35 * A' * X, if KASE=2,
36 * where A' is the conjugate transpose of A, and CLACN2 must be
37 * re-called with all the other parameters unchanged.
38 *
39 * EST (input/output) REAL
40 * On entry with KASE = 1 or 2 and ISAVE(1) = 3, EST should be
41 * unchanged from the previous call to CLACN2.
42 * On exit, EST is an estimate (a lower bound) for norm(A).
43 *
44 * KASE (input/output) INTEGER
45 * On the initial call to CLACN2, KASE should be 0.
46 * On an intermediate return, KASE will be 1 or 2, indicating
47 * whether X should be overwritten by A * X or A' * X.
48 * On the final return from CLACN2, KASE will again be 0.
49 *
50 * ISAVE (input/output) INTEGER array, dimension (3)
51 * ISAVE is used to save variables between calls to SLACN2
52 *
53 * Further Details
54 * ======= =======
55 *
56 * Contributed by Nick Higham, University of Manchester.
57 * Originally named CONEST, dated March 16, 1988.
58 *
59 * Reference: N.J. Higham, "FORTRAN codes for estimating the one-norm of
60 * a real or complex matrix, with applications to condition estimation",
61 * ACM Trans. Math. Soft., vol. 14, no. 4, pp. 381-396, December 1988.
62 *
63 * Last modified: April, 1999
64 *
65 * This is a thread safe version of CLACON, which uses the array ISAVE
66 * in place of a SAVE statement, as follows:
67 *
68 * CLACON CLACN2
69 * JUMP ISAVE(1)
70 * J ISAVE(2)
71 * ITER ISAVE(3)
72 *
73 * =====================================================================
74 *
75 * .. Parameters ..
76  INTEGER itmax
77  parameter( itmax = 5 )
78  REAL one, two
79  parameter( one = 1.0e0, two = 2.0e0 )
80  COMPLEX czero, cone
81  parameter( czero = ( 0.0e0, 0.0e0 ),
82  $ cone = ( 1.0e0, 0.0e0 ) )
83 * ..
84 * .. Local Scalars ..
85  INTEGER i, jlast
86  REAL absxi, altsgn, estold, safmin, temp
87 * ..
88 * .. External Functions ..
89  INTEGER icmax1
90  REAL scsum1, slamch
91  EXTERNAL icmax1, scsum1, slamch
92 * ..
93 * .. External Subroutines ..
94  EXTERNAL ccopy
95 * ..
96 * .. Intrinsic Functions ..
97  INTRINSIC abs, aimag, cmplx, real
98 * ..
99 * .. Executable Statements ..
100 *
101  safmin = slamch( 'Safe minimum' )
102  IF( kase.EQ.0 ) THEN
103  DO 10 i = 1, n
104  x( i ) = cmplx( one / REAL( N ) )
105  10 continue
106  kase = 1
107  isave( 1 ) = 1
108  return
109  END IF
110 *
111  go to( 20, 40, 70, 90, 120 )isave( 1 )
112 *
113 * ................ ENTRY (ISAVE( 1 ) = 1)
114 * FIRST ITERATION. X HAS BEEN OVERWRITTEN BY A*X.
115 *
116  20 continue
117  IF( n.EQ.1 ) THEN
118  v( 1 ) = x( 1 )
119  est = abs( v( 1 ) )
120 * ... QUIT
121  go to 130
122  END IF
123  est = scsum1( n, x, 1 )
124 *
125  DO 30 i = 1, n
126  absxi = abs( x( i ) )
127  IF( absxi.GT.safmin ) THEN
128  x( i ) = cmplx( REAL( X( I ) ) / absxi,
129  $ aimag( x( i ) ) / absxi )
130  ELSE
131  x( i ) = cone
132  END IF
133  30 continue
134  kase = 2
135  isave( 1 ) = 2
136  return
137 *
138 * ................ ENTRY (ISAVE( 1 ) = 2)
139 * FIRST ITERATION. X HAS BEEN OVERWRITTEN BY CTRANS(A)*X.
140 *
141  40 continue
142  isave( 2 ) = icmax1( n, x, 1 )
143  isave( 3 ) = 2
144 *
145 * MAIN LOOP - ITERATIONS 2,3,...,ITMAX.
146 *
147  50 continue
148  DO 60 i = 1, n
149  x( i ) = czero
150  60 continue
151  x( isave( 2 ) ) = cone
152  kase = 1
153  isave( 1 ) = 3
154  return
155 *
156 * ................ ENTRY (ISAVE( 1 ) = 3)
157 * X HAS BEEN OVERWRITTEN BY A*X.
158 *
159  70 continue
160  CALL ccopy( n, x, 1, v, 1 )
161  estold = est
162  est = scsum1( n, v, 1 )
163 *
164 * TEST FOR CYCLING.
165  IF( est.LE.estold )
166  $ go to 100
167 *
168  DO 80 i = 1, n
169  absxi = abs( x( i ) )
170  IF( absxi.GT.safmin ) THEN
171  x( i ) = cmplx( REAL( X( I ) ) / absxi,
172  $ aimag( x( i ) ) / absxi )
173  ELSE
174  x( i ) = cone
175  END IF
176  80 continue
177  kase = 2
178  isave( 1 ) = 4
179  return
180 *
181 * ................ ENTRY (ISAVE( 1 ) = 4)
182 * X HAS BEEN OVERWRITTEN BY CTRANS(A)*X.
183 *
184  90 continue
185  jlast = isave( 2 )
186  isave( 2 ) = icmax1( n, x, 1 )
187  IF( ( abs( x( jlast ) ).NE.abs( x( isave( 2 ) ) ) ) .AND.
188  $ ( isave( 3 ).LT.itmax ) ) THEN
189  isave( 3 ) = isave( 3 ) + 1
190  go to 50
191  END IF
192 *
193 * ITERATION COMPLETE. FINAL STAGE.
194 *
195  100 continue
196  altsgn = one
197  DO 110 i = 1, n
198  x( i ) = cmplx( altsgn*( one + REAL( I-1 ) / REAL( N-1 ) ) )
199  altsgn = -altsgn
200  110 continue
201  kase = 1
202  isave( 1 ) = 5
203  return
204 *
205 * ................ ENTRY (ISAVE( 1 ) = 5)
206 * X HAS BEEN OVERWRITTEN BY A*X.
207 *
208  120 continue
209  temp = two*( scsum1( n, x, 1 ) / REAL( 3*N ) )
210  IF( temp.GT.est ) THEN
211  CALL ccopy( n, x, 1, v, 1 )
212  est = temp
213  END IF
214 *
215  130 continue
216  kase = 0
217  return
218 *
219 * End of CLACN2
220 *
221  END