ScaLAPACK  2.0.2
ScaLAPACK: Scalable Linear Algebra PACKage
pdlaevswp.f
Go to the documentation of this file.
00001 *
00002 *
00003       SUBROUTINE PDLAEVSWP( N, ZIN, LDZI, Z, IZ, JZ, DESCZ, NVS, KEY,
00004      $                      WORK, LWORK )
00005 *
00006 *  -- ScaLAPACK routine (version 1.7) --
00007 *     University of Tennessee, Knoxville, Oak Ridge National Laboratory,
00008 *     and University of California, Berkeley.
00009 *     April 15, 1997
00010 *
00011 *     .. Scalar Arguments ..
00012       INTEGER            IZ, JZ, LDZI, LWORK, N
00013 *     ..
00014 *     .. Array Arguments ..
00015       INTEGER            DESCZ( * ), KEY( * ), NVS( * )
00016       DOUBLE PRECISION   WORK( * ), Z( * ), ZIN( LDZI, * )
00017 *     ..
00018 *
00019 *  Purpose
00020 *  =======
00021 *
00022 *  PDLAEVSWP moves the eigenvectors (potentially unsorted) from
00023 *  where they are computed, to a ScaLAPACK standard block cyclic
00024 *  array, sorted so that the corresponding eigenvalues are sorted.
00025 *
00026 *  Notes
00027 *  =====
00028 *
00029 *
00030 *  Each global data object is described by an associated description
00031 *  vector.  This vector stores the information required to establish
00032 *  the mapping between an object element and its corresponding process
00033 *  and memory location.
00034 *
00035 *  Let A be a generic term for any 2D block cyclicly distributed array.
00036 *  Such a global array has an associated description vector DESCA.
00037 *  In the following comments, the character _ should be read as
00038 *  "of the global array".
00039 *
00040 *  NOTATION        STORED IN      EXPLANATION
00041 *  --------------- -------------- --------------------------------------
00042 *  DTYPE_A(global) DESCA( DTYPE_ )The descriptor type.  In this case,
00043 *                                 DTYPE_A = 1.
00044 *  CTXT_A (global) DESCA( CTXT_ ) The BLACS context handle, indicating
00045 *                                 the BLACS process grid A is distribu-
00046 *                                 ted over. The context itself is glo-
00047 *                                 bal, but the handle (the integer
00048 *                                 value) may vary.
00049 *  M_A    (global) DESCA( M_ )    The number of rows in the global
00050 *                                 array A.
00051 *  N_A    (global) DESCA( N_ )    The number of columns in the global
00052 *                                 array A.
00053 *  MB_A   (global) DESCA( MB_ )   The blocking factor used to distribute
00054 *                                 the rows of the array.
00055 *  NB_A   (global) DESCA( NB_ )   The blocking factor used to distribute
00056 *                                 the columns of the array.
00057 *  RSRC_A (global) DESCA( RSRC_ ) The process row over which the first
00058 *                                 row of the array A is distributed.
00059 *  CSRC_A (global) DESCA( CSRC_ ) The process column over which the
00060 *                                 first column of the array A is
00061 *                                 distributed.
00062 *  LLD_A  (local)  DESCA( LLD_ )  The leading dimension of the local
00063 *                                 array.  LLD_A >= MAX(1,LOCr(M_A)).
00064 *
00065 *  Let K be the number of rows or columns of a distributed matrix,
00066 *  and assume that its process grid has dimension p x q.
00067 *  LOCr( K ) denotes the number of elements of K that a process
00068 *  would receive if K were distributed over the p processes of its
00069 *  process column.
00070 *  Similarly, LOCc( K ) denotes the number of elements of K that a
00071 *  process would receive if K were distributed over the q processes of
00072 *  its process row.
00073 *  The values of LOCr() and LOCc() may be determined via a call to the
00074 *  ScaLAPACK tool function, NUMROC:
00075 *          LOCr( M ) = NUMROC( M, MB_A, MYROW, RSRC_A, NPROW ),
00076 *          LOCc( N ) = NUMROC( N, NB_A, MYCOL, CSRC_A, NPCOL ).
00077 *  An upper bound for these quantities may be computed by:
00078 *          LOCr( M ) <= ceil( ceil(M/MB_A)/NPROW )*MB_A
00079 *          LOCc( N ) <= ceil( ceil(N/NB_A)/NPCOL )*NB_A
00080 *
00081 *
00082 *  Arguments
00083 *  =========
00084 *
00085 *     NP = the number of rows local to a given process.
00086 *     NQ = the number of columns local to a given process.
00087 *
00088 *  N       (global input) INTEGER
00089 *          The order of the matrix A.  N >= 0.
00090 *
00091 *  ZIN     (local input) DOUBLE PRECISION array,
00092 *          dimension ( LDZI, NVS(iam) )
00093 *          The eigenvectors on input.  Each eigenvector resides entirely
00094 *          in one process.  Each process holds a contiguous set of
00095 *          NVS(iam) eigenvectors.  The first eigenvector which the
00096 *          process holds is:  sum for i=[0,iam-1) of NVS(i)
00097 *
00098 *  LDZI    (locl input) INTEGER
00099 *          leading dimension of the ZIN array
00100 *
00101 *  Z       (local output) DOUBLE PRECISION array
00102 *          global dimension (N, N), local dimension (DESCZ(DLEN_), NQ)
00103 *          The eigenvectors on output.  The eigenvectors are distributed
00104 *          in a block cyclic manner in both dimensions, with a
00105 *          block size of NB.
00106 *
00107 *  IZ      (global input) INTEGER
00108 *          Z's global row index, which points to the beginning of the
00109 *          submatrix which is to be operated on.
00110 *
00111 *  JZ      (global input) INTEGER
00112 *          Z's global column index, which points to the beginning of
00113 *          the submatrix which is to be operated on.
00114 *
00115 *  DESCZ   (global and local input) INTEGER array of dimension DLEN_.
00116 *          The array descriptor for the distributed matrix Z.
00117 *
00118 *  NVS     (global input) INTEGER array, dimension( nprocs+1 )
00119 *          nvs(i) = number of processes
00120 *          number of eigenvectors held by processes [0,i-1)
00121 *          nvs(1) = number of eigen vectors held by [0,1-1) == 0
00122 *          nvs(nprocs+1) = number of eigen vectors held by [0,nprocs) ==
00123 *            total number of eigenvectors
00124 *
00125 *  KEY     (global input) INTEGER array, dimension( N )
00126 *          Indicates the actual index (after sorting) for each of the
00127 *          eigenvectors.
00128 *
00129 *  WORK    (local workspace) DOUBLE PRECISION array, dimension (LWORK)
00130 *
00131 *  LWORK   (local input) INTEGER dimension of WORK
00132 *     .. Parameters ..
00133       INTEGER            BLOCK_CYCLIC_2D, DLEN_, DTYPE_, CTXT_, M_, N_,
00134      $                   MB_, NB_, RSRC_, CSRC_, LLD_
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            CYCLIC_I, CYCLIC_J, DIST, I, IAM, II, INCII, J,
00141      $                   MAXI, MAXII, MINI, MINII, MYCOL, MYROW, NB,
00142      $                   NBUFSIZE, NPCOL, NPROCS, NPROW, PCOL, RECVCOL,
00143      $                   RECVFROM, RECVROW, SENDCOL, SENDROW, SENDTO
00144 *     ..
00145 *     .. External Functions ..
00146       INTEGER            INDXG2L, INDXG2P
00147       EXTERNAL           INDXG2L, INDXG2P
00148 *     ..
00149 *     .. External Subroutines ..
00150       EXTERNAL           BLACS_GRIDINFO, DGERV2D, DGESD2D
00151 *     ..
00152 *     .. Intrinsic Functions ..
00153       INTRINSIC          MAX, MIN, MOD
00154 *     ..
00155 *     .. Executable Statements ..
00156 *       This is just to keep ftnchek happy
00157       IF( BLOCK_CYCLIC_2D*CSRC_*CTXT_*DLEN_*DTYPE_*LLD_*MB_*M_*NB_*N_*
00158      $    RSRC_.LT.0 )RETURN
00159       CALL BLACS_GRIDINFO( DESCZ( CTXT_ ), NPROW, NPCOL, MYROW, MYCOL )
00160       IAM = MYROW + MYCOL*NPROW
00161       IAM = MYROW*NPCOL + MYCOL
00162 *
00163       NB = DESCZ( MB_ )
00164 *
00165       NPROCS = NPROW*NPCOL
00166 *
00167 *     If PxSTEIN operates on a sub-matrix of a global matrix, the
00168 *     key [] that contains the indicies of the eigenvectors is refe-
00169 *     renced to the dimensions of the sub-matrix and not the global
00170 *     distrubited matrix. Because of this, PxLAEVSWP will incorrectly
00171 *     map the eigenvectors to the global eigenvector matrix, Z, unless
00172 *     the key[] elements are shifted as below.
00173 *
00174       DO 10 J = DESCZ( N_ ), 1, -1
00175          KEY( J ) = KEY( J-JZ+1 ) + ( JZ-1 )
00176    10 CONTINUE
00177 *
00178       DO 110 DIST = 0, NPROCS - 1
00179 *
00180          SENDTO = MOD( IAM+DIST, NPROCS )
00181          RECVFROM = MOD( NPROCS+IAM-DIST, NPROCS )
00182 *
00183          SENDROW = MOD( SENDTO, NPROW )
00184          SENDCOL = SENDTO / NPROW
00185          RECVROW = MOD( RECVFROM, NPROW )
00186          RECVCOL = RECVFROM / NPROW
00187 *
00188          SENDROW = SENDTO / NPCOL
00189          SENDCOL = MOD( SENDTO, NPCOL )
00190          RECVROW = RECVFROM / NPCOL
00191          RECVCOL = MOD( RECVFROM, NPCOL )
00192 *
00193 *        Figure out what I have that process "sendto" wants
00194 *
00195          NBUFSIZE = 0
00196 *
00197 *        We are looping through the eigenvectors that I presently own.
00198 *
00199          DO 40 J = NVS( 1+IAM ) + JZ, NVS( 1+IAM+1 ) + JZ - 1
00200             PCOL = INDXG2P( KEY( J ), DESCZ( NB_ ), -1, DESCZ( CSRC_ ),
00201      $             NPCOL )
00202             IF( SENDCOL.EQ.PCOL ) THEN
00203                MINII = MOD( SENDROW+DESCZ( RSRC_ ), NPROW )*
00204      $                 DESCZ( MB_ ) + 1
00205                MAXII = DESCZ( M_ )
00206                INCII = DESCZ( MB_ )*NPROW
00207                DO 30 II = MINII, MAXII, INCII
00208                   MINI = MAX( II, IZ )
00209                   MAXI = MIN( II+DESCZ( MB_ )-1, N+IZ-1 )
00210                   DO 20 I = MINI, MAXI, 1
00211                      NBUFSIZE = NBUFSIZE + 1
00212                      WORK( NBUFSIZE ) = ZIN( I+1-IZ,
00213      $                                  J-NVS( 1+IAM )+1-JZ )
00214    20             CONTINUE
00215    30          CONTINUE
00216             END IF
00217    40    CONTINUE
00218 *
00219 *
00220          IF( MYROW.NE.SENDROW .OR. MYCOL.NE.SENDCOL )
00221      $      CALL DGESD2D( DESCZ( CTXT_ ), NBUFSIZE, 1, WORK, NBUFSIZE,
00222      $                    SENDROW, SENDCOL )
00223 *
00224 *
00225 *        Figure out what process "recvfrom" has that I want
00226 *
00227          NBUFSIZE = 0
00228          DO 70 J = NVS( 1+RECVFROM ) + JZ,
00229      $           NVS( 1+RECVFROM+1 ) + JZ - 1, 1
00230             PCOL = INDXG2P( KEY( J ), DESCZ( NB_ ), -1, DESCZ( CSRC_ ),
00231      $             NPCOL )
00232             IF( MYCOL.EQ.PCOL ) THEN
00233                MINII = MOD( MYROW+DESCZ( RSRC_ ), NPROW )*DESCZ( MB_ ) +
00234      $                 1
00235                MAXII = DESCZ( M_ )
00236                INCII = DESCZ( MB_ )*NPROW
00237                DO 60 II = MINII, MAXII, INCII
00238                   MINI = MAX( II, IZ )
00239                   MAXI = MIN( II+NB-1, N+IZ-1 )
00240                   DO 50 I = MINI, MAXI, 1
00241                      NBUFSIZE = NBUFSIZE + 1
00242    50             CONTINUE
00243    60          CONTINUE
00244             END IF
00245    70    CONTINUE
00246 *
00247 *
00248 *
00249          IF( MYROW.NE.RECVROW .OR. MYCOL.NE.RECVCOL )
00250      $      CALL DGERV2D( DESCZ( CTXT_ ), 1, NBUFSIZE, WORK, 1, RECVROW,
00251      $                    RECVCOL )
00252 *
00253          NBUFSIZE = 0
00254          DO 100 J = NVS( 1+RECVFROM ) + JZ,
00255      $           NVS( 1+RECVFROM+1 ) + JZ - 1, 1
00256             PCOL = INDXG2P( KEY( J ), DESCZ( NB_ ), -1, DESCZ( CSRC_ ),
00257      $             NPCOL )
00258             IF( MYCOL.EQ.PCOL ) THEN
00259                CYCLIC_J = INDXG2L( KEY( J ), DESCZ( MB_ ), -1, -1,
00260      $                    NPCOL )
00261                CYCLIC_I = 1
00262                MINII = MOD( MYROW+DESCZ( RSRC_ ), NPROW )*DESCZ( MB_ ) +
00263      $                 1
00264                MAXII = DESCZ( M_ )
00265                INCII = DESCZ( MB_ )*NPROW
00266                DO 90 II = MINII, MAXII, INCII
00267                   MINI = MAX( II, IZ )
00268                   CYCLIC_I = INDXG2L( MINI, DESCZ( MB_ ), -1, -1,
00269      $                       NPROW )
00270                   MAXI = MIN( II+NB-1, N+IZ-1 )
00271                   DO 80 I = MINI, MAXI, 1
00272                      NBUFSIZE = NBUFSIZE + 1
00273                      Z( CYCLIC_I+( CYCLIC_J-1 )*DESCZ( LLD_ ) )
00274      $                  = WORK( NBUFSIZE )
00275                      CYCLIC_I = CYCLIC_I + 1
00276    80             CONTINUE
00277    90          CONTINUE
00278             END IF
00279   100    CONTINUE
00280 *
00281   110 CONTINUE
00282       RETURN
00283 *
00284 *     End of PDLAEVSWP
00285 *
00286       END