get_node_neighbors Subroutine

private subroutine get_node_neighbors(self, node_id, neighbors)

Type Bound

type_node_adjacency

Arguments

Type IntentOptional Attributes Name
class(type_node_adjacency), intent(in) :: self
integer(kind=int32), intent(in) :: node_id
integer(kind=int32), intent(out), allocatable :: neighbors(:)

Called by

proc~~get_node_neighbors~~CalledByGraph proc~get_node_neighbors type_node_adjacency%get_node_neighbors proc~sort_and_enqueue_neighbors sort_and_enqueue_neighbors proc~sort_and_enqueue_neighbors->proc~get_node_neighbors proc~execute_cm_ordering execute_cm_ordering proc~execute_cm_ordering->proc~sort_and_enqueue_neighbors proc~cm_reorder_method cm_reorder_method proc~cm_reorder_method->proc~execute_cm_ordering proc~rcm_reorder_method rcm_reorder_method proc~rcm_reorder_method->proc~execute_cm_ordering interface~cm_reorder_method type_reordering%cm_reorder_method interface~cm_reorder_method->proc~cm_reorder_method interface~rcm_reorder_method type_reordering%rcm_reorder_method interface~rcm_reorder_method->proc~rcm_reorder_method proc~initialize_type_reordering type_reordering%initialize_type_reordering proc~initialize_type_reordering->interface~cm_reorder_method proc~initialize_type_reordering->interface~rcm_reorder_method

Source Code

    subroutine get_node_neighbors(self, node_id, neighbors)
        class(type_node_adjacency), intent(in) :: self
        integer(int32), intent(in) :: node_id
        integer(int32), allocatable, intent(out) :: neighbors(:)

        integer(int32) :: degree, start_p, end_p

        if (node_id < 1 .or. node_id > self%num_nodes) then
            ! 不正なノードIDの場合は、0サイズの配列を返す
            if (allocated(neighbors)) deallocate (neighbors)
            allocate (neighbors(0))
            return
        end if

        ! 1. 隣接ノードの数(次数)を計算
        start_p = self%ptr(node_id)
        end_p = self%ptr(node_id + 1) - 1
        degree = end_p - start_p + 1

        ! 2. 戻り値の配列を確保]
        if (allocated(neighbors)) deallocate (neighbors)
        allocate (neighbors(degree))

        ! 3. self%indから隣接ノードのリストをコピー
        neighbors = self%ind(start_p:end_p)

    end subroutine get_node_neighbors