LAPACK 3.12.1
LAPACK: Linear Algebra PACKage
Loading...
Searching...
No Matches

◆ zcgesv()

subroutine zcgesv ( integer n,
integer nrhs,
complex*16, dimension( lda, * ) a,
integer lda,
integer, dimension( * ) ipiv,
complex*16, dimension( ldb, * ) b,
integer ldb,
complex*16, dimension( ldx, * ) x,
integer ldx,
complex*16, dimension( n, * ) work,
complex, dimension( * ) swork,
double precision, dimension( * ) rwork,
integer iter,
integer info )

ZCGESV computes the solution to system of linear equations A * X = B for GE matrices (mixed precision with iterative refinement)

Download ZCGESV + dependencies [TGZ] [ZIP] [TXT]

Purpose:
!>
!> ZCGESV computes the solution to a complex system of linear equations
!>    A * X = B,
!> where A is an N-by-N matrix and X and B are N-by-NRHS matrices.
!>
!> ZCGESV first attempts to factorize the matrix in COMPLEX and use this
!> factorization within an iterative refinement procedure to produce a
!> solution with COMPLEX*16 normwise backward error quality (see below).
!> If the approach fails the method switches to a COMPLEX*16
!> factorization and solve.
!>
!> The iterative refinement is not going to be a winning strategy if
!> the ratio COMPLEX performance over COMPLEX*16 performance is too
!> small. A reasonable strategy should take the number of right-hand
!> sides and the size of the matrix into account. This might be done
!> with a call to ILAENV in the future. Up to now, we always try
!> iterative refinement.
!>
!> The iterative refinement process is stopped if
!>     ITER > ITERMAX
!> or for all the RHS we have:
!>     RNRM < SQRT(N)*XNRM*ANRM*EPS*BWDMAX
!> where
!>     o ITER is the number of the current iteration in the iterative
!>       refinement process
!>     o RNRM is the infinity-norm of the residual
!>     o XNRM is the infinity-norm of the solution
!>     o ANRM is the infinity-operator-norm of the matrix A
!>     o EPS is the machine epsilon returned by DLAMCH('Epsilon')
!> The value ITERMAX and BWDMAX are fixed to 30 and 1.0D+00
!> respectively.
!> 
Parameters
[in]N
!>          N is INTEGER
!>          The number of linear equations, i.e., the order of the
!>          matrix A.  N >= 0.
!> 
[in]NRHS
!>          NRHS is INTEGER
!>          The number of right hand sides, i.e., the number of columns
!>          of the matrix B.  NRHS >= 0.
!> 
[in,out]A
!>          A is COMPLEX*16 array,
!>          dimension (LDA,N)
!>          On entry, the N-by-N coefficient matrix A.
!>          On exit, if iterative refinement has been successfully used
!>          (INFO = 0 and ITER >= 0, see description below), then A is
!>          unchanged, if double precision factorization has been used
!>          (INFO = 0 and ITER < 0, see description below), then the
!>          array A contains the factors L and U from the factorization
!>          A = P*L*U; the unit diagonal elements of L are not stored.
!> 
[in]LDA
!>          LDA is INTEGER
!>          The leading dimension of the array A.  LDA >= max(1,N).
!> 
[out]IPIV
!>          IPIV is INTEGER array, dimension (N)
!>          The pivot indices that define the permutation matrix P;
!>          row i of the matrix was interchanged with row IPIV(i).
!>          Corresponds either to the single precision factorization
!>          (if INFO = 0 and ITER >= 0) or the double precision
!>          factorization (if INFO = 0 and ITER < 0).
!> 
[in]B
!>          B is COMPLEX*16 array, dimension (LDB,NRHS)
!>          The N-by-NRHS right hand side matrix B.
!> 
[in]LDB
!>          LDB is INTEGER
!>          The leading dimension of the array B.  LDB >= max(1,N).
!> 
[out]X
!>          X is COMPLEX*16 array, dimension (LDX,NRHS)
!>          If INFO = 0, the N-by-NRHS solution matrix X.
!> 
[in]LDX
!>          LDX is INTEGER
!>          The leading dimension of the array X.  LDX >= max(1,N).
!> 
[out]WORK
!>          WORK is COMPLEX*16 array, dimension (N,NRHS)
!>          This array is used to hold the residual vectors.
!> 
[out]SWORK
!>          SWORK is COMPLEX array, dimension (N*(N+NRHS))
!>          This array is used to use the single precision matrix and the
!>          right-hand sides or solutions in single precision.
!> 
[out]RWORK
!>          RWORK is DOUBLE PRECISION array, dimension (N)
!> 
[out]ITER
!>          ITER is INTEGER
!>          < 0: iterative refinement has failed, COMPLEX*16
!>               factorization has been performed
!>               -1 : the routine fell back to full precision for
!>                    implementation- or machine-specific reasons
!>               -2 : narrowing the precision induced an overflow,
!>                    the routine fell back to full precision
!>               -3 : failure of CGETRF
!>               -31: stop the iterative refinement after the 30th
!>                    iterations
!>          > 0: iterative refinement has been successfully used.
!>               Returns the number of iterations
!> 
[out]INFO
!>          INFO is INTEGER
!>          = 0:  successful exit
!>          < 0:  if INFO = -i, the i-th argument had an illegal value
!>          > 0:  if INFO = i, U(i,i) computed in COMPLEX*16 is exactly
!>                zero.  The factorization has been completed, but the
!>                factor U is exactly singular, so the solution
!>                could not be computed.
!> 
Author
Univ. of Tennessee
Univ. of California Berkeley
Univ. of Colorado Denver
NAG Ltd.

Definition at line 197 of file zcgesv.f.

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*
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 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
integer function izamax(n, zx, incx)
IZAMAX
Definition izamax.f:71
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
double precision function dlamch(cmach)
DLAMCH
Definition dlamch.f:69
double precision function zlange(norm, m, n, a, lda, work)
ZLANGE returns the value of the 1-norm, Frobenius norm, infinity-norm, or the largest absolute value ...
Definition zlange.f:113
Here is the call graph for this function:
Here is the caller graph for this function: