Stop a profiling region
If name is omitted, stops the most recently started region (stack-based). If name is provided, stops that specific region (for explicit control). Time is accumulated across multiple start/stop pairs.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| character(len=*), | intent(in), | optional | :: | name |
| Type | Visibility | Attributes | Name | Initial | |||
|---|---|---|---|---|---|---|---|
| logical, | private | :: | found | ||||
| integer(kind=default_int), | private | :: | idx |
subroutine profiler_stop(name) !! Stop a profiling region !! !! If name is omitted, stops the most recently started region (stack-based). !! If name is provided, stops that specific region (for explicit control). !! Time is accumulated across multiple start/stop pairs. character(len=*), intent(in), optional :: name integer(default_int) :: idx logical :: found #ifdef PIC_DISABLE_PROFILER return #endif if (.not. state%enabled) return if (present(name)) then ! Find the region by name. Use an explicit `found` flag instead of ! relying on the DO-variable value after the loop, which is not ! portable (e.g. LFortran leaves it at 0 for a zero-trip loop, ! causing an out-of-bounds access below). found = .false. do idx = 1, state%num_regions if (trim(state%regions(idx)%name) == trim(name)) then found = .true. exit end if end do if (.not. found) return if (.not. state%regions(idx)%active) return ! Remove from stack (may not be at top if using explicit names) call remove_from_stack(idx) else ! Stack-based: pop the most recent region if (state%stack_depth == 0) return idx = state%stack(state%stack_depth) state%stack_depth = state%stack_depth - 1 if (.not. state%regions(idx)%active) return end if call state%regions(idx)%timer%stop() call nvtx_range_pop() state%regions(idx)%total_time = state%regions(idx)%total_time + & state%regions(idx)%timer%get_elapsed_time() state%regions(idx)%call_count = state%regions(idx)%call_count + 1 state%regions(idx)%active = .false. end subroutine profiler_stop