ScaLAPACK  2.0.2
ScaLAPACK: Scalable Linear Algebra PACKage
pspbmv1.f
Go to the documentation of this file.
00001       SUBROUTINE PSPBDCMV( LDBW, BW, UPLO, N, A, JA, DESCA, NRHS, B, IB,
00002      $                     DESCB, X, WORK, LWORK, INFO )
00003 *
00004 *
00005 *
00006 *  -- ScaLAPACK routine (version 1.7) --
00007 *     University of Tennessee, Knoxville, Oak Ridge National Laboratory,
00008 *     and University of California, Berkeley.
00009 *     November 15, 1997
00010 *
00011 *     .. Scalar Arguments ..
00012       CHARACTER          UPLO
00013       INTEGER            BW, IB, INFO, JA, LDBW, LWORK, N, NRHS
00014 *     ..
00015 *     .. Array Arguments ..
00016       INTEGER            DESCA( * ), DESCB( * )
00017       REAL               A( * ), B( * ), WORK( * ), X( * )
00018 *     ..
00019 *
00020 *
00021 *  Purpose
00022 *  =======
00023 *
00024 *
00025 *  =====================================================================
00026 *
00027 *  Arguments
00028 *  =========
00029 *
00030 *  UPLO    (global input) CHARACTER
00031 *          = 'U':  Upper triangle of A(1:N, JA:JA+N-1) is stored;
00032 *          = 'L':  Lower triangle of A(1:N, JA:JA+N-1) is stored.
00033 *
00034 *  N       (global input) INTEGER
00035 *          The number of rows and columns to be operated on, i.e. the
00036 *          order of the distributed submatrix A(1:N, JA:JA+N-1). N >= 0.
00037 *
00038 *  BW      (global input) INTEGER
00039 *          Number of subdiagonals in L or U. 0 <= BW <= N-1
00040 *
00041 *  A       (local input/local output) REAL pointer into
00042 *          local memory to an array with first dimension
00043 *          LLD_A >=(bw+1) (stored in DESCA).
00044 *          On entry, this array contains the local pieces of the
00045 *          This local portion is stored in the packed banded format
00046 *            used in LAPACK. Please see the Notes below and the
00047 *            ScaLAPACK manual for more detail on the format of
00048 *            distributed matrices.
00049 *
00050 *  JA      (global input) INTEGER
00051 *          The index in the global array A that points to the start of
00052 *          the matrix to be operated on (which may be either all of A
00053 *          or a submatrix of A).
00054 *
00055 *  DESCA   (global and local input) INTEGER array of dimension DLEN.
00056 *          if 1D type (DTYPE_A=501), DLEN >= 7;
00057 *          if 2D type (DTYPE_A=1), DLEN >= 9 .
00058 *          The array descriptor for the distributed matrix A.
00059 *          Contains information of mapping of A to memory. Please
00060 *          see NOTES below for full description and options.
00061 *
00062 *  AF      (local output) REAL array, dimension LAF.
00063 *          Auxiliary Fillin Space.
00064 *          Fillin is created during the factorization routine
00065 *          PSPBTRF and this is stored in AF. If a linear system
00066 *          is to be solved using PSPBTRS after the factorization
00067 *          routine, AF *must not be altered* after the factorization.
00068 *
00069 *  LAF     (local input) INTEGER
00070 *          Size of user-input Auxiliary Fillin space AF. Must be >=
00071 *          (NB+2*bw)*bw
00072 *          If LAF is not large enough, an error code will be returned
00073 *          and the minimum acceptable size will be returned in AF( 1 )
00074 *
00075 *  WORK    (local workspace/local output)
00076 *          REAL temporary workspace. This space may
00077 *          be overwritten in between calls to routines. WORK must be
00078 *          the size given in LWORK.
00079 *          On exit, WORK( 1 ) contains the minimal LWORK.
00080 *
00081 *  LWORK   (local input or global input) INTEGER
00082 *          Size of user-input workspace WORK.
00083 *          If LWORK is too small, the minimal acceptable size will be
00084 *          returned in WORK(1) and an error code is returned. LWORK>=
00085 *
00086 *  INFO    (global output) INTEGER
00087 *          = 0:  successful exit
00088 *          < 0:  If the i-th argument is an array and the j-entry had
00089 *                an illegal value, then INFO = -(i*100+j), if the i-th
00090 *                argument is a scalar and had an illegal value, then
00091 *                INFO = -i.
00092 *
00093 *  =====================================================================
00094 *
00095 *
00096 *  Restrictions
00097 *  ============
00098 *
00099 *  The following are restrictions on the input parameters. Some of these
00100 *    are temporary and will be removed in future releases, while others
00101 *    may reflect fundamental technical limitations.
00102 *
00103 *    Non-cyclic restriction: VERY IMPORTANT!
00104 *      P*NB>= mod(JA-1,NB)+N.
00105 *      The mapping for matrices must be blocked, reflecting the nature
00106 *      of the divide and conquer algorithm as a task-parallel algorithm.
00107 *      This formula in words is: no processor may have more than one
00108 *      chunk of the matrix.
00109 *
00110 *    Blocksize cannot be too small:
00111 *      If the matrix spans more than one processor, the following
00112 *      restriction on NB, the size of each block on each processor,
00113 *      must hold:
00114 *      NB >= 2*BW
00115 *      The bulk of parallel computation is done on the matrix of size
00116 *      O(NB) on each processor. If this is too small, divide and conquer
00117 *      is a poor choice of algorithm.
00118 *
00119 *    Submatrix reference:
00120 *      JA = IB
00121 *      Alignment restriction that prevents unnecessary communication.
00122 *
00123 *
00124 *  =====================================================================
00125 *
00126 *
00127 *  Notes
00128 *  =====
00129 *
00130 *  If the factorization routine and the solve routine are to be called
00131 *    separately (to solve various sets of righthand sides using the same
00132 *    coefficient matrix), the auxiliary space AF *must not be altered*
00133 *    between calls to the factorization routine and the solve routine.
00134 *
00135 *  The best algorithm for solving banded and tridiagonal linear systems
00136 *    depends on a variety of parameters, especially the bandwidth.
00137 *    Currently, only algorithms designed for the case N/P >> bw are
00138 *    implemented. These go by many names, including Divide and Conquer,
00139 *    Partitioning, domain decomposition-type, etc.
00140 *
00141 *  Algorithm description: Divide and Conquer
00142 *
00143 *    The Divide and Conqer algorithm assumes the matrix is narrowly
00144 *      banded compared with the number of equations. In this situation,
00145 *      it is best to distribute the input matrix A one-dimensionally,
00146 *      with columns atomic and rows divided amongst the processes.
00147 *      The basic algorithm divides the banded matrix up into
00148 *      P pieces with one stored on each processor,
00149 *      and then proceeds in 2 phases for the factorization or 3 for the
00150 *      solution of a linear system.
00151 *      1) Local Phase:
00152 *         The individual pieces are factored independently and in
00153 *         parallel. These factors are applied to the matrix creating
00154 *         fillin, which is stored in a non-inspectable way in auxiliary
00155 *         space AF. Mathematically, this is equivalent to reordering
00156 *         the matrix A as P A P^T and then factoring the principal
00157 *         leading submatrix of size equal to the sum of the sizes of
00158 *         the matrices factored on each processor. The factors of
00159 *         these submatrices overwrite the corresponding parts of A
00160 *         in memory.
00161 *      2) Reduced System Phase:
00162 *         A small (BW* (P-1)) system is formed representing
00163 *         interaction of the larger blocks, and is stored (as are its
00164 *         factors) in the space AF. A parallel Block Cyclic Reduction
00165 *         algorithm is used. For a linear system, a parallel front solve
00166 *         followed by an analagous backsolve, both using the structure
00167 *         of the factored matrix, are performed.
00168 *      3) Backsubsitution Phase:
00169 *         For a linear system, a local backsubstitution is performed on
00170 *         each processor in parallel.
00171 *
00172 *
00173 *  Descriptors
00174 *  ===========
00175 *
00176 *  Descriptors now have *types* and differ from ScaLAPACK 1.0.
00177 *
00178 *  Note: banded codes can use either the old two dimensional
00179 *    or new one-dimensional descriptors, though the processor grid in
00180 *    both cases *must be one-dimensional*. We describe both types below.
00181 *
00182 *  Each global data object is described by an associated description
00183 *  vector.  This vector stores the information required to establish
00184 *  the mapping between an object element and its corresponding process
00185 *  and memory location.
00186 *
00187 *  Let A be a generic term for any 2D block cyclicly distributed array.
00188 *  Such a global array has an associated description vector DESCA.
00189 *  In the following comments, the character _ should be read as
00190 *  "of the global array".
00191 *
00192 *  NOTATION        STORED IN      EXPLANATION
00193 *  --------------- -------------- --------------------------------------
00194 *  DTYPE_A(global) DESCA( DTYPE_ )The descriptor type.  In this case,
00195 *                                 DTYPE_A = 1.
00196 *  CTXT_A (global) DESCA( CTXT_ ) The BLACS context handle, indicating
00197 *                                 the BLACS process grid A is distribu-
00198 *                                 ted over. The context itself is glo-
00199 *                                 bal, but the handle (the integer
00200 *                                 value) may vary.
00201 *  M_A    (global) DESCA( M_ )    The number of rows in the global
00202 *                                 array A.
00203 *  N_A    (global) DESCA( N_ )    The number of columns in the global
00204 *                                 array A.
00205 *  MB_A   (global) DESCA( MB_ )   The blocking factor used to distribute
00206 *                                 the rows of the array.
00207 *  NB_A   (global) DESCA( NB_ )   The blocking factor used to distribute
00208 *                                 the columns of the array.
00209 *  RSRC_A (global) DESCA( RSRC_ ) The process row over which the first
00210 *                                 row of the array A is distributed.
00211 *  CSRC_A (global) DESCA( CSRC_ ) The process column over which the
00212 *                                 first column of the array A is
00213 *                                 distributed.
00214 *  LLD_A  (local)  DESCA( LLD_ )  The leading dimension of the local
00215 *                                 array.  LLD_A >= MAX(1,LOCr(M_A)).
00216 *
00217 *  Let K be the number of rows or columns of a distributed matrix,
00218 *  and assume that its process grid has dimension p x q.
00219 *  LOCr( K ) denotes the number of elements of K that a process
00220 *  would receive if K were distributed over the p processes of its
00221 *  process column.
00222 *  Similarly, LOCc( K ) denotes the number of elements of K that a
00223 *  process would receive if K were distributed over the q processes of
00224 *  its process row.
00225 *  The values of LOCr() and LOCc() may be determined via a call to the
00226 *  ScaLAPACK tool function, NUMROC:
00227 *          LOCr( M ) = NUMROC( M, MB_A, MYROW, RSRC_A, NPROW ),
00228 *          LOCc( N ) = NUMROC( N, NB_A, MYCOL, CSRC_A, NPCOL ).
00229 *  An upper bound for these quantities may be computed by:
00230 *          LOCr( M ) <= ceil( ceil(M/MB_A)/NPROW )*MB_A
00231 *          LOCc( N ) <= ceil( ceil(N/NB_A)/NPCOL )*NB_A
00232 *
00233 *
00234 *  One-dimensional descriptors:
00235 *
00236 *  One-dimensional descriptors are a new addition to ScaLAPACK since
00237 *    version 1.0. They simplify and shorten the descriptor for 1D
00238 *    arrays.
00239 *
00240 *  Since ScaLAPACK supports two-dimensional arrays as the fundamental
00241 *    object, we allow 1D arrays to be distributed either over the
00242 *    first dimension of the array (as if the grid were P-by-1) or the
00243 *    2nd dimension (as if the grid were 1-by-P). This choice is
00244 *    indicated by the descriptor type (501 or 502)
00245 *    as described below.
00246 *
00247 *    IMPORTANT NOTE: the actual BLACS grid represented by the
00248 *    CTXT entry in the descriptor may be *either*  P-by-1 or 1-by-P
00249 *    irrespective of which one-dimensional descriptor type
00250 *    (501 or 502) is input.
00251 *    This routine will interpret the grid properly either way.
00252 *    ScaLAPACK routines *do not support intercontext operations* so that
00253 *    the grid passed to a single ScaLAPACK routine *must be the same*
00254 *    for all array descriptors passed to that routine.
00255 *
00256 *    NOTE: In all cases where 1D descriptors are used, 2D descriptors
00257 *    may also be used, since a one-dimensional array is a special case
00258 *    of a two-dimensional array with one dimension of size unity.
00259 *    The two-dimensional array used in this case *must* be of the
00260 *    proper orientation:
00261 *      If the appropriate one-dimensional descriptor is DTYPEA=501
00262 *      (1 by P type), then the two dimensional descriptor must
00263 *      have a CTXT value that refers to a 1 by P BLACS grid;
00264 *      If the appropriate one-dimensional descriptor is DTYPEA=502
00265 *      (P by 1 type), then the two dimensional descriptor must
00266 *      have a CTXT value that refers to a P by 1 BLACS grid.
00267 *
00268 *
00269 *  Summary of allowed descriptors, types, and BLACS grids:
00270 *  DTYPE           501         502         1         1
00271 *  BLACS grid      1xP or Px1  1xP or Px1  1xP       Px1
00272 *  -----------------------------------------------------
00273 *  A               OK          NO          OK        NO
00274 *  B               NO          OK          NO        OK
00275 *
00276 *  Let A be a generic term for any 1D block cyclicly distributed array.
00277 *  Such a global array has an associated description vector DESCA.
00278 *  In the following comments, the character _ should be read as
00279 *  "of the global array".
00280 *
00281 *  NOTATION        STORED IN  EXPLANATION
00282 *  --------------- ---------- ------------------------------------------
00283 *  DTYPE_A(global) DESCA( 1 ) The descriptor type. For 1D grids,
00284 *                                TYPE_A = 501: 1-by-P grid.
00285 *                                TYPE_A = 502: P-by-1 grid.
00286 *  CTXT_A (global) DESCA( 2 ) The BLACS context handle, indicating
00287 *                                the BLACS process grid A is distribu-
00288 *                                ted over. The context itself is glo-
00289 *                                bal, but the handle (the integer
00290 *                                value) may vary.
00291 *  N_A    (global) DESCA( 3 ) The size of the array dimension being
00292 *                                distributed.
00293 *  NB_A   (global) DESCA( 4 ) The blocking factor used to distribute
00294 *                                the distributed dimension of the array.
00295 *  SRC_A  (global) DESCA( 5 ) The process row or column over which the
00296 *                                first row or column of the array
00297 *                                is distributed.
00298 *  LLD_A  (local)  DESCA( 6 ) The leading dimension of the local array
00299 *                                storing the local blocks of the distri-
00300 *                                buted array A. Minimum value of LLD_A
00301 *                                depends on TYPE_A.
00302 *                                TYPE_A = 501: LLD_A >=
00303 *                                   size of undistributed dimension, 1.
00304 *                                TYPE_A = 502: LLD_A >=NB_A, 1.
00305 *  Reserved        DESCA( 7 ) Reserved for future use.
00306 *
00307 *
00308 *
00309 *  =====================================================================
00310 *
00311 *  Code Developer: Andrew J. Cleary, University of Tennessee.
00312 *    Current address: Lawrence Livermore National Labs.
00313 *  This version released: August, 2001.
00314 *
00315 *  =====================================================================
00316 *
00317 *     ..
00318 *     .. Parameters ..
00319       REAL               ONE, ZERO
00320       PARAMETER          ( ONE = 1.0E+0 )
00321       PARAMETER          ( ZERO = 0.0E+0 )
00322       INTEGER            INT_ONE
00323       PARAMETER          ( INT_ONE = 1 )
00324       INTEGER            DESCMULT, BIGNUM
00325       PARAMETER          (DESCMULT = 100, BIGNUM = DESCMULT * DESCMULT)
00326       INTEGER            BLOCK_CYCLIC_2D, CSRC_, CTXT_, DLEN_, DTYPE_,
00327      $                   LLD_, MB_, M_, NB_, N_, RSRC_
00328       PARAMETER          ( BLOCK_CYCLIC_2D = 1, DLEN_ = 9, DTYPE_ = 1,
00329      $                     CTXT_ = 2, M_ = 3, N_ = 4, MB_ = 5, NB_ = 6,
00330      $                     RSRC_ = 7, CSRC_ = 8, LLD_ = 9 )
00331 *     ..
00332 *     .. Local Scalars ..
00333       INTEGER            CSRC, DL_N_M, DL_N_N, DL_P_M, DL_P_N,
00334      $                   FIRST_PROC, I, ICTXT, ICTXT_NEW, ICTXT_SAVE,
00335      $                   IDUM1, IDUM3, J, JA_NEW, LLDA, LLDB, MYCOL,
00336      $                   MYROW, MY_NUM_COLS, NB, NP, NPCOL, NPROW,
00337      $                   NP_SAVE, ODD_SIZE, OFST, PART_OFFSET,
00338      $                   PART_SIZE, STORE_M_B, STORE_N_A
00339       INTEGER NUMROC_SIZE
00340 *     ..
00341 *     .. Local Arrays ..
00342       INTEGER            PARAM_CHECK( 16, 3 )
00343 *     ..
00344 *     .. External Subroutines ..
00345       EXTERNAL           BLACS_GRIDINFO, PXERBLA, RESHAPE
00346 *     ..
00347 *     .. External Functions ..
00348       LOGICAL            LSAME
00349       INTEGER            NUMROC
00350       EXTERNAL           LSAME, NUMROC
00351 *     ..
00352 *     .. Intrinsic Functions ..
00353       INTRINSIC          ICHAR, MIN, MOD
00354 *     ..
00355 *     .. Executable Statements ..
00356 *
00357 *     Test the input parameters
00358 *
00359       INFO = 0
00360 *
00361       ICTXT = DESCA( CTXT_ )
00362       CSRC = DESCA( CSRC_ )
00363       NB = DESCA( NB_ )
00364       LLDA = DESCA( LLD_ )
00365       STORE_N_A = DESCA( N_ )
00366       LLDB = DESCB( LLD_ )
00367       STORE_M_B = DESCB( M_ )
00368 *
00369 *
00370 *     Pre-calculate bw^2
00371 *
00372 *
00373       CALL BLACS_GRIDINFO( ICTXT, NPROW, NPCOL, MYROW, MYCOL )
00374       NP = NPROW * NPCOL
00375 *
00376 *
00377 *
00378       IF( LSAME( UPLO, 'U' ) ) THEN
00379          IDUM1 = ICHAR( 'U' )
00380       ELSE IF ( LSAME( UPLO, 'L' ) ) THEN
00381          IDUM1 = ICHAR( 'L' )
00382       ELSE
00383          INFO = -1
00384       END IF
00385 *
00386       IF( LWORK .LT. -1) THEN
00387          INFO = -14
00388       ELSE IF ( LWORK .EQ. -1 ) THEN
00389          IDUM3 = -1
00390       ELSE
00391          IDUM3 = 1
00392       ENDIF
00393 *
00394       IF( N .LT. 0 ) THEN
00395          INFO = -2
00396       ENDIF
00397 *
00398       IF( N+JA-1 .GT. STORE_N_A ) THEN
00399          INFO = -( 7*100 + 6 )
00400       ENDIF
00401 *
00402       IF(( BW .GT. N-1 ) .OR.
00403      $   ( BW .LT. 0 ) ) THEN
00404          INFO = -3
00405       ENDIF
00406 *
00407       IF( LLDA .LT. (BW+1) ) THEN
00408          INFO = -( 7*100 + 6 )
00409       ENDIF
00410 *
00411       IF( NB .LE. 0 ) THEN
00412          INFO = -( 7*100 + 4 )
00413       ENDIF
00414 *
00415 *     Argument checking that is specific to Divide & Conquer routine
00416 *
00417       IF( NPROW .NE. 1 ) THEN
00418          INFO = -( 7*100+2 )
00419       ENDIF
00420 *
00421       IF( N .GT. NP*NB-MOD( JA-1, NB )) THEN
00422          INFO = -( 2 )
00423          CALL PXERBLA( ICTXT,
00424      $      'PSPBDCMV, D&C alg.: only 1 block per proc',
00425      $      -INFO )
00426          RETURN
00427       ENDIF
00428 *
00429       IF((JA+N-1.GT.NB) .AND. ( NB.LT.2*BW )) THEN
00430          INFO = -( 7*100+4 )
00431          CALL PXERBLA( ICTXT,
00432      $      'PSPBDCMV, D&C alg.: NB too small',
00433      $      -INFO )
00434          RETURN
00435       ENDIF
00436 *
00437 *
00438 *     Pack params and positions into arrays for global consistency check
00439 *
00440       PARAM_CHECK( 16, 1 ) = DESCB(5)
00441       PARAM_CHECK( 15, 1 ) = DESCB(4)
00442       PARAM_CHECK( 14, 1 ) = DESCB(3)
00443       PARAM_CHECK( 13, 1 ) = DESCB(2)
00444       PARAM_CHECK( 12, 1 ) = DESCB(1)
00445       PARAM_CHECK( 11, 1 ) = IB
00446       PARAM_CHECK( 10, 1 ) = DESCA(5)
00447       PARAM_CHECK(  9, 1 ) = DESCA(4)
00448       PARAM_CHECK(  8, 1 ) = DESCA(3)
00449       PARAM_CHECK(  7, 1 ) = DESCA(1)
00450       PARAM_CHECK(  6, 1 ) = JA
00451       PARAM_CHECK(  5, 1 ) = NRHS
00452       PARAM_CHECK(  4, 1 ) = BW
00453       PARAM_CHECK(  3, 1 ) = N
00454       PARAM_CHECK(  2, 1 ) = IDUM3
00455       PARAM_CHECK(  1, 1 ) = IDUM1
00456 *
00457       PARAM_CHECK( 16, 2 ) = 1005
00458       PARAM_CHECK( 15, 2 ) = 1004
00459       PARAM_CHECK( 14, 2 ) = 1003
00460       PARAM_CHECK( 13, 2 ) = 1002
00461       PARAM_CHECK( 12, 2 ) = 1001
00462       PARAM_CHECK( 11, 2 ) = 9
00463       PARAM_CHECK( 10, 2 ) = 705
00464       PARAM_CHECK(  9, 2 ) = 704
00465       PARAM_CHECK(  8, 2 ) = 703
00466       PARAM_CHECK(  7, 2 ) = 701
00467       PARAM_CHECK(  6, 2 ) = 6
00468       PARAM_CHECK(  5, 2 ) = 4
00469       PARAM_CHECK(  4, 2 ) = 3
00470       PARAM_CHECK(  3, 2 ) = 2
00471       PARAM_CHECK(  2, 2 ) = 14
00472       PARAM_CHECK(  1, 2 ) = 1
00473 *
00474 *     Want to find errors with MIN( ), so if no error, set it to a big
00475 *     number. If there already is an error, multiply by the the
00476 *     descriptor multiplier.
00477 *
00478       IF( INFO.GE.0 ) THEN
00479          INFO = BIGNUM
00480       ELSE IF( INFO.LT.-DESCMULT ) THEN
00481          INFO = -INFO
00482       ELSE
00483          INFO = -INFO * DESCMULT
00484       END IF
00485 *
00486 *     Check consistency across processors
00487 *
00488       CALL GLOBCHK( ICTXT, 16, PARAM_CHECK, 16,
00489      $              PARAM_CHECK( 1, 3 ), INFO )
00490 *
00491 *     Prepare output: set info = 0 if no error, and divide by DESCMULT
00492 *     if error is not in a descriptor entry.
00493 *
00494       IF( INFO.EQ.BIGNUM ) THEN
00495          INFO = 0
00496       ELSE IF( MOD( INFO, DESCMULT ) .EQ. 0 ) THEN
00497          INFO = -INFO / DESCMULT
00498       ELSE
00499          INFO = -INFO
00500       END IF
00501 *
00502       IF( INFO.LT.0 ) THEN
00503          CALL PXERBLA( ICTXT, 'PSPBDCMV', -INFO )
00504          RETURN
00505       END IF
00506 *
00507 *     Quick return if possible
00508 *
00509       IF( N.EQ.0 )
00510      $   RETURN
00511 *
00512 *
00513 *     Adjust addressing into matrix space to properly get into
00514 *        the beginning part of the relevant data
00515 *
00516       PART_OFFSET = NB*( (JA-1)/(NPCOL*NB) )
00517 *
00518       IF ( (MYCOL-CSRC) .LT. (JA-PART_OFFSET-1)/NB ) THEN
00519          PART_OFFSET = PART_OFFSET + NB
00520       ENDIF
00521 *
00522       IF ( MYCOL .LT. CSRC ) THEN
00523          PART_OFFSET = PART_OFFSET - NB
00524       ENDIF
00525 *
00526 *     Form a new BLACS grid (the "standard form" grid) with only procs
00527 *        holding part of the matrix, of size 1xNP where NP is adjusted,
00528 *        starting at csrc=0, with JA modified to reflect dropped procs.
00529 *
00530 *     First processor to hold part of the matrix:
00531 *
00532       FIRST_PROC = MOD( ( JA-1 )/NB+CSRC, NPCOL )
00533 *
00534 *     Calculate new JA one while dropping off unused processors.
00535 *
00536       JA_NEW = MOD( JA-1, NB ) + 1
00537 *
00538 *     Save and compute new value of NP
00539 *
00540       NP_SAVE = NP
00541       NP = ( JA_NEW+N-2 )/NB + 1
00542 *
00543 *     Call utility routine that forms "standard-form" grid
00544 *
00545       CALL RESHAPE( ICTXT, INT_ONE, ICTXT_NEW, INT_ONE,
00546      $              FIRST_PROC, INT_ONE, NP )
00547 *
00548 *     Use new context from standard grid as context.
00549 *
00550       ICTXT_SAVE = ICTXT
00551       ICTXT = ICTXT_NEW
00552 *
00553 *     Get information about new grid.
00554 *
00555       CALL BLACS_GRIDINFO( ICTXT, NPROW, NPCOL, MYROW, MYCOL )
00556 *
00557 *     Drop out processors that do not have part of the matrix.
00558 *
00559       IF( MYROW .LT. 0 ) THEN
00560          GOTO 1234
00561       ENDIF
00562 *
00563 *     ********************************
00564 *     Values reused throughout routine
00565 *
00566 *     User-input value of partition size
00567 *
00568       PART_SIZE = NB
00569 *
00570 *     Number of columns in each processor
00571 *
00572       MY_NUM_COLS = NUMROC( N, PART_SIZE, MYCOL, 0, NPCOL )
00573 *
00574 *     Offset in columns to beginning of main partition in each proc
00575 *
00576       IF ( MYCOL .EQ. 0 ) THEN
00577         PART_OFFSET = PART_OFFSET+MOD( JA_NEW-1, PART_SIZE )
00578         MY_NUM_COLS = MY_NUM_COLS - MOD(JA_NEW-1, PART_SIZE )
00579       ENDIF
00580 *
00581 *     Offset in elements
00582 *
00583       OFST = PART_OFFSET*LLDA
00584 *
00585 *     Size of main (or odd) partition in each processor
00586 *
00587       ODD_SIZE = MY_NUM_COLS
00588       IF ( MYCOL .LT. NP-1 ) THEN
00589          ODD_SIZE = ODD_SIZE - BW
00590       ENDIF
00591 *
00592 *
00593 *
00594 *       Zero out solution to use to accumulate answer
00595 *
00596         NUMROC_SIZE =
00597      $    NUMROC( N, PART_SIZE, MYCOL, 0, NPCOL)
00598 *
00599         DO 2279 J=1,NRHS
00600           DO 4502 I=1,NUMROC_SIZE
00601             X( (J-1)*LLDB + I ) = ZERO
00602  4502     CONTINUE
00603  2279   CONTINUE
00604 *
00605         DO 5642 I=1, (BW+2)*BW
00606           WORK( I ) = ZERO
00607  5642   CONTINUE
00608 *
00609 *     Begin main code
00610 *
00611 *
00612 **************************************
00613 *
00614       IF ( LSAME( UPLO, 'L' ) ) THEN
00615 *
00616 *       Sizes of the extra triangles communicated bewtween processors
00617 *
00618         IF( MYCOL .GT. 0 ) THEN
00619 *
00620           DL_P_M= MIN( BW,
00621      $          NUMROC( N, PART_SIZE, MYCOL, 0, NPCOL ) )
00622           DL_P_N= MIN( BW,
00623      $          NUMROC( N, PART_SIZE, MYCOL-1, 0, NPCOL ) )
00624         ENDIF
00625 *
00626         IF( MYCOL .LT. NPCOL-1 ) THEN
00627 *
00628           DL_N_M= MIN( BW,
00629      $          NUMROC( N, PART_SIZE, MYCOL+1, 0, NPCOL ) )
00630           DL_N_N= MIN( BW,
00631      $          NUMROC( N, PART_SIZE, MYCOL, 0, NPCOL ) )
00632         ENDIF
00633 *
00634 *
00635         IF( MYCOL .LT. NPCOL-1 ) THEN
00636 *         ...must send triangle in upper half of matrix to right
00637 *
00638 *         Transpose triangle in preparation for sending
00639 *
00640           CALL SLATCPY( 'U', BW, BW,
00641      $          A( LLDA*( NUMROC_SIZE-BW )+1+BW ),
00642      $          LLDA-1, WORK( 1 ), BW )
00643 *
00644 *         Send the triangle to neighboring processor to right
00645 *
00646           CALL STRSD2D(ICTXT, 'L', 'N',
00647      $                  BW, BW,
00648      $                  WORK( 1 ),
00649      $                  BW, MYROW, MYCOL+1 )
00650 *
00651         ENDIF
00652 *
00653 *       Use main partition in each processor to multiply locally
00654 *
00655         CALL SSBMV( 'L', NUMROC_SIZE, BW, ONE, A( OFST+1 ), LLDA,
00656      $              B(PART_OFFSET+1), 1, ZERO, X( PART_OFFSET+1 ), 1 )
00657 *
00658 *
00659 *
00660         IF ( MYCOL .LT. NPCOL-1 ) THEN
00661 *
00662 *         Do the multiplication of the triangle in the lower half
00663 *
00664           CALL SCOPY( DL_N_N,
00665      $                  B( NUMROC_SIZE-DL_N_N+1 ),
00666      $                  1, WORK( BW*BW+1+BW-DL_N_N ), 1 )
00667 *
00668          CALL STRMV( 'U', 'N', 'N', BW,
00669      $            A( LLDA*( NUMROC_SIZE-BW )+1+BW ), LLDA-1,
00670      $            WORK( BW*BW+1 ), 1)
00671 *
00672 *        Zero out extraneous elements caused by TRMV if any
00673 *
00674          IF( DL_N_M .GT. DL_N_N ) THEN
00675         DO 10  I = DL_N_M-DL_N_N, DL_N_M
00676                 WORK( BW*BW+I ) = 0
00677    10   CONTINUE
00678          ENDIF
00679 *
00680 *         Send the result to the neighbor
00681 *
00682           CALL SGESD2D( ICTXT, BW, 1,
00683      $       WORK( BW*BW+1 ), BW, MYROW, MYCOL+1 )
00684 *
00685         ENDIF
00686 *
00687         IF ( MYCOL .GT. 0 ) THEN
00688 *
00689         DO 20  I=1, BW*( BW+2 )
00690           WORK( I ) = ZERO
00691    20   CONTINUE
00692 *
00693 *         Do the multiplication of the triangle in the upper half
00694 *
00695 *         Copy vector to workspace
00696 *
00697           CALL SCOPY( DL_P_M, B( 1 ), 1,
00698      $                  WORK( BW*BW+1 ), 1)
00699 *
00700 *         Receive the triangle prior to multiplying by it.
00701 *
00702           CALL STRRV2D(ICTXT, 'L', 'N',
00703      $                  BW, BW,
00704      $                  WORK( 1 ), BW, MYROW, MYCOL-1 )
00705 *
00706           CALL STRMV(
00707      $     'L',
00708      $     'N',
00709      $     'N', BW,
00710      $     WORK( 1 ), BW,
00711      $     WORK( BW*BW+1 ), 1 )
00712 *
00713 *         Zero out extraneous results from TRMV if any
00714 *
00715           IF( DL_P_M .GT. DL_P_N ) THEN
00716         DO 30  I=1, DL_P_M-DL_P_N
00717               WORK( BW*BW+I ) = 0
00718    30   CONTINUE
00719           ENDIF
00720 *
00721 *         Send result back
00722 *
00723           CALL SGESD2D( ICTXT, BW, 1, WORK(BW*BW+1 ),
00724      $                   BW, MYROW, MYCOL-1 )
00725 *
00726 *         Receive vector result from neighboring processor
00727 *
00728           CALL SGERV2D( ICTXT, BW, 1, WORK( BW*BW+1 ),
00729      $                    BW, MYROW, MYCOL-1 )
00730 *
00731 *         Do addition of received vector
00732 *
00733           CALL SAXPY( BW, ONE,
00734      $                  WORK( BW*BW+1 ), 1,
00735      $                  X( 1 ), 1 )
00736 *
00737         ENDIF
00738 *
00739 *
00740 *
00741          IF( MYCOL .LT. NPCOL-1 ) THEN
00742 *
00743 *          Receive returned result
00744 *
00745            CALL SGERV2D( ICTXT, BW, 1, WORK( BW*BW+1 ),
00746      $                    BW, MYROW, MYCOL+1 )
00747 *
00748 *          Do addition of received vector
00749 *
00750            CALL SAXPY( BW, ONE,
00751      $                  WORK( BW*BW+1 ), 1,
00752      $                  X( NUMROC_SIZE-BW+1 ), 1)
00753 *
00754          ENDIF
00755 *
00756 *
00757       ENDIF
00758 *
00759 *     End of LSAME if
00760 *
00761 **************************************
00762 *
00763       IF ( LSAME( UPLO, 'U' ) ) THEN
00764 *
00765 *       Sizes of the extra triangles communicated bewtween processors
00766 *
00767         IF( MYCOL .GT. 0 ) THEN
00768 *
00769           DL_P_M= MIN( BW,
00770      $          NUMROC( N, PART_SIZE, MYCOL, 0, NPCOL ) )
00771           DL_P_N= MIN( BW,
00772      $          NUMROC( N, PART_SIZE, MYCOL-1, 0, NPCOL ) )
00773         ENDIF
00774 *
00775         IF( MYCOL .LT. NPCOL-1 ) THEN
00776 *
00777           DL_N_M= MIN( BW,
00778      $          NUMROC( N, PART_SIZE, MYCOL+1, 0, NPCOL ) )
00779           DL_N_N= MIN( BW,
00780      $          NUMROC( N, PART_SIZE, MYCOL, 0, NPCOL ) )
00781         ENDIF
00782 *
00783 *
00784         IF( MYCOL .GT. 0 ) THEN
00785 *         ...must send triangle in lower half of matrix to left
00786 *
00787 *         Transpose triangle in preparation for sending
00788 *
00789           CALL SLATCPY( 'L', BW, BW, A( OFST+1 ),
00790      $          LLDA-1, WORK( 1 ), BW )
00791 *
00792 *         Send the triangle to neighboring processor to left
00793 *
00794           CALL STRSD2D(ICTXT, 'U', 'N',
00795      $                  BW, BW,
00796      $                  WORK( 1 ),
00797      $                  BW, MYROW, MYCOL-1 )
00798 *
00799         ENDIF
00800 *
00801 *       Use main partition in each processor to multiply locally
00802 *
00803         CALL SSBMV( 'U', NUMROC_SIZE, BW, ONE, A( OFST+1 ), LLDA,
00804      $              B(PART_OFFSET+1), 1, ZERO, X( PART_OFFSET+1 ), 1 )
00805 *
00806 *
00807 *
00808         IF ( MYCOL .LT. NPCOL-1 ) THEN
00809 *
00810 *         Do the multiplication of the triangle in the lower half
00811 *
00812           CALL SCOPY( DL_N_N,
00813      $                  B( NUMROC_SIZE-DL_N_N+1 ),
00814      $                  1, WORK( BW*BW+1+BW-DL_N_N ), 1 )
00815 *
00816 *         Receive the triangle prior to multiplying by it.
00817 *
00818           CALL STRRV2D(ICTXT, 'U', 'N',
00819      $                  BW, BW,
00820      $                  WORK( 1 ), BW, MYROW, MYCOL+1 )
00821 *
00822          CALL STRMV( 'U', 'N', 'N', BW,
00823      $            WORK( 1 ), BW,
00824      $            WORK( BW*BW+1 ), 1)
00825 *
00826 *        Zero out extraneous elements caused by TRMV if any
00827 *
00828          IF( DL_N_M .GT. DL_N_N ) THEN
00829         DO 40  I = DL_N_M-DL_N_N, DL_N_M
00830                 WORK( BW*BW+I ) = 0
00831    40   CONTINUE
00832          ENDIF
00833 *
00834 *         Send the result to the neighbor
00835 *
00836           CALL SGESD2D( ICTXT, BW, 1,
00837      $       WORK( BW*BW+1 ), BW, MYROW, MYCOL+1 )
00838 *
00839         ENDIF
00840 *
00841         IF ( MYCOL .GT. 0 ) THEN
00842 *
00843         DO 50  I=1, BW*( BW+2 )
00844           WORK( I ) = ZERO
00845    50   CONTINUE
00846 *
00847 *         Do the multiplication of the triangle in the upper half
00848 *
00849 *         Copy vector to workspace
00850 *
00851           CALL SCOPY( DL_P_M, B( 1 ), 1,
00852      $                  WORK( BW*BW+1 ), 1)
00853 *
00854           CALL STRMV(
00855      $     'L',
00856      $     'N',
00857      $     'N', BW,
00858      $     A( 1 ), LLDA-1,
00859      $     WORK( BW*BW+1 ), 1 )
00860 *
00861 *         Zero out extraneous results from TRMV if any
00862 *
00863           IF( DL_P_M .GT. DL_P_N ) THEN
00864         DO 60  I=1, DL_P_M-DL_P_N
00865               WORK( BW*BW+I ) = 0
00866    60   CONTINUE
00867           ENDIF
00868 *
00869 *         Send result back
00870 *
00871           CALL SGESD2D( ICTXT, BW, 1, WORK(BW*BW+1 ),
00872      $                   BW, MYROW, MYCOL-1 )
00873 *
00874 *         Receive vector result from neighboring processor
00875 *
00876           CALL SGERV2D( ICTXT, BW, 1, WORK( BW*BW+1 ),
00877      $                    BW, MYROW, MYCOL-1 )
00878 *
00879 *         Do addition of received vector
00880 *
00881           CALL SAXPY( BW, ONE,
00882      $                  WORK( BW*BW+1 ), 1,
00883      $                  X( 1 ), 1 )
00884 *
00885         ENDIF
00886 *
00887 *
00888 *
00889          IF( MYCOL .LT. NPCOL-1 ) THEN
00890 *
00891 *          Receive returned result
00892 *
00893            CALL SGERV2D( ICTXT, BW, 1, WORK( BW*BW+1 ),
00894      $                    BW, MYROW, MYCOL+1 )
00895 *
00896 *          Do addition of received vector
00897 *
00898            CALL SAXPY( BW, ONE,
00899      $                  WORK( BW*BW+1 ), 1,
00900      $                  X( NUMROC_SIZE-BW+1 ), 1)
00901 *
00902          ENDIF
00903 *
00904 *
00905       ENDIF
00906 *
00907 *     End of LSAME if
00908 *
00909 *
00910 *     Free BLACS space used to hold standard-form grid.
00911 *
00912       IF( ICTXT_SAVE .NE. ICTXT_NEW ) THEN
00913          CALL BLACS_GRIDEXIT( ICTXT_NEW )
00914       ENDIF
00915 *
00916  1234 CONTINUE
00917 *
00918 *     Restore saved input parameters
00919 *
00920       ICTXT = ICTXT_SAVE
00921       NP = NP_SAVE
00922 *
00923 *
00924       RETURN
00925 *
00926 *     End of PSBsBMV1
00927 *
00928       END