ScaLAPACK  2.0.2
ScaLAPACK: Scalable Linear Algebra PACKage
pclase2.f
Go to the documentation of this file.
00001       SUBROUTINE PCLASE2( UPLO, M, N, ALPHA, BETA, A, IA, JA, DESCA )
00002 *
00003 *  -- ScaLAPACK auxiliary routine (version 1.7) --
00004 *     University of Tennessee, Knoxville, Oak Ridge National Laboratory,
00005 *     and University of California, Berkeley.
00006 *     May 1, 1997
00007 *
00008 *     .. Scalar Arguments ..
00009       CHARACTER          UPLO
00010       INTEGER            IA, JA, M, N
00011       COMPLEX            ALPHA, BETA
00012 *     ..
00013 *     .. Array Arguments ..
00014       INTEGER            DESCA( * )
00015       COMPLEX            A( * )
00016 *     ..
00017 *
00018 *  Purpose
00019 *  =======
00020 *
00021 *  PCLASE2 initializes an M-by-N distributed matrix sub( A ) denoting
00022 *  A(IA:IA+M-1,JA:JA+N-1) to BETA on the diagonal and ALPHA on the
00023 *  offdiagonals.  PCLASE2 requires that only dimension of the matrix
00024 *  operand is distributed.
00025 *
00026 *  Notes
00027 *  =====
00028 *
00029 *  Each global data object is described by an associated description
00030 *  vector.  This vector stores the information required to establish
00031 *  the mapping between an object element and its corresponding process
00032 *  and memory location.
00033 *
00034 *  Let A be a generic term for any 2D block cyclicly distributed array.
00035 *  Such a global array has an associated description vector DESCA.
00036 *  In the following comments, the character _ should be read as
00037 *  "of the global array".
00038 *
00039 *  NOTATION        STORED IN      EXPLANATION
00040 *  --------------- -------------- --------------------------------------
00041 *  DTYPE_A(global) DESCA( DTYPE_ )The descriptor type.  In this case,
00042 *                                 DTYPE_A = 1.
00043 *  CTXT_A (global) DESCA( CTXT_ ) The BLACS context handle, indicating
00044 *                                 the BLACS process grid A is distribu-
00045 *                                 ted over. The context itself is glo-
00046 *                                 bal, but the handle (the integer
00047 *                                 value) may vary.
00048 *  M_A    (global) DESCA( M_ )    The number of rows in the global
00049 *                                 array A.
00050 *  N_A    (global) DESCA( N_ )    The number of columns in the global
00051 *                                 array A.
00052 *  MB_A   (global) DESCA( MB_ )   The blocking factor used to distribute
00053 *                                 the rows of the array.
00054 *  NB_A   (global) DESCA( NB_ )   The blocking factor used to distribute
00055 *                                 the columns of the array.
00056 *  RSRC_A (global) DESCA( RSRC_ ) The process row over which the first
00057 *                                 row of the array A is distributed.
00058 *  CSRC_A (global) DESCA( CSRC_ ) The process column over which the
00059 *                                 first column of the array A is
00060 *                                 distributed.
00061 *  LLD_A  (local)  DESCA( LLD_ )  The leading dimension of the local
00062 *                                 array.  LLD_A >= MAX(1,LOCr(M_A)).
00063 *
00064 *  Let K be the number of rows or columns of a distributed matrix,
00065 *  and assume that its process grid has dimension p x q.
00066 *  LOCr( K ) denotes the number of elements of K that a process
00067 *  would receive if K were distributed over the p processes of its
00068 *  process column.
00069 *  Similarly, LOCc( K ) denotes the number of elements of K that a
00070 *  process would receive if K were distributed over the q processes of
00071 *  its process row.
00072 *  The values of LOCr() and LOCc() may be determined via a call to the
00073 *  ScaLAPACK tool function, NUMROC:
00074 *          LOCr( M ) = NUMROC( M, MB_A, MYROW, RSRC_A, NPROW ),
00075 *          LOCc( N ) = NUMROC( N, NB_A, MYCOL, CSRC_A, NPCOL ).
00076 *  An upper bound for these quantities may be computed by:
00077 *          LOCr( M ) <= ceil( ceil(M/MB_A)/NPROW )*MB_A
00078 *          LOCc( N ) <= ceil( ceil(N/NB_A)/NPCOL )*NB_A
00079 *
00080 *  Arguments
00081 *  =========
00082 *
00083 *  UPLO    (global input) CHARACTER
00084 *          Specifies the part of the distributed matrix sub( A ) to be
00085 *          set:
00086 *          = 'U':      Upper triangular part is set; the strictly lower
00087 *                      triangular part of sub( A ) is not changed;
00088 *          = 'L':      Lower triangular part is set; the strictly upper
00089 *                      triangular part of sub( A ) is not changed;
00090 *          Otherwise:  All of the matrix sub( A ) is set.
00091 *
00092 *  M       (global input) INTEGER
00093 *          The number of rows to be operated on i.e the number of rows
00094 *          of the distributed submatrix sub( A ). M >= 0.
00095 *
00096 *  N       (global input) INTEGER
00097 *          The number of columns to be operated on i.e the number of
00098 *          columns of the distributed submatrix sub( A ). N >= 0.
00099 *
00100 *  ALPHA   (global input) COMPLEX
00101 *          The constant to which the offdiagonal elements are to be
00102 *          set.
00103 *
00104 *  BETA    (global input) COMPLEX
00105 *          The constant to which the diagonal elements are to be set.
00106 *
00107 *  A       (local output) COMPLEX pointer into the local memory
00108 *          to an array of dimension (LLD_A,LOCc(JA+N-1)).  This array
00109 *          contains the local pieces of the distributed matrix sub( A )
00110 *          to be set.  On exit, the leading M-by-N submatrix sub( A )
00111 *          is set as follows:
00112 *
00113 *          if UPLO = 'U', A(IA+i-1,JA+j-1) = ALPHA, 1<=i<=j-1, 1<=j<=N,
00114 *          if UPLO = 'L', A(IA+i-1,JA+j-1) = ALPHA, j+1<=i<=M, 1<=j<=N,
00115 *          otherwise,     A(IA+i-1,JA+j-1) = ALPHA, 1<=i<=M, 1<=j<=N,
00116 *                                                   IA+i.NE.JA+j,
00117 *          and, for all UPLO, A(IA+i-1,JA+i-1) = BETA, 1<=i<=min(M,N).
00118 *
00119 *  IA      (global input) INTEGER
00120 *          The row index in the global array A indicating the first
00121 *          row of sub( A ).
00122 *
00123 *  JA      (global input) INTEGER
00124 *          The column index in the global array A indicating the
00125 *          first column of sub( A ).
00126 *
00127 *  DESCA   (global and local input) INTEGER array of dimension DLEN_.
00128 *          The array descriptor for the distributed matrix A.
00129 *
00130 *  =====================================================================
00131 *
00132 *     .. Parameters ..
00133       INTEGER            BLOCK_CYCLIC_2D, CSRC_, CTXT_, DLEN_, DTYPE_,
00134      $                   LLD_, MB_, M_, NB_, N_, RSRC_
00135       PARAMETER          ( BLOCK_CYCLIC_2D = 1, DLEN_ = 9, DTYPE_ = 1,
00136      $                     CTXT_ = 2, M_ = 3, N_ = 4, MB_ = 5, NB_ = 6,
00137      $                     RSRC_ = 7, CSRC_ = 8, LLD_ = 9 )
00138 *     ..
00139 *     .. Local Scalars ..
00140       INTEGER            HEIGHT, IACOL, IAROW, IBASE, ICOFFA, II, IIA,
00141      $                   IIBEG, IIEND, IINXT, ILEFT, IRIGHT, IROFFA,
00142      $                   ITOP, JJ, JJA, JJBEG, JJEND, JJNXT, LDA, MBA,
00143      $                   MP, MPA, MYCOL, MYDIST, MYROW, NBA, NPCOL,
00144      $                   NPROW, NQ, NQA, WIDE
00145 *     ..
00146 *     .. External Subroutines ..
00147       EXTERNAL           BLACS_GRIDINFO, CLASET, INFOG2L
00148 *     ..
00149 *     .. External Functions ..
00150       LOGICAL            LSAME
00151       INTEGER            ICEIL, NUMROC
00152       EXTERNAL           ICEIL, LSAME, NUMROC
00153 *     ..
00154 *     .. Intrinsic Functions ..
00155       INTRINSIC          MAX, MIN, MOD
00156 *     ..
00157 *     .. Executable Statements ..
00158 *
00159       IF( M.EQ.0 .OR. N.EQ.0 )
00160      $   RETURN
00161 *
00162 *     Get grid parameters
00163 *
00164       CALL BLACS_GRIDINFO( DESCA( CTXT_ ), NPROW, NPCOL, MYROW, MYCOL )
00165 *
00166       CALL INFOG2L( IA, JA, DESCA, NPROW, NPCOL, MYROW, MYCOL, IIA, JJA,
00167      $              IAROW, IACOL )
00168       MBA = DESCA( MB_ )
00169       NBA = DESCA( NB_ )
00170       LDA = DESCA( LLD_ )
00171       IROFFA = MOD( IA-1, MBA )
00172       ICOFFA = MOD( JA-1, NBA )
00173 *
00174       IF( N.LE.( NBA-ICOFFA ) ) THEN
00175 *
00176 *        It is assumed that the local columns JJA:JJA+N-1 of the matrix
00177 *        A are in the same process column (IACOL).
00178 *
00179 *                         N
00180 *                JJA             JJA+N-1
00181 *         /      ---------------------    \
00182 *   IROFFA|      |                   |    |
00183 *         \      |...................|    |       ( IAROW )
00184 *           IIA  |x                  |    | MB_A
00185 *                | x                 |    |
00186 *                |--x----------------|    /
00187 *                |   x               |
00188 *                |    x              |        ITOP
00189 *                |     x             |          |
00190 *                |      x            |      /-------\
00191 *                |-------x-----------|      |-------x-----------|
00192 *                |        x          |      |        x          |
00193 *                |         x         |      |         x         |
00194 *                |          x        |      |          x        |
00195 *                |           x       |      |           x       |
00196 *                |------------x------|      |------------x------|
00197 *                |             x     |      \____________/
00198 *                |              x    |            |
00199 *                |               x   |          IBASE
00200 *                |                x  |
00201 *                |-----------------x-|          Local picture
00202 *                |                  x|
00203 *                |                   |
00204 *                |                   |
00205 *                |                   |
00206 *                |-------------------|
00207 *                |                   |
00208 *                .                   .
00209 *                .                   .
00210 *                .      (IACOL)      .
00211 *
00212          IF( MYCOL.EQ.IACOL ) THEN
00213 *
00214             MPA = NUMROC( M+IROFFA, MBA, MYROW, IAROW, NPROW )
00215             IF( MPA.LE.0 )
00216      $         RETURN
00217             IF( MYROW.EQ.IAROW )
00218      $         MPA = MPA - IROFFA
00219             MYDIST = MOD( MYROW-IAROW+NPROW, NPROW )
00220             ITOP = MYDIST * MBA - IROFFA
00221 *
00222             IF( LSAME( UPLO, 'U' ) ) THEN
00223 *
00224                ITOP = MAX( 0, ITOP )
00225                IIBEG = IIA
00226                IIEND = IIA + MPA - 1
00227                IINXT = MIN( ICEIL( IIBEG, MBA ) * MBA, IIEND )
00228 *
00229    10          CONTINUE
00230                IF( ( N-ITOP ).GT.0 ) THEN
00231                   CALL CLASET( UPLO, IINXT-IIBEG+1, N-ITOP, ALPHA, BETA,
00232      $                         A( IIBEG+(JJA+ITOP-1)*LDA ), LDA )
00233                   MYDIST = MYDIST + NPROW
00234                   ITOP = MYDIST * MBA - IROFFA
00235                   IIBEG = IINXT +1
00236                   IINXT = MIN( IINXT+MBA, IIEND )
00237                   GO TO 10
00238                END IF
00239 *
00240             ELSE IF( LSAME( UPLO, 'L' ) ) THEN
00241 *
00242                II = IIA
00243                JJ = JJA
00244                MP = MPA
00245                IBASE = MIN( ITOP+MBA, N )
00246                ITOP = MIN( MAX( 0, ITOP ), N )
00247 *
00248    20          CONTINUE
00249                IF( JJ.LE.( JJA+N-1 ) ) THEN
00250                   HEIGHT = IBASE - ITOP
00251                   CALL CLASET( 'All', MP, ITOP-JJ+JJA, ALPHA, ALPHA,
00252      $                         A( II+(JJ-1)*LDA ), LDA )
00253                   CALL CLASET( UPLO, MP, HEIGHT, ALPHA, BETA,
00254      $                         A( II+(JJA+ITOP-1)*LDA ), LDA )
00255                   MP = MAX( 0, MP - HEIGHT )
00256                   II = II + HEIGHT
00257                   JJ = JJA + IBASE
00258                   MYDIST = MYDIST + NPROW
00259                   ITOP = MYDIST * MBA - IROFFA
00260                   IBASE = MIN( ITOP + MBA, N )
00261                   ITOP = MIN( ITOP, N )
00262                   GO TO 20
00263                END IF
00264 *
00265             ELSE
00266 *
00267                II = IIA
00268                JJ = JJA
00269                MP = MPA
00270                IBASE = MIN( ITOP+MBA, N )
00271                ITOP = MIN( MAX( 0, ITOP ), N )
00272 *
00273    30          CONTINUE
00274                IF( JJ.LE.( JJA+N-1 ) ) THEN
00275                   HEIGHT = IBASE - ITOP
00276                   CALL CLASET( 'All', MPA, ITOP-JJ+JJA, ALPHA, ALPHA,
00277      $                         A( IIA+(JJ-1)*LDA ), LDA )
00278                   CALL CLASET( 'All', MPA-MP, HEIGHT, ALPHA, ALPHA,
00279      $                         A( IIA+(JJA+ITOP-1)*LDA ), LDA )
00280                   CALL CLASET( 'All', MP, HEIGHT, ALPHA, BETA,
00281      $                         A( II+(JJA+ITOP-1)*LDA ), LDA )
00282                   MP = MAX( 0, MP - HEIGHT )
00283                   II = II + HEIGHT
00284                   JJ = JJA + IBASE
00285                   MYDIST = MYDIST + NPROW
00286                   ITOP = MYDIST * MBA - IROFFA
00287                   IBASE = MIN( ITOP + MBA, N )
00288                   ITOP = MIN( ITOP, N )
00289                   GO TO 30
00290                END IF
00291 *
00292             END IF
00293 *
00294          END IF
00295 *
00296       ELSE IF( M.LE.( MBA-IROFFA ) ) THEN
00297 *
00298 *        It is assumed that the local rows IIA:IIA+M-1 of the matrix A
00299 *        are in the same process row (IAROW).
00300 *
00301 *            ICOFFA
00302 *             / \JJA
00303 *        IIA  ------------------ ....            --------
00304 *             | .x  |    |    |                 / |    | \
00305 *             | . x |    |    |            ILEFT| |    | |
00306 *             | .  x     |    |                 | |    | |
00307 *             | .   x    |    |                 \ x    | |
00308 *             | .   |x   |    |                   |x   | | IRIGHT
00309 *             | .   | x  |    |                   | x  | |
00310 *    (IAROW)  | .   |  x |    |                   |  x | |
00311 *             | .   |   x|    |                   |   x| |
00312 *             | .   |    x    |                   |    x /
00313 *             | .   |    |x   |                   |    |
00314 *             | .   |    | x  |                   |    |
00315 *             | .   |    |  x |                   |    |
00316 *             | .   |    |   x|                   |    |
00317 *    IIA+M-1  ------------------ ....            -------
00318 *              NB_A
00319 *             (IACOL)                          Local picture
00320 *
00321          IF( MYROW.EQ.IAROW ) THEN
00322 *
00323             NQA = NUMROC( N+ICOFFA, NBA, MYCOL, IACOL, NPCOL )
00324             IF( NQA.LE.0 )
00325      $         RETURN
00326             IF( MYCOL.EQ.IACOL )
00327      $         NQA = NQA - ICOFFA
00328             MYDIST = MOD( MYCOL-IACOL+NPCOL, NPCOL )
00329             ILEFT = MYDIST * NBA - ICOFFA
00330 *
00331             IF( LSAME( UPLO, 'L' ) ) THEN
00332 *
00333                ILEFT = MAX( 0, ILEFT )
00334                JJBEG = JJA
00335                JJEND = JJA + NQA - 1
00336                JJNXT = MIN( ICEIL( JJBEG, NBA ) * NBA, JJEND )
00337 *
00338    40          CONTINUE
00339                IF( ( M-ILEFT ).GT.0 ) THEN
00340                   CALL CLASET( UPLO, M-ILEFT, JJNXT-JJBEG+1, ALPHA,
00341      $                         BETA, A( IIA+ILEFT+(JJBEG-1)*LDA ), LDA )
00342                   MYDIST = MYDIST + NPCOL
00343                   ILEFT = MYDIST * NBA - ICOFFA
00344                   JJBEG = JJNXT +1
00345                   JJNXT = MIN( JJNXT+NBA, JJEND )
00346                   GO TO 40
00347                END IF
00348 *
00349             ELSE IF( LSAME( UPLO, 'U' ) ) THEN
00350 *
00351                II = IIA
00352                JJ = JJA
00353                NQ = NQA
00354                IRIGHT = MIN( ILEFT+NBA, M )
00355                ILEFT = MIN( MAX( 0, ILEFT ), M )
00356 *
00357    50          CONTINUE
00358                IF( II.LE.( IIA+M-1 ) ) THEN
00359                   WIDE = IRIGHT - ILEFT
00360                   CALL CLASET( 'All', ILEFT-II+IIA, NQ, ALPHA, ALPHA,
00361      $                         A( II+(JJ-1)*LDA ), LDA )
00362                   CALL CLASET( UPLO, WIDE, NQ, ALPHA, BETA,
00363      $                         A( IIA+ILEFT+(JJ-1)*LDA ), LDA )
00364                   NQ = MAX( 0, NQ - WIDE )
00365                   II = IIA + IRIGHT
00366                   JJ = JJ + WIDE
00367                   MYDIST = MYDIST + NPCOL
00368                   ILEFT = MYDIST * NBA - ICOFFA
00369                   IRIGHT = MIN( ILEFT + NBA, M )
00370                   ILEFT = MIN( ILEFT, M )
00371                   GO TO 50
00372                END IF
00373 *
00374             ELSE
00375 *
00376                II = IIA
00377                JJ = JJA
00378                NQ = NQA
00379                IRIGHT = MIN( ILEFT+NBA, M )
00380                ILEFT = MIN( MAX( 0, ILEFT ), M )
00381 *
00382    60          CONTINUE
00383                IF( II.LE.( IIA+M-1 ) ) THEN
00384                   WIDE = IRIGHT - ILEFT
00385                   CALL CLASET( 'All', ILEFT-II+IIA, NQA, ALPHA, ALPHA,
00386      $                         A( II+(JJA-1)*LDA ), LDA )
00387                   CALL CLASET( 'All', WIDE, NQA-NQ, ALPHA, ALPHA,
00388      $                         A( IIA+ILEFT+(JJA-1)*LDA ), LDA )
00389                   CALL CLASET( 'All', WIDE, NQ, ALPHA, BETA,
00390      $                         A( IIA+ILEFT+(JJ-1)*LDA ), LDA )
00391                   NQ = MAX( 0, NQ - WIDE )
00392                   II = IIA + IRIGHT
00393                   JJ = JJ + WIDE
00394                   MYDIST = MYDIST + NPCOL
00395                   ILEFT = MYDIST * NBA - ICOFFA
00396                   IRIGHT = MIN( ILEFT + NBA, M )
00397                   ILEFT = MIN( ILEFT, M )
00398                   GO TO 60
00399                END IF
00400 *
00401             END IF
00402 *
00403          END IF
00404 *
00405       END IF
00406 *
00407       RETURN
00408 *
00409 *     End of PCLASE2
00410 *
00411       END