LAPACK 3.12.1
LAPACK: Linear Algebra PACKage
Loading...
Searching...
No Matches
zcgesv.f
Go to the documentation of this file.
1*> \brief <b> ZCGESV computes the solution to system of linear equations A * X = B for GE matrices</b> (mixed precision with iterative refinement)
2*
3* =========== DOCUMENTATION ===========
4*
5* Online html documentation available at
6* http://www.netlib.org/lapack/explore-html/
7*
8*> Download ZCGESV + dependencies
9*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/zcgesv.f">
10*> [TGZ]</a>
11*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/zcgesv.f">
12*> [ZIP]</a>
13*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/zcgesv.f">
14*> [TXT]</a>
15*
16* Definition:
17* ===========
18*
19* SUBROUTINE ZCGESV( N, NRHS, A, LDA, IPIV, B, LDB, X, LDX, WORK,
20* SWORK, RWORK, ITER, INFO )
21*
22* .. Scalar Arguments ..
23* INTEGER INFO, ITER, LDA, LDB, LDX, N, NRHS
24* ..
25* .. Array Arguments ..
26* INTEGER IPIV( * )
27* DOUBLE PRECISION RWORK( * )
28* COMPLEX SWORK( * )
29* COMPLEX*16 A( LDA, * ), B( LDB, * ), WORK( N, * ),
30* $ X( LDX, * )
31* ..
32*
33*
34*> \par Purpose:
35* =============
36*>
37*> \verbatim
38*>
39*> ZCGESV computes the solution to a complex system of linear equations
40*> A * X = B,
41*> where A is an N-by-N matrix and X and B are N-by-NRHS matrices.
42*>
43*> ZCGESV first attempts to factorize the matrix in COMPLEX and use this
44*> factorization within an iterative refinement procedure to produce a
45*> solution with COMPLEX*16 normwise backward error quality (see below).
46*> If the approach fails the method switches to a COMPLEX*16
47*> factorization and solve.
48*>
49*> The iterative refinement is not going to be a winning strategy if
50*> the ratio COMPLEX performance over COMPLEX*16 performance is too
51*> small. A reasonable strategy should take the number of right-hand
52*> sides and the size of the matrix into account. This might be done
53*> with a call to ILAENV in the future. Up to now, we always try
54*> iterative refinement.
55*>
56*> The iterative refinement process is stopped if
57*> ITER > ITERMAX
58*> or for all the RHS we have:
59*> RNRM < SQRT(N)*XNRM*ANRM*EPS*BWDMAX
60*> where
61*> o ITER is the number of the current iteration in the iterative
62*> refinement process
63*> o RNRM is the infinity-norm of the residual
64*> o XNRM is the infinity-norm of the solution
65*> o ANRM is the infinity-operator-norm of the matrix A
66*> o EPS is the machine epsilon returned by DLAMCH('Epsilon')
67*> The value ITERMAX and BWDMAX are fixed to 30 and 1.0D+00
68*> respectively.
69*> \endverbatim
70*
71* Arguments:
72* ==========
73*
74*> \param[in] N
75*> \verbatim
76*> N is INTEGER
77*> The number of linear equations, i.e., the order of the
78*> matrix A. N >= 0.
79*> \endverbatim
80*>
81*> \param[in] NRHS
82*> \verbatim
83*> NRHS is INTEGER
84*> The number of right hand sides, i.e., the number of columns
85*> of the matrix B. NRHS >= 0.
86*> \endverbatim
87*>
88*> \param[in,out] A
89*> \verbatim
90*> A is COMPLEX*16 array,
91*> dimension (LDA,N)
92*> On entry, the N-by-N coefficient matrix A.
93*> On exit, if iterative refinement has been successfully used
94*> (INFO = 0 and ITER >= 0, see description below), then A is
95*> unchanged, if double precision factorization has been used
96*> (INFO = 0 and ITER < 0, see description below), then the
97*> array A contains the factors L and U from the factorization
98*> A = P*L*U; the unit diagonal elements of L are not stored.
99*> \endverbatim
100*>
101*> \param[in] LDA
102*> \verbatim
103*> LDA is INTEGER
104*> The leading dimension of the array A. LDA >= max(1,N).
105*> \endverbatim
106*>
107*> \param[out] IPIV
108*> \verbatim
109*> IPIV is INTEGER array, dimension (N)
110*> The pivot indices that define the permutation matrix P;
111*> row i of the matrix was interchanged with row IPIV(i).
112*> Corresponds either to the single precision factorization
113*> (if INFO = 0 and ITER >= 0) or the double precision
114*> factorization (if INFO = 0 and ITER < 0).
115*> \endverbatim
116*>
117*> \param[in] B
118*> \verbatim
119*> B is COMPLEX*16 array, dimension (LDB,NRHS)
120*> The N-by-NRHS right hand side matrix B.
121*> \endverbatim
122*>
123*> \param[in] LDB
124*> \verbatim
125*> LDB is INTEGER
126*> The leading dimension of the array B. LDB >= max(1,N).
127*> \endverbatim
128*>
129*> \param[out] X
130*> \verbatim
131*> X is COMPLEX*16 array, dimension (LDX,NRHS)
132*> If INFO = 0, the N-by-NRHS solution matrix X.
133*> \endverbatim
134*>
135*> \param[in] LDX
136*> \verbatim
137*> LDX is INTEGER
138*> The leading dimension of the array X. LDX >= max(1,N).
139*> \endverbatim
140*>
141*> \param[out] WORK
142*> \verbatim
143*> WORK is COMPLEX*16 array, dimension (N,NRHS)
144*> This array is used to hold the residual vectors.
145*> \endverbatim
146*>
147*> \param[out] SWORK
148*> \verbatim
149*> SWORK is COMPLEX array, dimension (N*(N+NRHS))
150*> This array is used to use the single precision matrix and the
151*> right-hand sides or solutions in single precision.
152*> \endverbatim
153*>
154*> \param[out] RWORK
155*> \verbatim
156*> RWORK is DOUBLE PRECISION array, dimension (N)
157*> \endverbatim
158*>
159*> \param[out] ITER
160*> \verbatim
161*> ITER is INTEGER
162*> < 0: iterative refinement has failed, COMPLEX*16
163*> factorization has been performed
164*> -1 : the routine fell back to full precision for
165*> implementation- or machine-specific reasons
166*> -2 : narrowing the precision induced an overflow,
167*> the routine fell back to full precision
168*> -3 : failure of CGETRF
169*> -31: stop the iterative refinement after the 30th
170*> iterations
171*> > 0: iterative refinement has been successfully used.
172*> Returns the number of iterations
173*> \endverbatim
174*>
175*> \param[out] INFO
176*> \verbatim
177*> INFO is INTEGER
178*> = 0: successful exit
179*> < 0: if INFO = -i, the i-th argument had an illegal value
180*> > 0: if INFO = i, U(i,i) computed in COMPLEX*16 is exactly
181*> zero. The factorization has been completed, but the
182*> factor U is exactly singular, so the solution
183*> could not be computed.
184*> \endverbatim
185*
186* Authors:
187* ========
188*
189*> \author Univ. of Tennessee
190*> \author Univ. of California Berkeley
191*> \author Univ. of Colorado Denver
192*> \author NAG Ltd.
193*
194*> \ingroup gesv_mixed
195*
196* =====================================================================
197 SUBROUTINE zcgesv( N, NRHS, A, LDA, IPIV, B, LDB, X, LDX, WORK,
198 $ SWORK, RWORK, ITER, INFO )
199*
200* -- LAPACK driver routine --
201* -- LAPACK is a software package provided by Univ. of Tennessee, --
202* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
203*
204* .. Scalar Arguments ..
205 INTEGER INFO, ITER, LDA, LDB, LDX, N, NRHS
206* ..
207* .. Array Arguments ..
208 INTEGER IPIV( * )
209 DOUBLE PRECISION RWORK( * )
210 COMPLEX SWORK( * )
211 COMPLEX*16 A( LDA, * ), B( LDB, * ), WORK( N, * ),
212 $ x( ldx, * )
213* ..
214*
215* =====================================================================
216*
217* .. Parameters ..
218 LOGICAL DOITREF
219 parameter( doitref = .true. )
220*
221 INTEGER ITERMAX
222 parameter( itermax = 30 )
223*
224 DOUBLE PRECISION BWDMAX
225 parameter( bwdmax = 1.0e+00 )
226*
227 COMPLEX*16 NEGONE, ONE
228 parameter( negone = ( -1.0d+00, 0.0d+00 ),
229 $ one = ( 1.0d+00, 0.0d+00 ) )
230*
231* .. Local Scalars ..
232 INTEGER I, IITER, PTSA, PTSX
233 DOUBLE PRECISION ANRM, CTE, EPS, RNRM, XNRM
234 COMPLEX*16 ZDUM
235*
236* .. External Subroutines ..
237 EXTERNAL cgetrs, cgetrf, clag2z, xerbla, zaxpy,
238 $ zgemm,
240* ..
241* .. External Functions ..
242 INTEGER IZAMAX
243 DOUBLE PRECISION DLAMCH, ZLANGE
244 EXTERNAL izamax, dlamch, zlange
245* ..
246* .. Intrinsic Functions ..
247 INTRINSIC abs, dble, max, sqrt
248* ..
249* .. Statement Functions ..
250 DOUBLE PRECISION CABS1
251* ..
252* .. Statement Function definitions ..
253 cabs1( zdum ) = abs( dble( zdum ) ) + abs( dimag( zdum ) )
254* ..
255* .. Executable Statements ..
256*
257 info = 0
258 iter = 0
259*
260* Test the input parameters.
261*
262 IF( n.LT.0 ) THEN
263 info = -1
264 ELSE IF( nrhs.LT.0 ) THEN
265 info = -2
266 ELSE IF( lda.LT.max( 1, n ) ) THEN
267 info = -4
268 ELSE IF( ldb.LT.max( 1, n ) ) THEN
269 info = -7
270 ELSE IF( ldx.LT.max( 1, n ) ) THEN
271 info = -9
272 END IF
273 IF( info.NE.0 ) THEN
274 CALL xerbla( 'ZCGESV', -info )
275 RETURN
276 END IF
277*
278* Quick return if (N.EQ.0).
279*
280 IF( n.EQ.0 )
281 $ RETURN
282*
283* Skip single precision iterative refinement if a priori slower
284* than double precision factorization.
285*
286 IF( .NOT.doitref ) THEN
287 iter = -1
288 GO TO 40
289 END IF
290*
291* Compute some constants.
292*
293 anrm = zlange( 'I', n, n, a, lda, rwork )
294 eps = dlamch( 'Epsilon' )
295 cte = anrm*eps*sqrt( dble( n ) )*bwdmax
296*
297* Set the indices PTSA, PTSX for referencing SA and SX in SWORK.
298*
299 ptsa = 1
300 ptsx = ptsa + n*n
301*
302* Convert B from double precision to single precision and store the
303* result in SX.
304*
305 CALL zlag2c( n, nrhs, b, ldb, swork( ptsx ), n, info )
306*
307 IF( info.NE.0 ) THEN
308 iter = -2
309 GO TO 40
310 END IF
311*
312* Convert A from double precision to single precision and store the
313* result in SA.
314*
315 CALL zlag2c( n, n, a, lda, swork( ptsa ), n, info )
316*
317 IF( info.NE.0 ) THEN
318 iter = -2
319 GO TO 40
320 END IF
321*
322* Compute the LU factorization of SA.
323*
324 CALL cgetrf( n, n, swork( ptsa ), n, ipiv, info )
325*
326 IF( info.NE.0 ) THEN
327 iter = -3
328 GO TO 40
329 END IF
330*
331* Solve the system SA*SX = SB.
332*
333 CALL cgetrs( 'No transpose', n, nrhs, swork( ptsa ), n, ipiv,
334 $ swork( ptsx ), n, info )
335*
336* Convert SX back to double precision
337*
338 CALL clag2z( n, nrhs, swork( ptsx ), n, x, ldx, info )
339*
340* Compute R = B - AX (R is WORK).
341*
342 CALL zlacpy( 'All', n, nrhs, b, ldb, work, n )
343*
344 CALL zgemm( 'No Transpose', 'No Transpose', n, nrhs, n, negone,
345 $ a,
346 $ lda, x, ldx, one, work, n )
347*
348* Check whether the NRHS normwise backward errors satisfy the
349* stopping criterion. If yes, set ITER=0 and return.
350*
351 DO i = 1, nrhs
352 xnrm = cabs1( x( izamax( n, x( 1, i ), 1 ), i ) )
353 rnrm = cabs1( work( izamax( n, work( 1, i ), 1 ), i ) )
354 IF( rnrm.GT.xnrm*cte )
355 $ GO TO 10
356 END DO
357*
358* If we are here, the NRHS normwise backward errors satisfy the
359* stopping criterion. We are good to exit.
360*
361 iter = 0
362 RETURN
363*
364 10 CONTINUE
365*
366 DO 30 iiter = 1, itermax
367*
368* Convert R (in WORK) from double precision to single precision
369* and store the result in SX.
370*
371 CALL zlag2c( n, nrhs, work, n, swork( ptsx ), n, info )
372*
373 IF( info.NE.0 ) THEN
374 iter = -2
375 GO TO 40
376 END IF
377*
378* Solve the system SA*SX = SR.
379*
380 CALL cgetrs( 'No transpose', n, nrhs, swork( ptsa ), n,
381 $ ipiv,
382 $ swork( ptsx ), n, info )
383*
384* Convert SX back to double precision and update the current
385* iterate.
386*
387 CALL clag2z( n, nrhs, swork( ptsx ), n, work, n, info )
388*
389 DO i = 1, nrhs
390 CALL zaxpy( n, one, work( 1, i ), 1, x( 1, i ), 1 )
391 END DO
392*
393* Compute R = B - AX (R is WORK).
394*
395 CALL zlacpy( 'All', n, nrhs, b, ldb, work, n )
396*
397 CALL zgemm( 'No Transpose', 'No Transpose', n, nrhs, n,
398 $ negone,
399 $ a, lda, x, ldx, one, work, n )
400*
401* Check whether the NRHS normwise backward errors satisfy the
402* stopping criterion. If yes, set ITER=IITER>0 and return.
403*
404 DO i = 1, nrhs
405 xnrm = cabs1( x( izamax( n, x( 1, i ), 1 ), i ) )
406 rnrm = cabs1( work( izamax( n, work( 1, i ), 1 ), i ) )
407 IF( rnrm.GT.xnrm*cte )
408 $ GO TO 20
409 END DO
410*
411* If we are here, the NRHS normwise backward errors satisfy the
412* stopping criterion, we are good to exit.
413*
414 iter = iiter
415*
416 RETURN
417*
418 20 CONTINUE
419*
420 30 CONTINUE
421*
422* If we are at this place of the code, this is because we have
423* performed ITER=ITERMAX iterations and never satisfied the stopping
424* criterion, set up the ITER flag accordingly and follow up on double
425* precision routine.
426*
427 iter = -itermax - 1
428*
429 40 CONTINUE
430*
431* Single-precision iterative refinement failed to converge to a
432* satisfactory solution, so we resort to double precision.
433*
434 CALL zgetrf( n, n, a, lda, ipiv, info )
435*
436 IF( info.NE.0 )
437 $ RETURN
438*
439 CALL zlacpy( 'All', n, nrhs, b, ldb, x, ldx )
440 CALL zgetrs( 'No transpose', n, nrhs, a, lda, ipiv, x, ldx,
441 $ info )
442*
443 RETURN
444*
445* End of ZCGESV
446*
447 END
subroutine xerbla(srname, info)
Definition cblat2.f:3285
subroutine clag2z(m, n, sa, ldsa, a, lda, info)
CLAG2Z converts a complex single precision matrix to a complex double precision matrix.
Definition clag2z.f:101
subroutine zlag2c(m, n, a, lda, sa, ldsa, info)
ZLAG2C converts a complex double precision matrix to a complex single precision matrix.
Definition zlag2c.f:105
subroutine zaxpy(n, za, zx, incx, zy, incy)
ZAXPY
Definition zaxpy.f:88
subroutine zgemm(transa, transb, m, n, k, alpha, a, lda, b, ldb, beta, c, ldc)
ZGEMM
Definition zgemm.f:188
subroutine zcgesv(n, nrhs, a, lda, ipiv, b, ldb, x, ldx, work, swork, rwork, iter, info)
ZCGESV computes the solution to system of linear equations A * X = B for GE matrices (mixed precision...
Definition zcgesv.f:199
subroutine cgetrf(m, n, a, lda, ipiv, info)
CGETRF
Definition cgetrf.f:106
subroutine zgetrf(m, n, a, lda, ipiv, info)
ZGETRF
Definition zgetrf.f:106
subroutine cgetrs(trans, n, nrhs, a, lda, ipiv, b, ldb, info)
CGETRS
Definition cgetrs.f:119
subroutine zgetrs(trans, n, nrhs, a, lda, ipiv, b, ldb, info)
ZGETRS
Definition zgetrs.f:119
subroutine zlacpy(uplo, m, n, a, lda, b, ldb)
ZLACPY copies all or part of one two-dimensional array to another.
Definition zlacpy.f:101