srtdat Subroutine

private subroutine srtdat(n, Nnz, Indrow, Indcol, Jpntr, Iwa)

given the non-zero elements of an m by n matrix a in arbitrary order as specified by their row and column indices, this subroutine permutes these elements so that their column indices are in non-decreasing order.

on input it is assumed that the elements are specified in

indrow(k),indcol(k), k = 1,...,nnz.

on output the elements are permuted so that indcol is in non-decreasing order. in addition, the array jpntr is set so that the row indices for column j are

indrow(k), k = jpntr(j),...,jpntr(j+1)-1.

note that the value of m is not needed by srtdat and is therefore not present in the subroutine statement.

Arguments

Type IntentOptional Attributes Name
integer :: n

a positive integer input variable set to the number of columns of a.

integer :: Nnz

a positive integer input variable set to the number of non-zero elements of a.

integer, dimension(Nnz) :: Indrow

an integer array of length nnz. on input indrow must contain the row indices of the non-zero elements of a. on output indrow is permuted so that the corresponding column indices of indcol are in non-decreasing order.

integer, dimension(Nnz) :: Indcol

an integer array of length nnz. on input indcol must contain the column indices of the non-zero elements of a. on output indcol is permuted so that these indices are in non-decreasing order.

integer, dimension(n+1) :: Jpntr

an integer output array of length n + 1 which specifies the locations of the row indices in the output indrow. the row indices for column j are indrow(k), k = jpntr(j),...,jpntr(j+1)-1. note that jpntr(1) is set to 1 and that jpntr(n+1)-1 is then nnz.

integer, dimension(n) :: Iwa

an integer work array of length n.


Called by

proc~~srtdat~~CalledByGraph proc~srtdat dsm_module::srtdat proc~dsm dsm_module::dsm proc~dsm->proc~srtdat proc~dsm_wrapper numerical_differentiation_module::sparsity_pattern%dsm_wrapper proc~dsm_wrapper->proc~dsm proc~compute_sparsity_random numerical_differentiation_module::compute_sparsity_random proc~compute_sparsity_random->proc~dsm_wrapper proc~compute_sparsity_random_2 numerical_differentiation_module::compute_sparsity_random_2 proc~compute_sparsity_random_2->proc~dsm_wrapper proc~set_sparsity_pattern numerical_differentiation_module::numdiff_type%set_sparsity_pattern proc~set_sparsity_pattern->proc~dsm_wrapper

Source Code

    subroutine srtdat(n,Nnz,Indrow,Indcol,Jpntr,Iwa)

    implicit none

    integer                :: n       !! a positive integer input variable set to the number
                                      !! of columns of `a`.
    integer                :: Nnz     !! a positive integer input variable set to the number
                                      !! of non-zero elements of `a`.
    integer,dimension(Nnz) :: Indrow  !! an integer array of length `nnz`. on input `indrow`
                                      !! must contain the row indices of the non-zero elements of `a`.
                                      !! on output `indrow` is permuted so that the corresponding
                                      !! column indices of `indcol` are in non-decreasing order.
    integer,dimension(Nnz) :: Indcol  !! an integer array of length `nnz`. on input `indcol`
                                      !! must contain the column indices of the non-zero elements
                                      !! of `a`. on output `indcol` is permuted so that these indices
                                      !! are in non-decreasing order.
    integer,dimension(n+1) :: Jpntr   !! an integer output array of length `n + 1` which
                                      !! specifies the locations of the row indices in the output
                                      !! `indrow`. the row indices for column `j` are
                                      !! `indrow(k), k = jpntr(j),...,jpntr(j+1)-1`.
                                      !! **note** that `jpntr(1)` is set to 1 and that `jpntr(n+1)-1`
                                      !! is then `nnz`.
    integer,dimension(n)   :: Iwa     !! an integer work array of length `n`.

    integer :: i , j , k , l

    ! store in array iwa the counts of non-zeroes in the columns.

    do j = 1 , n
        Iwa(j) = 0
    enddo
    do k = 1 , Nnz
        Iwa(Indcol(k)) = Iwa(Indcol(k)) + 1
    enddo

    ! set pointers to the start of the columns in indrow.

    Jpntr(1) = 1
    do j = 1 , n
        Jpntr(j+1) = Jpntr(j) + Iwa(j)
        Iwa(j) = Jpntr(j)
    enddo
    k = 1

    ! begin in-place sort.

    do
        j = Indcol(k)
        if ( k>=Jpntr(j) ) then
            ! current element is in position. now examine the
            ! next element or the first un-sorted element in
            ! the j-th group.
            k = max(k+1,Iwa(j))
        else
            ! current element is not in position. place element
            ! in position and make the displaced element the
            ! current element.
            l = Iwa(j)
            Iwa(j) = Iwa(j) + 1
            i = Indrow(k)
            Indrow(k) = Indrow(l)
            Indcol(k) = Indcol(l)
            Indrow(l) = i
            Indcol(l) = j
        endif
        if ( k>Nnz ) exit
    end do

    end subroutine srtdat