compute_indices Subroutine

private subroutine compute_indices(me, n)

Computes the indices vector in the class, and the column index (col_ptr, col_idx) of the sparsity pattern.

Note

The column index is only computed if icol has been populated (or there are no nonzero elements). It must be called again if icol is changed.

Type Bound

sparsity_pattern

Arguments

Type IntentOptional Attributes Name
class(sparsity_pattern), intent(inout) :: me
integer, intent(in) :: n

number of columns in the jacobian


Called by

proc~~compute_indices~~CalledByGraph proc~compute_indices sparsity_pattern%compute_indices proc~compute_sparsity_dense compute_sparsity_dense proc~compute_sparsity_dense->proc~compute_indices proc~compute_sparsity_random compute_sparsity_random proc~compute_sparsity_random->proc~compute_indices proc~compute_sparsity_random_2 compute_sparsity_random_2 proc~compute_sparsity_random_2->proc~compute_indices proc~set_sparsity_pattern numdiff_type%set_sparsity_pattern proc~set_sparsity_pattern->proc~compute_indices

Source Code

    subroutine compute_indices(me,n)

    implicit none

    class(sparsity_pattern),intent(inout) :: me
    integer,intent(in) :: n  !! number of columns in the jacobian

    integer :: i !! counter
    integer :: j !! column number
    integer,dimension(:),allocatable :: next !! next free position in `col_idx` for each column

    if (allocated(me%indices)) deallocate(me%indices)
    allocate(me%indices(me%num_nonzero_elements))
    do i = 1, me%num_nonzero_elements
        me%indices(i) = i
    end do

    ! column index (a stable counting sort of the elements by column,
    ! so the elements in each column stay in their original order):
    if (allocated(me%col_ptr)) deallocate(me%col_ptr)
    if (allocated(me%col_idx)) deallocate(me%col_idx)
    if (.not. allocated(me%icol) .and. me%num_nonzero_elements>0) return
    allocate(me%col_ptr(n+1))
    allocate(me%col_idx(me%num_nonzero_elements))
    me%col_ptr = 0
    do i = 1, me%num_nonzero_elements
        j = me%icol(i)
        me%col_ptr(j+1) = me%col_ptr(j+1) + 1
    end do
    me%col_ptr(1) = 1
    do j = 1, n
        me%col_ptr(j+1) = me%col_ptr(j+1) + me%col_ptr(j)
    end do
    next = me%col_ptr(1:n)
    do i = 1, me%num_nonzero_elements
        j = me%icol(i)
        me%col_idx(next(j)) = i
        next(j) = next(j) + 1
    end do

    end subroutine compute_indices