ScaLAPACK  2.0.2
ScaLAPACK: Scalable Linear Algebra PACKage
pzlarfg.f
Go to the documentation of this file.
00001       SUBROUTINE PZLARFG( N, ALPHA, IAX, JAX, X, IX, JX, DESCX, INCX,
00002      $                    TAU )
00003 *
00004 *  -- ScaLAPACK auxiliary routine (version 1.7) --
00005 *     University of Tennessee, Knoxville, Oak Ridge National Laboratory,
00006 *     and University of California, Berkeley.
00007 *     May 1, 1997
00008 *
00009 *     .. Scalar Arguments ..
00010       INTEGER            IAX, INCX, IX, JAX, JX, N
00011       COMPLEX*16         ALPHA
00012 *     ..
00013 *     .. Array Arguments ..
00014       INTEGER            DESCX( * )
00015       COMPLEX*16         TAU( * ), X( * )
00016 *     ..
00017 *
00018 *  Purpose
00019 *  =======
00020 *
00021 *  PZLARFG generates a complex elementary reflector H of order n, such
00022 *  that
00023 *
00024 *     H * sub( X ) = H * ( x(iax,jax) ) = ( alpha ),   H' * H = I.
00025 *                        (      x     )   (   0   )
00026 *
00027 *  where alpha is a real scalar, and sub( X ) is an (N-1)-element
00028 *  complex distributed vector X(IX:IX+N-2,JX) if INCX = 1 and
00029 *  X(IX,JX:JX+N-2) if INCX = DESCX(M_).  H is represented in the form
00030 *
00031 *        H = I - tau * ( 1 ) * ( 1 v' ) ,
00032 *                      ( v )
00033 *
00034 *  where tau is a complex scalar and v is a complex (N-1)-element
00035 *  vector. Note that H is not Hermitian.
00036 *
00037 *  If the elements of sub( X ) are all zero and X(IAX,JAX) is real,
00038 *  then tau = 0 and H is taken to be the unit matrix.
00039 *
00040 *  Otherwise  1 <= real(tau) <= 2 and abs(tau-1) <= 1.
00041 *
00042 *  Notes
00043 *  =====
00044 *
00045 *  Each global data object is described by an associated description
00046 *  vector.  This vector stores the information required to establish
00047 *  the mapping between an object element and its corresponding process
00048 *  and memory location.
00049 *
00050 *  Let A be a generic term for any 2D block cyclicly distributed array.
00051 *  Such a global array has an associated description vector DESCA.
00052 *  In the following comments, the character _ should be read as
00053 *  "of the global array".
00054 *
00055 *  NOTATION        STORED IN      EXPLANATION
00056 *  --------------- -------------- --------------------------------------
00057 *  DTYPE_A(global) DESCA( DTYPE_ )The descriptor type.  In this case,
00058 *                                 DTYPE_A = 1.
00059 *  CTXT_A (global) DESCA( CTXT_ ) The BLACS context handle, indicating
00060 *                                 the BLACS process grid A is distribu-
00061 *                                 ted over. The context itself is glo-
00062 *                                 bal, but the handle (the integer
00063 *                                 value) may vary.
00064 *  M_A    (global) DESCA( M_ )    The number of rows in the global
00065 *                                 array A.
00066 *  N_A    (global) DESCA( N_ )    The number of columns in the global
00067 *                                 array A.
00068 *  MB_A   (global) DESCA( MB_ )   The blocking factor used to distribute
00069 *                                 the rows of the array.
00070 *  NB_A   (global) DESCA( NB_ )   The blocking factor used to distribute
00071 *                                 the columns of the array.
00072 *  RSRC_A (global) DESCA( RSRC_ ) The process row over which the first
00073 *                                 row of the array A is distributed.
00074 *  CSRC_A (global) DESCA( CSRC_ ) The process column over which the
00075 *                                 first column of the array A is
00076 *                                 distributed.
00077 *  LLD_A  (local)  DESCA( LLD_ )  The leading dimension of the local
00078 *                                 array.  LLD_A >= MAX(1,LOCr(M_A)).
00079 *
00080 *  Let K be the number of rows or columns of a distributed matrix,
00081 *  and assume that its process grid has dimension p x q.
00082 *  LOCr( K ) denotes the number of elements of K that a process
00083 *  would receive if K were distributed over the p processes of its
00084 *  process column.
00085 *  Similarly, LOCc( K ) denotes the number of elements of K that a
00086 *  process would receive if K were distributed over the q processes of
00087 *  its process row.
00088 *  The values of LOCr() and LOCc() may be determined via a call to the
00089 *  ScaLAPACK tool function, NUMROC:
00090 *          LOCr( M ) = NUMROC( M, MB_A, MYROW, RSRC_A, NPROW ),
00091 *          LOCc( N ) = NUMROC( N, NB_A, MYCOL, CSRC_A, NPCOL ).
00092 *  An upper bound for these quantities may be computed by:
00093 *          LOCr( M ) <= ceil( ceil(M/MB_A)/NPROW )*MB_A
00094 *          LOCc( N ) <= ceil( ceil(N/NB_A)/NPCOL )*NB_A
00095 *
00096 *  Because vectors may be viewed as a subclass of matrices, a
00097 *  distributed vector is considered to be a distributed matrix.
00098 *
00099 *  Arguments
00100 *  =========
00101 *
00102 *  N       (global input) INTEGER
00103 *          The global order of the elementary reflector. N >= 0.
00104 *
00105 *  ALPHA   (local output) COMPLEX*16
00106 *          On exit, alpha is computed in the process scope having the
00107 *          vector sub( X ).
00108 *
00109 *  IAX     (global input) INTEGER
00110 *          The global row index in X of X(IAX,JAX).
00111 *
00112 *  JAX     (global input) INTEGER
00113 *          The global column index in X of X(IAX,JAX).
00114 *
00115 *  X       (local input/local output) COMPLEX*16, pointer into the
00116 *          local memory to an array of dimension (LLD_X,*). This array
00117 *          contains the local pieces of the distributed vector sub( X ).
00118 *          Before entry, the incremented array sub( X ) must contain
00119 *          the vector x. On exit, it is overwritten with the vector v.
00120 *
00121 *  IX      (global input) INTEGER
00122 *          The row index in the global array X indicating the first
00123 *          row of sub( X ).
00124 *
00125 *  JX      (global input) INTEGER
00126 *          The column index in the global array X indicating the
00127 *          first column of sub( X ).
00128 *
00129 *  DESCX   (global and local input) INTEGER array of dimension DLEN_.
00130 *          The array descriptor for the distributed matrix X.
00131 *
00132 *  INCX    (global input) INTEGER
00133 *          The global increment for the elements of X. Only two values
00134 *          of INCX are supported in this version, namely 1 and M_X.
00135 *          INCX must not be zero.
00136 *
00137 *  TAU     (local output) COMPLEX*16, array, dimension  LOCc(JX)
00138 *          if INCX = 1, and LOCr(IX) otherwise. This array contains the
00139 *          Householder scalars related to the Householder vectors.
00140 *          TAU is tied to the distributed matrix X.
00141 *
00142 *  =====================================================================
00143 *
00144 *     .. Parameters ..
00145       INTEGER            BLOCK_CYCLIC_2D, CSRC_, CTXT_, DLEN_, DTYPE_,
00146      $                   LLD_, MB_, M_, NB_, N_, RSRC_
00147       PARAMETER          ( BLOCK_CYCLIC_2D = 1, DLEN_ = 9, DTYPE_ = 1,
00148      $                     CTXT_ = 2, M_ = 3, N_ = 4, MB_ = 5, NB_ = 6,
00149      $                     RSRC_ = 7, CSRC_ = 8, LLD_ = 9 )
00150       DOUBLE PRECISION   ONE, ZERO
00151       PARAMETER          ( ONE = 1.0D+0, ZERO = 0.0D+0 )
00152 *     ..
00153 *     .. Local Scalars ..
00154       INTEGER            ICTXT, IIAX, INDXTAU, IXCOL, IXROW, J, JJAX,
00155      $                   KNT, MYCOL, MYROW, NPCOL, NPROW
00156       DOUBLE PRECISION   ALPHI, ALPHR, BETA, RSAFMN, SAFMIN, XNORM
00157 *     ..
00158 *     .. External Subroutines ..
00159       EXTERNAL           BLACS_GRIDINFO, INFOG2L, PDZNRM2,
00160      $                   ZGEBR2D, ZGEBS2D, PZSCAL,
00161      $                   PZDSCAL
00162 *     ..
00163 *     .. External Functions ..
00164       DOUBLE PRECISION   DLAMCH, DLAPY3
00165       COMPLEX*16         ZLADIV
00166       EXTERNAL           DLAMCH, DLAPY3, ZLADIV
00167 *     ..
00168 *     .. Intrinsic Functions ..
00169       INTRINSIC          ABS, DBLE, DCMPLX, DIMAG, SIGN
00170 *     ..
00171 *     .. Executable Statements ..
00172 *
00173 *     Get grid parameters.
00174 *
00175       ICTXT = DESCX( CTXT_ )
00176       CALL BLACS_GRIDINFO( ICTXT, NPROW, NPCOL, MYROW, MYCOL )
00177 *
00178       IF( INCX.EQ.DESCX( M_ ) ) THEN
00179 *
00180 *        sub( X ) is distributed across a process row.
00181 *
00182          CALL INFOG2L( IX, JAX, DESCX, NPROW, NPCOL, MYROW, MYCOL,
00183      $                 IIAX, JJAX, IXROW, IXCOL )
00184 *
00185          IF( MYROW.NE.IXROW )
00186      $      RETURN
00187 *
00188 *        Broadcast X(IAX,JAX) across the process row.
00189 *
00190          IF( MYCOL.EQ.IXCOL ) THEN
00191             J = IIAX+(JJAX-1)*DESCX( LLD_ )
00192             CALL ZGEBS2D( ICTXT, 'Rowwise', ' ', 1, 1, X( J ), 1 )
00193             ALPHA = X( J )
00194          ELSE
00195             CALL ZGEBR2D( ICTXT, 'Rowwise', ' ', 1, 1, ALPHA, 1,
00196      $                    MYROW, IXCOL )
00197          END IF
00198 *
00199          INDXTAU = IIAX
00200 *
00201       ELSE
00202 *
00203 *        sub( X ) is distributed across a process column.
00204 *
00205          CALL INFOG2L( IAX, JX, DESCX, NPROW, NPCOL, MYROW, MYCOL,
00206      $                 IIAX, JJAX, IXROW, IXCOL )
00207 *
00208          IF( MYCOL.NE.IXCOL )
00209      $      RETURN
00210 *
00211 *        Broadcast X(IAX,JAX) across the process column.
00212 *
00213          IF( MYROW.EQ.IXROW ) THEN
00214             J = IIAX+(JJAX-1)*DESCX( LLD_ )
00215             CALL ZGEBS2D( ICTXT, 'Columnwise', ' ', 1, 1, X( J ), 1 )
00216             ALPHA = X( J )
00217          ELSE
00218             CALL ZGEBR2D( ICTXT, 'Columnwise', ' ', 1, 1, ALPHA, 1,
00219      $                    IXROW, MYCOL )
00220          END IF
00221 *
00222          INDXTAU = JJAX
00223 *
00224       END IF
00225 *
00226       IF( N.LE.0 ) THEN
00227          TAU( INDXTAU ) = ZERO
00228          RETURN
00229       END IF
00230 *
00231       CALL PDZNRM2( N-1, XNORM, X, IX, JX, DESCX, INCX )
00232       ALPHR = DBLE( ALPHA )
00233       ALPHI = DIMAG( ALPHA )
00234 *
00235       IF( XNORM.EQ.ZERO .AND. ALPHI.EQ.ZERO ) THEN
00236 *
00237 *        H = I
00238 *
00239          TAU( INDXTAU ) = ZERO
00240 *
00241       ELSE
00242 *
00243 *        General case
00244 *
00245          BETA = -SIGN( DLAPY3( ALPHR, ALPHI, XNORM ), ALPHR )
00246          SAFMIN = DLAMCH( 'S' )
00247          RSAFMN = ONE / SAFMIN
00248          IF( ABS( BETA ).LT.SAFMIN ) THEN
00249 *
00250 *           XNORM, BETA may be inaccurate; scale X and recompute them
00251 *
00252             KNT = 0
00253    10       CONTINUE
00254             KNT = KNT + 1
00255             CALL PZDSCAL( N-1, RSAFMN, X, IX, JX, DESCX, INCX )
00256             BETA = BETA*RSAFMN
00257             ALPHI = ALPHI*RSAFMN
00258             ALPHR = ALPHR*RSAFMN
00259             IF( ABS( BETA ).LT.SAFMIN )
00260      $         GO TO 10
00261 *
00262 *           New BETA is at most 1, at least SAFMIN
00263 *
00264             CALL PDZNRM2( N-1, XNORM, X, IX, JX, DESCX, INCX )
00265             ALPHA = DCMPLX( ALPHR, ALPHI )
00266             BETA = -SIGN( DLAPY3( ALPHR, ALPHI, XNORM ), ALPHR )
00267             TAU( INDXTAU ) = DCMPLX( ( BETA-ALPHR ) / BETA,
00268      $                                 -ALPHI / BETA )
00269             ALPHA = ZLADIV( DCMPLX( ONE ), ALPHA-BETA )
00270             CALL PZSCAL( N-1, ALPHA, X, IX, JX, DESCX, INCX )
00271 *
00272 *           If ALPHA is subnormal, it may lose relative accuracy
00273 *
00274             ALPHA = BETA
00275             DO 20 J = 1, KNT
00276                ALPHA = ALPHA*SAFMIN
00277    20       CONTINUE
00278          ELSE
00279             TAU( INDXTAU ) = DCMPLX( ( BETA-ALPHR ) / BETA,
00280      $                               -ALPHI / BETA )
00281             ALPHA = ZLADIV( DCMPLX( ONE ), ALPHA-BETA )
00282             CALL PZSCAL( N-1, ALPHA, X, IX, JX, DESCX, INCX )
00283             ALPHA = BETA
00284          END IF
00285       END IF
00286 *
00287       RETURN
00288 *
00289 *     End of PZLARFG
00290 *
00291       END