*DECK DS2Y
SUBROUTINE DS2Y (N, NELT, IA, JA, A, ISYM)
C***BEGIN PROLOGUE DS2Y
C***PURPOSE SLAP Triad to SLAP Column Format Converter.
C Routine to convert from the SLAP Triad to SLAP Column
C format.
C***LIBRARY SLATEC (SLAP)
C***CATEGORY D1B9
C***TYPE DOUBLE PRECISION (SS2Y-S, DS2Y-D)
C***KEYWORDS LINEAR SYSTEM, SLAP SPARSE
C***AUTHOR Seager, Mark K., (LLNL)
C Lawrence Livermore National Laboratory
C PO BOX 808, L-60
C Livermore, CA 94550 (510) 423-3141
C seager@llnl.gov
C***DESCRIPTION
C
C *Usage:
C INTEGER N, NELT, IA(NELT), JA(NELT), ISYM
C DOUBLE PRECISION A(NELT)
C
C CALL DS2Y( N, NELT, IA, JA, A, ISYM )
C
C *Arguments:
C N :IN Integer
C Order of the Matrix.
C NELT :IN Integer.
C Number of non-zeros stored in A.
C IA :INOUT Integer IA(NELT).
C JA :INOUT Integer JA(NELT).
C A :INOUT Double Precision A(NELT).
C These arrays should hold the matrix A in either the SLAP
C Triad format or the SLAP Column format. See "Description",
C below. If the SLAP Triad format is used, this format is
C translated to the SLAP Column format by this routine.
C ISYM :IN Integer.
C Flag to indicate symmetric storage format.
C If ISYM=0, all non-zero entries of the matrix are stored.
C If ISYM=1, the matrix is symmetric, and only the lower
C triangle of the matrix is stored.
C
C *Description:
C The Sparse Linear Algebra Package (SLAP) utilizes two matrix
C data structures: 1) the SLAP Triad format or 2) the SLAP
C Column format. The user can hand this routine either of the
C of these data structures. If the SLAP Triad format is give
C as input then this routine transforms it into SLAP Column
C format. The way this routine tells which format is given as
C input is to look at JA(N+1). If JA(N+1) = NELT+1 then we
C have the SLAP Column format. If that equality does not hold
C then it is assumed that the IA, JA, A arrays contain the
C SLAP Triad format.
C
C =================== S L A P Triad format ===================
C This routine requires that the matrix A be stored in the
C SLAP Triad format. In this format only the non-zeros are
C stored. They may appear in *ANY* order. The user supplies
C three arrays of length NELT, where NELT is the number of
C non-zeros in the matrix: (IA(NELT), JA(NELT), A(NELT)). For
C each non-zero the user puts the row and column index of that
C matrix element in the IA and JA arrays. The value of the
C non-zero matrix element is placed in the corresponding
C location of the A array. This is an extremely easy data
C structure to generate. On the other hand it is not too
C efficient on vector computers for the iterative solution of
C linear systems. Hence, SLAP changes this input data
C structure to the SLAP Column format for the iteration (but
C does not change it back).
C
C Here is an example of the SLAP Triad storage format for a
C 5x5 Matrix. Recall that the entries may appear in any order.
C
C 5x5 Matrix SLAP Triad format for 5x5 matrix on left.
C 1 2 3 4 5 6 7 8 9 10 11
C |11 12 0 0 15| A: 51 12 11 33 15 53 55 22 35 44 21
C |21 22 0 0 0| IA: 5 1 1 3 1 5 5 2 3 4 2
C | 0 0 33 0 35| JA: 1 2 1 3 5 3 5 2 5 4 1
C | 0 0 0 44 0|
C |51 0 53 0 55|
C
C =================== S L A P Column format ==================
C
C This routine requires that the matrix A be stored in the
C SLAP Column format. In this format the non-zeros are stored
C counting down columns (except for the diagonal entry, which
C must appear first in each "column") and are stored in the
C double precision array A. In other words, for each column
C in the matrix put the diagonal entry in A. Then put in the
C other non-zero elements going down the column (except the
C diagonal) in order. The IA array holds the row index for
C each non-zero. The JA array holds the offsets into the IA,
C A arrays for the beginning of each column. That is,
C IA(JA(ICOL)), A(JA(ICOL)) points to the beginning of the
C ICOL-th column in IA and A. IA(JA(ICOL+1)-1),
C A(JA(ICOL+1)-1) points to the end of the ICOL-th column.
C Note that we always have JA(N+1) = NELT+1, where N is the
C number of columns in the matrix and NELT is the number of
C non-zeros in the matrix.
C
C Here is an example of the SLAP Column storage format for a
C 5x5 Matrix (in the A and IA arrays '|' denotes the end of a
C column):
C
C 5x5 Matrix SLAP Column format for 5x5 matrix on left.
C 1 2 3 4 5 6 7 8 9 10 11
C |11 12 0 0 15| A: 11 21 51 | 22 12 | 33 53 | 44 | 55 15 35
C |21 22 0 0 0| IA: 1 2 5 | 2 1 | 3 5 | 4 | 5 1 3
C | 0 0 33 0 35| JA: 1 4 6 8 9 12
C | 0 0 0 44 0|
C |51 0 53 0 55|
C
C***REFERENCES (NONE)
C***ROUTINES CALLED QS2I1D
C***REVISION HISTORY (YYMMDD)
C 871119 DATE WRITTEN
C 881213 Previous REVISION DATE
C 890915 Made changes requested at July 1989 CML Meeting. (MKS)
C 890922 Numerous changes to prologue to make closer to SLATEC
C standard. (FNF)
C 890929 Numerous changes to reduce SP/DP differences. (FNF)
C 910411 Prologue converted to Version 4.0 format. (BAB)
C 910502 Corrected C***FIRST EXECUTABLE STATEMENT line. (FNF)
C 920511 Added complete declaration section. (WRB)
C 930701 Updated CATEGORY section. (FNF, WRB)
C***END PROLOGUE DS2Y
C .. Scalar Arguments ..
INTEGER ISYM, N, NELT
C .. Array Arguments ..
DOUBLE PRECISION A(NELT)
INTEGER IA(NELT), JA(NELT)
C .. Local Scalars ..
DOUBLE PRECISION TEMP
INTEGER I, IBGN, ICOL, IEND, ITEMP, J
C .. External Subroutines ..
EXTERNAL QS2I1D
C***FIRST EXECUTABLE STATEMENT DS2Y
C
C Check to see if the (IA,JA,A) arrays are in SLAP Column
C format. If it's not then transform from SLAP Triad.
C
IF( JA(N+1).EQ.NELT+1 ) RETURN
C
C Sort into ascending order by COLUMN (on the ja array).
C This will line up the columns.
C
CALL QS2I1D( JA, IA, A, NELT, 1 )
C
C Loop over each column to see where the column indices change
C in the column index array ja. This marks the beginning of the
C next column.
C
CVD$R NOVECTOR
JA(1) = 1
DO 20 ICOL = 1, N-1
DO 10 J = JA(ICOL)+1, NELT
IF( JA(J).NE.ICOL ) THEN
JA(ICOL+1) = J
GOTO 20
ENDIF
10 CONTINUE
20 CONTINUE
JA(N+1) = NELT+1
C
C Mark the n+2 element so that future calls to a SLAP routine
C utilizing the YSMP-Column storage format will be able to tell.
C
JA(N+2) = 0
C
C Now loop through the IA array making sure that the diagonal
C matrix element appears first in the column. Then sort the
C rest of the column in ascending order.
C
DO 70 ICOL = 1, N
IBGN = JA(ICOL)
IEND = JA(ICOL+1)-1
DO 30 I = IBGN, IEND
IF( IA(I).EQ.ICOL ) THEN
C
C Swap the diagonal element with the first element in the
C column.
C
ITEMP = IA(I)
IA(I) = IA(IBGN)
IA(IBGN) = ITEMP
TEMP = A(I)
A(I) = A(IBGN)
A(IBGN) = TEMP
GOTO 40
ENDIF
30 CONTINUE
40 IBGN = IBGN + 1
IF( IBGN.LT.IEND ) THEN
DO 60 I = IBGN, IEND
DO 50 J = I+1, IEND
IF( IA(I).GT.IA(J) ) THEN
ITEMP = IA(I)
IA(I) = IA(J)
IA(J) = ITEMP
TEMP = A(I)
A(I) = A(J)
A(J) = TEMP
ENDIF
50 CONTINUE
60 CONTINUE
ENDIF
70 CONTINUE
RETURN
C------------- LAST LINE OF DS2Y FOLLOWS ----------------------------
END