Nullify graph using visit_tag for O(1) cycle detection
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| class(array_type), | intent(inout), | target | :: | this | ||
| logical, | intent(in), | optional | :: | ignore_ownership |
module subroutine nullify_graph(this, ignore_ownership) !! Nullify graph using visit_tag for O(1) cycle detection implicit none class(array_type), intent(inout), target :: this logical, intent(in), optional :: ignore_ownership type(array_ptr), allocatable :: dealloc_list(:) type(array_type), pointer :: node_to_dealloc integer :: i, dealloc_count, visit_id, dealloc_id logical :: ignore_ownership_ ignore_ownership_ = .not.this%is_forward if(present(ignore_ownership)) ignore_ownership_ = ignore_ownership ! Increment global counter by 2: one for visited, one for dealloc tracking diffstruc__visit_counter = diffstruc__visit_counter + 2 visit_id = diffstruc__visit_counter - 1 dealloc_id = diffstruc__visit_counter dealloc_count = 0 ! Traverse graph with O(1) visited checks via visit_tag call nullify_graph_recursive(this, dealloc_list, dealloc_count, & ignore_ownership_, visit_id, dealloc_id) ! Deallocate collected nodes if(allocated(dealloc_list))then do i = 1, dealloc_count if(associated(dealloc_list(i)%p))then node_to_dealloc => dealloc_list(i)%p if(node_to_dealloc%allocated)then call node_to_dealloc%deallocate() end if node_to_dealloc%is_temporary = .true. deallocate(node_to_dealloc) nullify(dealloc_list(i)%p) end if end do deallocate(dealloc_list) end if end subroutine nullify_graph