ScaLAPACK  2.0.2
ScaLAPACK: Scalable Linear Algebra PACKage
pzher_.c
Go to the documentation of this file.
00001 /* ---------------------------------------------------------------------
00002 *
00003 *  -- PBLAS routine (version 2.0) --
00004 *     University of Tennessee, Knoxville, Oak Ridge National Laboratory,
00005 *     and University of California, Berkeley.
00006 *     April 1, 1998
00007 *
00008 *  ---------------------------------------------------------------------
00009 */
00010 /*
00011 *  Include files
00012 */
00013 #include "pblas.h"
00014 #include "PBpblas.h"
00015 #include "PBtools.h"
00016 #include "PBblacs.h"
00017 #include "PBblas.h"
00018 
00019 #ifdef __STDC__
00020 void pzher_( F_CHAR_T UPLO, int * N, double * ALPHA,
00021              double * X, int * IX, int * JX, int * DESCX, int * INCX,
00022              double * A, int * IA, int * JA, int * DESCA )
00023 #else
00024 void pzher_( UPLO, N, ALPHA, X, IX, JX, DESCX, INCX, A, IA, JA, DESCA )
00025 /*
00026 *  .. Scalar Arguments ..
00027 */
00028    F_CHAR_T       UPLO;
00029    int            * IA, * INCX, * IX, * JA, * JX, * N;
00030    double         * ALPHA;
00031 /*
00032 *  .. Array Arguments ..
00033 */
00034    int            * DESCA, * DESCX;
00035    double         * A, * X;
00036 #endif
00037 {
00038 /*
00039 *  Purpose
00040 *  =======
00041 *
00042 *  PZHER  performs the Hermitian rank 1 operation
00043 *
00044 *     sub( A ) := alpha*sub( X )*conjg( sub( X )' ) + sub( A ),
00045 *
00046 *  where
00047 *
00048 *     sub( A ) denotes A(IA:IA+N-1,JA:JA+N-1), and,
00049 *
00050 *     sub( X ) denotes X(IX,JX:JX+N-1) if INCX = M_X,
00051 *                      X(IX:IX+N-1,JX) if INCX = 1 and INCX <> M_X.
00052 *
00053 *  Alpha is a  real  scalar,  sub( X )  is an  n element  subvector  and
00054 *  sub( A ) is an n by n Hermitian submatrix.
00055 *
00056 *  Notes
00057 *  =====
00058 *
00059 *  A description  vector  is associated with each 2D block-cyclicly dis-
00060 *  tributed matrix.  This  vector  stores  the  information  required to
00061 *  establish the  mapping  between a  matrix entry and its corresponding
00062 *  process and memory location.
00063 *
00064 *  In  the  following  comments,   the character _  should  be  read  as
00065 *  "of  the  distributed  matrix".  Let  A  be a generic term for any 2D
00066 *  block cyclicly distributed matrix.  Its description vector is DESC_A:
00067 *
00068 *  NOTATION         STORED IN       EXPLANATION
00069 *  ---------------- --------------- ------------------------------------
00070 *  DTYPE_A (global) DESCA[ DTYPE_ ] The descriptor type.
00071 *  CTXT_A  (global) DESCA[ CTXT_  ] The BLACS context handle, indicating
00072 *                                   the NPROW x NPCOL BLACS process grid
00073 *                                   A  is  distributed over. The context
00074 *                                   itself  is  global,  but  the handle
00075 *                                   (the integer value) may vary.
00076 *  M_A     (global) DESCA[ M_     ] The  number of rows in the distribu-
00077 *                                   ted matrix A, M_A >= 0.
00078 *  N_A     (global) DESCA[ N_     ] The number of columns in the distri-
00079 *                                   buted matrix A, N_A >= 0.
00080 *  IMB_A   (global) DESCA[ IMB_   ] The number of rows of the upper left
00081 *                                   block of the matrix A, IMB_A > 0.
00082 *  INB_A   (global) DESCA[ INB_   ] The  number  of columns of the upper
00083 *                                   left   block   of   the  matrix   A,
00084 *                                   INB_A > 0.
00085 *  MB_A    (global) DESCA[ MB_    ] The blocking factor used to  distri-
00086 *                                   bute the last  M_A-IMB_A  rows of A,
00087 *                                   MB_A > 0.
00088 *  NB_A    (global) DESCA[ NB_    ] The blocking factor used to  distri-
00089 *                                   bute the last  N_A-INB_A  columns of
00090 *                                   A, NB_A > 0.
00091 *  RSRC_A  (global) DESCA[ RSRC_  ] The process row over which the first
00092 *                                   row of the matrix  A is distributed,
00093 *                                   NPROW > RSRC_A >= 0.
00094 *  CSRC_A  (global) DESCA[ CSRC_  ] The  process column  over  which the
00095 *                                   first column of  A  is  distributed.
00096 *                                   NPCOL > CSRC_A >= 0.
00097 *  LLD_A   (local)  DESCA[ LLD_   ] The  leading dimension  of the local
00098 *                                   array  storing  the  local blocks of
00099 *                                   the distributed matrix A,
00100 *                                   IF( Lc( 1, N_A ) > 0 )
00101 *                                      LLD_A >= MAX( 1, Lr( 1, M_A ) )
00102 *                                   ELSE
00103 *                                      LLD_A >= 1.
00104 *
00105 *  Let K be the number of  rows of a matrix A starting at the global in-
00106 *  dex IA,i.e, A( IA:IA+K-1, : ). Lr( IA, K ) denotes the number of rows
00107 *  that the process of row coordinate MYROW ( 0 <= MYROW < NPROW ) would
00108 *  receive if these K rows were distributed over NPROW processes.  If  K
00109 *  is the number of columns of a matrix  A  starting at the global index
00110 *  JA, i.e, A( :, JA:JA+K-1, : ), Lc( JA, K ) denotes the number  of co-
00111 *  lumns that the process MYCOL ( 0 <= MYCOL < NPCOL ) would  receive if
00112 *  these K columns were distributed over NPCOL processes.
00113 *
00114 *  The values of Lr() and Lc() may be determined via a call to the func-
00115 *  tion PB_Cnumroc:
00116 *  Lr( IA, K ) = PB_Cnumroc( K, IA, IMB_A, MB_A, MYROW, RSRC_A, NPROW )
00117 *  Lc( JA, K ) = PB_Cnumroc( K, JA, INB_A, NB_A, MYCOL, CSRC_A, NPCOL )
00118 *
00119 *  Arguments
00120 *  =========
00121 *
00122 *  UPLO    (global input) CHARACTER*1
00123 *          On  entry,   UPLO  specifies  whether  the  local  pieces  of
00124 *          the array  A  containing the  upper or lower triangular  part
00125 *          of the Hermitian submatrix  sub( A )  are to be referenced as
00126 *          follows:
00127 *
00128 *             UPLO = 'U' or 'u'   Only the local pieces corresponding to
00129 *                                 the   upper  triangular  part  of  the
00130 *                                 Hermitian submatrix sub( A ) are to be
00131 *                                 referenced,
00132 *
00133 *             UPLO = 'L' or 'l'   Only the local pieces corresponding to
00134 *                                 the   lower  triangular  part  of  the
00135 *                                 Hermitian submatrix sub( A ) are to be
00136 *                                 referenced.
00137 *
00138 *  N       (global input) INTEGER
00139 *          On entry,  N specifies the order of the  submatrix  sub( A ).
00140 *          N must be at least zero.
00141 *
00142 *  ALPHA   (global input) DOUBLE PRECISION
00143 *          On entry, ALPHA specifies the scalar alpha.   When  ALPHA  is
00144 *          supplied  as  zero  then  the  local entries of the array   X
00145 *          corresponding to the entries of the subvector  sub( X )  need
00146 *          not be set on input.
00147 *
00148 *  X       (local input) COMPLEX*16 array
00149 *          On entry, X is an array of dimension (LLD_X, Kx), where LLD_X
00150 *          is   at  least  MAX( 1, Lr( 1, IX ) )  when  INCX = M_X   and
00151 *          MAX( 1, Lr( 1, IX+N-1 ) )  otherwise,  and,  Kx  is  at least
00152 *          Lc( 1, JX+N-1 )  when  INCX = M_X  and Lc( 1, JX ) otherwise.
00153 *          Before  entry,  this array  contains the local entries of the
00154 *          matrix X.
00155 *
00156 *  IX      (global input) INTEGER
00157 *          On entry, IX  specifies X's global row index, which points to
00158 *          the beginning of the submatrix sub( X ).
00159 *
00160 *  JX      (global input) INTEGER
00161 *          On entry, JX  specifies X's global column index, which points
00162 *          to the beginning of the submatrix sub( X ).
00163 *
00164 *  DESCX   (global and local input) INTEGER array
00165 *          On entry, DESCX  is an integer array of dimension DLEN_. This
00166 *          is the array descriptor for the matrix X.
00167 *
00168 *  INCX    (global input) INTEGER
00169 *          On entry,  INCX   specifies  the  global  increment  for  the
00170 *          elements of  X.  Only two values of  INCX   are  supported in
00171 *          this version, namely 1 and M_X. INCX  must not be zero.
00172 *
00173 *  A       (local input/local output) COMPLEX*16 array
00174 *          On entry, A is an array of dimension (LLD_A, Ka), where Ka is
00175 *          at least Lc( 1, JA+N-1 ).  Before  entry, this array contains
00176 *          the local entries of the matrix A.
00177 *          Before  entry  with  UPLO = 'U' or 'u', this  array  contains
00178 *          the local entries corresponding to the upper triangular  part
00179 *          of  the  Hermitian submatrix  sub( A ), and the local entries
00180 *          corresponding to the  strictly lower triangular  of  sub( A )
00181 *          are not referenced.  On exit,  the upper  triangular  part of
00182 *          sub( A ) is overwritten by the  upper triangular part  of the
00183 *          updated submatrix.
00184 *          Before  entry  with  UPLO = 'L' or 'l', this  array  contains
00185 *          the local entries corresponding to the lower triangular  part
00186 *          of  the  Hermitian submatrix  sub( A ), and the local entries
00187 *          corresponding to the  strictly upper triangular  of  sub( A )
00188 *          are not referenced.  On exit,  the lower  triangular  part of
00189 *          sub( A ) is overwritten by the  lower triangular part  of the
00190 *          updated submatrix.
00191 *          Note that the  imaginary parts  of the local entries  corres-
00192 *          ponding to the  diagonal elements  of  sub( A )  need not  be
00193 *          set,  they are assumed to be zero,  and on exit they are  set
00194 *          to zero.
00195 *
00196 *  IA      (global input) INTEGER
00197 *          On entry, IA  specifies A's global row index, which points to
00198 *          the beginning of the submatrix sub( A ).
00199 *
00200 *  JA      (global input) INTEGER
00201 *          On entry, JA  specifies A's global column index, which points
00202 *          to the beginning of the submatrix sub( A ).
00203 *
00204 *  DESCA   (global and local input) INTEGER array
00205 *          On entry, DESCA  is an integer array of dimension DLEN_. This
00206 *          is the array descriptor for the matrix A.
00207 *
00208 *  -- Written on April 1, 1998 by
00209 *     Antoine Petitet, University of Tennessee, Knoxville 37996, USA.
00210 *
00211 *  ---------------------------------------------------------------------
00212 */
00213 /*
00214 *  .. Local Scalars ..
00215 */
00216    char           UploA;
00217    int            Acol, Ai, Aii, Aimb1, Ainb1, Aj, Ajj, Akp, Akq, Ald, Amb,
00218                   Amp, Amp0, Anb, Anq, Anq0, Arow, XCfr, XCld, XRfr, XRld,
00219                   Xi, Xj, ctxt, info, ione=1, k, kb, ktmp, mycol, myrow, nb,
00220                   npcol, nprow, size, upper;
00221    cmplx16        Calpha;
00222    PBTYP_T        * type;
00223 /*
00224 *  .. Local Arrays ..
00225 */
00226    int            Ad[DLEN_], Ad0[DLEN_], XCd0[DLEN_], XRd0[DLEN_], Xd[DLEN_];
00227    char           * Aptr = NULL, * XC = NULL, * XR = NULL;
00228 /* ..
00229 *  .. Executable Statements ..
00230 *
00231 */
00232    upper = ( ( UploA  = Mupcase( F2C_CHAR( UPLO )[0] ) ) == CUPPER );
00233    PB_CargFtoC( *IA, *JA, DESCA, &Ai, &Aj, Ad );
00234    PB_CargFtoC( *IX, *JX, DESCX, &Xi, &Xj, Xd );
00235 #ifndef NO_ARGCHK
00236 /*
00237 *  Test the input parameters
00238 */
00239    Cblacs_gridinfo( ( ctxt = Xd[CTXT_] ), &nprow, &npcol, &myrow, &mycol );
00240    if( !( info = ( ( nprow == -1 ) ? -( 701 + CTXT_ ) : 0 ) ) )
00241    {
00242       if( ( !upper ) && ( UploA != CLOWER ) )
00243       {
00244          PB_Cwarn( ctxt, __LINE__, "PZHER", "Illegal UPLO = %c\n", UploA );
00245          info = -1;
00246       }
00247       PB_Cchkvec( ctxt, "PZHER", "X", *N, 2, Xi, Xj, Xd, *INCX,  7, &info );
00248       PB_Cchkmat( ctxt, "PZHER", "A", *N, 2, *N, 2, Ai, Aj, Ad, 12, &info );
00249    }
00250    if( info ) { PB_Cabort( ctxt, "PZHER", info ); return; }
00251 #endif
00252 /*
00253 *  Quick return if possible
00254 */
00255    if( ( *N == 0 ) || ( ALPHA[REAL_PART] == ZERO ) )
00256       return;
00257 /*
00258 *  Retrieve process grid information
00259 */
00260 #ifdef NO_ARGCHK
00261    Cblacs_gridinfo( ( ctxt = Ad[CTXT_] ), &nprow, &npcol, &myrow, &mycol );
00262 #endif
00263 /*
00264 *  Get type structure
00265 */
00266    type = PB_Cztypeset();
00267 /*
00268 *  Compute descriptor Ad0 for sub( A )
00269 */
00270    PB_Cdescribe( *N, *N, Ai, Aj, Ad, nprow, npcol, myrow, mycol, &Aii, &Ajj,
00271                  &Ald, &Aimb1, &Ainb1, &Amb, &Anb, &Arow, &Acol, Ad0 );
00272 /*
00273 *  Replicate sub( X ) in process rows (XR) and process columns (XC) spanned by
00274 *  sub( A )
00275 */
00276    if( *INCX == Xd[M_] )
00277    {
00278       PB_CInV( type, NOCONJG, ROW,    *N, *N, Ad0, 1, ((char *) X), Xi, Xj,
00279                Xd,   ROW,    &XR, XRd0, &XRfr );
00280       PB_CInV( type, NOCONJG, COLUMN, *N, *N, Ad0, 1, XR,            0,  0,
00281                XRd0, ROW,    &XC, XCd0, &XCfr );
00282    }
00283    else
00284    {
00285       PB_CInV( type, NOCONJG, COLUMN, *N, *N, Ad0, 1, ((char *) X), Xi, Xj,
00286                Xd,   COLUMN, &XC, XCd0, &XCfr );
00287       PB_CInV( type, NOCONJG, ROW,    *N, *N, Ad0, 1, XC,            0, 0,
00288                XCd0, COLUMN, &XR, XRd0, &XRfr );
00289    }
00290 /*
00291 *  Local rank-1 update if I own some data
00292 */
00293    Amp = PB_Cnumroc( *N, 0, Aimb1, Amb, myrow, Arow, nprow );
00294    Anq = PB_Cnumroc( *N, 0, Ainb1, Anb, mycol, Acol, npcol );
00295 
00296    if( ( Amp > 0 ) && ( Anq > 0 ) )
00297    {
00298       size = type->size;
00299       Aptr = Mptr( ((char *) A), Aii, Ajj, Ald, size );
00300 /*
00301 *  Computational partitioning size is computed as the product of the logical
00302 *  value returned by pilaenv_ and 2 * lcm( nprow, npcol ).
00303 */
00304       nb   = 2 * pilaenv_( &ctxt, C2F_CHAR( &type->type ) ) *
00305              PB_Clcm( ( Arow >= 0 ? nprow : 1 ), ( Acol >= 0 ? npcol : 1 ) );
00306 
00307       XCld = XCd0[LLD_]; XRld = XRd0[LLD_];
00308       Calpha[REAL_PART] = ALPHA[REAL_PART];
00309       Calpha[IMAG_PART] = ZERO;
00310 
00311       if( upper )
00312       {
00313          for( k = 0; k < *N; k += nb )
00314          {
00315             kb   = *N - k; kb = MIN( kb, nb );
00316             Akp  = PB_Cnumroc( k,  0, Aimb1, Amb, myrow, Arow, nprow );
00317             Akq  = PB_Cnumroc( k,  0, Ainb1, Anb, mycol, Acol, npcol );
00318             Anq0 = PB_Cnumroc( kb, k, Ainb1, Anb, mycol, Acol, npcol );
00319             if( Akp > 0 && Anq0 > 0 )
00320                zgerc_( &Akp, &Anq0, ((char *) Calpha), XC, &ione,
00321                        Mptr( XR, 0, Akq, XRld, size ), &XRld, Mptr( Aptr, 0,
00322                        Akq, Ald, size ), &Ald );
00323             PB_Cpsyr( type, UPPER, kb, 1, ((char *) Calpha), Mptr( XC, Akp, 0,
00324                       XCld, size ), XCld, Mptr( XR, 0, Akq, XRld, size ), XRld,
00325                       Aptr, k, k, Ad0, PB_Ctzher );
00326          }
00327       }
00328       else
00329       {
00330          for( k = 0; k < *N; k += nb )
00331          {
00332             kb = *N - k; ktmp = k + ( kb = MIN( kb, nb ) );
00333             Akp = PB_Cnumroc( k, 0, Aimb1, Amb, myrow, Arow, nprow );
00334             Akq = PB_Cnumroc( k, 0, Ainb1, Anb, mycol, Acol, npcol );
00335             PB_Cpsyr( type, LOWER, kb, 1, ((char *) Calpha), Mptr( XC, Akp, 0,
00336                       XCld, size ), XCld, Mptr( XR, 0, Akq, XRld, size ), XRld,
00337                       Aptr, k, k, Ad0, PB_Ctzher );
00338             Akp  = PB_Cnumroc( ktmp, 0, Aimb1, Amb, myrow, Arow, nprow );
00339             Amp0 = Amp - Akp;
00340             Anq0 = PB_Cnumroc( kb,   k, Ainb1, Anb, mycol, Acol, npcol );
00341             if( Amp0 > 0 && Anq0 > 0 )
00342                zgerc_( &Amp0, &Anq0, ((char *) Calpha), Mptr( XC, Akp,
00343                        0, XCld, size ), &ione, Mptr( XR, 0, Akq, XRld, size ),
00344                        &XRld, Mptr( Aptr, Akp, Akq, Ald, size ), &Ald );
00345          }
00346       }
00347    }
00348    if( XRfr ) free( XR );
00349    if( XCfr ) free( XC );
00350 /*
00351 *  End of PZHER
00352 */
00353 }