csort
C CSORT SOURCE CHAT 05/01/12 22:32:01 5004 IMPLICIT INTEGER(I-N) IMPLICIT REAL*8 (A-H,O-Z) C*********************************************************************** C NOM : CSORT C DESCRIPTION : Ordonnancement du profil ou d'une matrice Morse. C C C LANGAGE : FORTRAN 77 C ADAPTATION : Stéphane GOUNAND (CEA/DRN/DMT/SEMT/LTMF) C mél : gounand@semt2.smts.cea.fr C AUTEUR : C Sparskit : a basic tool kit for sparse matrix computations C Version 2 (Youcef Saad) C -> URL : http://www.cs.umn.edu/Research/arpa/SPARSKIT/sparskit.html C C*********************************************************************** LOGICAL VALUES INTEGER N, JA(*), IA(N+1), IWORK(*) REAL*8 A(*) c----------------------------------------------------------------------- c This routine sorts the elements of a matrix (stored in Compressed c Sparse Row Format) in increasing order of their column indices within c each row. It uses a form of bucket sort with a cost of O(nnz) where c nnz = number of nonzero elements. c requires an integer work array of length 2*nnz. c----------------------------------------------------------------------- c on entry: c--------- c n = the row dimension of the matrix c a = the matrix A in compressed sparse row format. c ja = the array of column indices of the elements in array a. c ia = the array of pointers to the rows. c iwork = integer work array of length max ( n+1, 2*nnz ) c where nnz = (ia(n+1)-ia(1)) ) . c values= logical indicating whether or not the real values a(*) must c also be permuted. if (.not. values) then the array a is not c touched by csort and can be a dummy array. c c on return: c---------- c the matrix stored in the structure a, ja, ia is permuted in such a c way that the column indices are in increasing order within each row. c iwork(1:nnz) contains the permutation used to rearrange the elements. c----------------------------------------------------------------------- c Y. Saad - Feb. 1, 1991. c----------------------------------------------------------------------- c local variables INTEGER I, K, J, IFIRST, NNZ, NEXT INTEGER IROW,KO c c count the number of elements in each column c * gounand : déjà fait * DO 1 I=1,N+1 * IWORK(I) = 0 * 1 CONTINUE DO 3 I=1, N DO 2 K=IA(I), IA(I+1)-1 J = JA(K)+1 IWORK(J) = IWORK(J)+1 2 CONTINUE 3 CONTINUE c c compute pointers from lengths. c IWORK(1) = 1 DO 4 I=1,N IWORK(I+1) = IWORK(I) + IWORK(I+1) 4 CONTINUE C C get the positions of the nonzero elements in order of columns. C IFIRST = IA(1) NNZ = IA(N+1)-IFIRST DO 5 I=1,N DO 51 K=IA(I),IA(I+1)-1 J = JA(K) NEXT = IWORK(J) IWORK(NNZ+NEXT) = K IWORK(J) = NEXT+1 51 CONTINUE 5 CONTINUE c c convert to coordinate format c DO 6 I=1, N DO 61 K=IA(I), IA(I+1)-1 IWORK(K) = I 61 CONTINUE 6 CONTINUE c c loop to find permutation: for each element find the correct c position in (sorted) arrays a, ja. Record this in iwork. c DO 7 K=1, NNZ KO = IWORK(NNZ+K) IROW = IWORK(KO) NEXT = IA(IROW) c c the current element should go in next position in row. iwork c records this position. c IWORK(KO) = NEXT IA(IROW) = NEXT+1 7 CONTINUE c c perform an in-place permutation of the arrays. c c c reshift the pointers of the original matrix back. c DO 8 I=N,1,-1 IA(I+1) = IA(I) 8 CONTINUE IA(1) = IFIRST c RETURN c---------------end-of-csort-------------------------------------------- c----------------------------------------------------------------------- END
© Cast3M 2003 - Tous droits réservés.
Mentions légales