mirror of
https://gitlab.com/scemama/irpf90.git
synced 2024-12-22 12:23:32 +01:00
Cleaned irp_stack
This commit is contained in:
parent
002db06d15
commit
e0f8e66e7e
150
src/irp_stack.py
150
src/irp_stack.py
@ -41,52 +41,25 @@ def create():
|
|||||||
txt = """
|
txt = """
|
||||||
module irp_stack_mod
|
module irp_stack_mod
|
||||||
integer, parameter :: STACKMAX=1000
|
integer, parameter :: STACKMAX=1000
|
||||||
character*(128),allocatable :: irp_stack(:,:)
|
character*(128),allocatable :: irp_stack(:)
|
||||||
double precision,allocatable :: irp_cpu(:,:)
|
double precision,allocatable :: irp_cpu(:)
|
||||||
integer,allocatable :: stack_index(:)
|
integer :: stack_index
|
||||||
logical :: alloc = .False.
|
logical :: alloc = .False.
|
||||||
integer :: nthread
|
|
||||||
character*(128) :: white = ''
|
character*(128) :: white = ''
|
||||||
end module
|
end module
|
||||||
|
|
||||||
subroutine irp_enter(irp_where)
|
subroutine irp_enter(irp_where)
|
||||||
use irp_stack_mod
|
use irp_stack_mod
|
||||||
integer :: ithread
|
|
||||||
character*(*) :: irp_where
|
character*(*) :: irp_where
|
||||||
"""
|
"""
|
||||||
if not do_openmp:
|
|
||||||
txt += """
|
|
||||||
ithread = 0
|
|
||||||
"""
|
|
||||||
else:
|
|
||||||
txt += """
|
|
||||||
integer, external :: omp_get_thread_num
|
|
||||||
integer, external :: omp_get_num_threads
|
|
||||||
ithread = omp_get_thread_num()
|
|
||||||
"""
|
|
||||||
|
|
||||||
txt += "$1"
|
txt += "$1"
|
||||||
|
|
||||||
if do_memory:
|
if do_memory:
|
||||||
txt+="""
|
txt+="""
|
||||||
if (.not.alloc) then
|
if (.not.alloc) then
|
||||||
"""
|
print *, 'Allocating irp_stack(',STACKMAX+1,')'
|
||||||
if do_openmp:
|
print *, 'Allocating irp_cpu(',STACKMAX+1,')'
|
||||||
txt += """
|
|
||||||
!$OMP PARALLEL
|
|
||||||
!$OMP SINGLE
|
|
||||||
nthread = omp_get_num_threads()
|
|
||||||
!$OMP END SINGLE
|
|
||||||
!$OMP END PARALLEL
|
|
||||||
"""
|
|
||||||
else:
|
|
||||||
txt += """
|
|
||||||
nthread = 1
|
|
||||||
"""
|
|
||||||
txt += """
|
|
||||||
print *, 'Allocating irp_stack(',STACKMAX,',',0:nthread,')'
|
|
||||||
print *, 'Allocating irp_cpu(',STACKMAX,',',0:nthread,')'
|
|
||||||
print *, 'Allocating stack_index(',0:nthread,')'
|
|
||||||
endif"""
|
endif"""
|
||||||
txt +="""
|
txt +="""
|
||||||
$2
|
$2
|
||||||
@ -94,42 +67,14 @@ end subroutine
|
|||||||
|
|
||||||
subroutine irp_enter_f(irp_where)
|
subroutine irp_enter_f(irp_where)
|
||||||
use irp_stack_mod
|
use irp_stack_mod
|
||||||
integer :: ithread
|
|
||||||
character*(*) :: irp_where
|
character*(*) :: irp_where
|
||||||
"""
|
|
||||||
if do_openmp:
|
|
||||||
txt += """
|
|
||||||
integer, external :: omp_get_thread_num
|
|
||||||
integer, external :: omp_get_num_threads
|
|
||||||
ithread = omp_get_thread_num()
|
|
||||||
"""
|
|
||||||
else:
|
|
||||||
txt += """
|
|
||||||
ithread = 0
|
|
||||||
"""
|
|
||||||
txt += """
|
|
||||||
$1
|
$1
|
||||||
"""
|
"""
|
||||||
if do_memory:
|
if do_memory:
|
||||||
txt+="""
|
txt+="""
|
||||||
if (.not.alloc) then
|
if (.not.alloc) then
|
||||||
"""
|
print *, 'Allocating irp_stack(',STACKMAX+1,')'
|
||||||
if do_openmp:
|
print *, 'Allocating irp_cpu(',STACKMAX+1,')'
|
||||||
txt += """
|
|
||||||
!$OMP PARALLEL
|
|
||||||
!$OMP SINGLE
|
|
||||||
nthread = omp_get_num_threads()
|
|
||||||
!$OMP END SINGLE
|
|
||||||
!$OMP END PARALLEL
|
|
||||||
"""
|
|
||||||
else:
|
|
||||||
txt += """
|
|
||||||
nthread = 1
|
|
||||||
"""
|
|
||||||
txt +="""
|
|
||||||
print *, 'Allocating irp_stack(',STACKMAX,',',0:nthread,')'
|
|
||||||
print *, 'Allocating irp_cpu(',STACKMAX,',',0:nthread,')'
|
|
||||||
print *, 'Allocating stack_index(',0:nthread,')'
|
|
||||||
endif
|
endif
|
||||||
"""
|
"""
|
||||||
txt += """
|
txt += """
|
||||||
@ -139,19 +84,7 @@ end subroutine
|
|||||||
subroutine irp_leave (irp_where)
|
subroutine irp_leave (irp_where)
|
||||||
use irp_stack_mod
|
use irp_stack_mod
|
||||||
character*(*) :: irp_where
|
character*(*) :: irp_where
|
||||||
integer :: ithread
|
|
||||||
double precision :: cpu
|
double precision :: cpu
|
||||||
"""
|
|
||||||
if do_openmp:
|
|
||||||
txt += """
|
|
||||||
integer, external :: omp_get_thread_num
|
|
||||||
ithread = omp_get_thread_num()
|
|
||||||
"""
|
|
||||||
else:
|
|
||||||
txt += """
|
|
||||||
ithread = 0
|
|
||||||
"""
|
|
||||||
txt += """
|
|
||||||
$3
|
$3
|
||||||
$4
|
$4
|
||||||
end subroutine
|
end subroutine
|
||||||
@ -161,44 +94,17 @@ end subroutine
|
|||||||
if do_debug:
|
if do_debug:
|
||||||
s = """
|
s = """
|
||||||
if (.not.alloc) then
|
if (.not.alloc) then
|
||||||
"""
|
allocate(irp_stack(0:STACKMAX))
|
||||||
if do_openmp:
|
allocate(irp_cpu(0:STACKMAX))
|
||||||
s += """
|
|
||||||
!$OMP PARALLEL
|
|
||||||
!$OMP SINGLE
|
|
||||||
nthread = omp_get_num_threads()
|
|
||||||
!$OMP END SINGLE
|
|
||||||
!$OMP END PARALLEL
|
|
||||||
!$OMP CRITICAL
|
|
||||||
if (.not.alloc) then
|
|
||||||
allocate(irp_stack(0:STACKMAX,0:nthread))
|
|
||||||
allocate(irp_cpu(0:STACKMAX,0:nthread))
|
|
||||||
allocate(stack_index(0:nthread))
|
|
||||||
stack_index = 0
|
stack_index = 0
|
||||||
alloc = .True.
|
alloc = .True.
|
||||||
endif
|
endif
|
||||||
!$OMP END CRITICAL
|
stack_index = min(stack_index+1,STACKMAX)
|
||||||
endif
|
irp_stack(stack_index) = irp_where"""
|
||||||
stack_index(ithread) = min(stack_index(ithread)+1,STACKMAX)
|
|
||||||
irp_stack(stack_index(ithread),ithread) = irp_where"""
|
|
||||||
else:
|
|
||||||
s += """
|
|
||||||
nthread = 1
|
|
||||||
if (.not.alloc) then
|
|
||||||
allocate(irp_stack(0:STACKMAX,0:1))
|
|
||||||
allocate(irp_cpu(0:STACKMAX,0:1))
|
|
||||||
allocate(stack_index(0:2))
|
|
||||||
stack_index = 0
|
|
||||||
alloc = .True.
|
|
||||||
endif
|
|
||||||
endif
|
|
||||||
stack_index(1) = min(stack_index(1)+1,STACKMAX)
|
|
||||||
irp_stack(stack_index(1),1) = irp_where"""
|
|
||||||
if do_memory:
|
if do_memory:
|
||||||
txt+="""
|
txt+="""
|
||||||
print *, 'Allocating irp_stack(',STACKMAX,','0:nthread,')'
|
print *, 'Allocating irp_stack(',STACKMAX+1,')'
|
||||||
print *, 'Allocating irp_cpu(',STACKMAX,','0:nthread,')'
|
print *, 'Allocating irp_cpu(',STACKMAX+1,')' """
|
||||||
print *, 'Allocating stack_index(',0:nthread,')'"""
|
|
||||||
else:
|
else:
|
||||||
s = ""
|
s = ""
|
||||||
txt = txt.replace("$1",s)
|
txt = txt.replace("$1",s)
|
||||||
@ -206,8 +112,8 @@ end subroutine
|
|||||||
# $2
|
# $2
|
||||||
if do_debug:
|
if do_debug:
|
||||||
txt = txt.replace("$2","""
|
txt = txt.replace("$2","""
|
||||||
print *, ithread, ':', white(1:stack_index(ithread))//'-> ', trim(irp_where)
|
print *, white(1:stack_index)//'-> ', trim(irp_where)
|
||||||
call cpu_time(irp_cpu(stack_index(ithread),ithread))""")
|
call cpu_time(irp_cpu(stack_index))""")
|
||||||
else:
|
else:
|
||||||
txt = txt.replace("$2","")
|
txt = txt.replace("$2","")
|
||||||
|
|
||||||
@ -215,40 +121,28 @@ end subroutine
|
|||||||
if do_debug:
|
if do_debug:
|
||||||
txt = txt.replace("$3","""
|
txt = txt.replace("$3","""
|
||||||
call cpu_time(cpu)
|
call cpu_time(cpu)
|
||||||
print *, ithread, ':', white(1:stack_index(ithread))//'<- ', &
|
print *, white(1:stack_index)//'<- ', &
|
||||||
trim(irp_stack(stack_index(ithread),ithread)), &
|
trim(irp_stack(stack_index)), &
|
||||||
cpu-irp_cpu(stack_index(ithread),ithread)""")
|
cpu-irp_cpu(stack_index)""")
|
||||||
else:
|
else:
|
||||||
txt = txt.replace("$3","")
|
txt = txt.replace("$3","")
|
||||||
|
|
||||||
# $4
|
# $4
|
||||||
if do_debug:
|
if do_debug:
|
||||||
txt = txt.replace("$4","""
|
txt = txt.replace("$4","""
|
||||||
stack_index(ithread) = max(0,stack_index(ithread)-1)""")
|
stack_index = max(0,stack_index-1)""")
|
||||||
else:
|
else:
|
||||||
txt = txt.replace("$4","")
|
txt = txt.replace("$4","")
|
||||||
|
|
||||||
txt += """
|
txt += """
|
||||||
subroutine irp_trace
|
subroutine irp_trace
|
||||||
use irp_stack_mod
|
use irp_stack_mod
|
||||||
integer :: ithread
|
|
||||||
integer :: i
|
integer :: i
|
||||||
"""
|
|
||||||
if do_openmp:
|
|
||||||
txt += """
|
|
||||||
!$ integer, external :: omp_get_thread_num
|
|
||||||
!$ ithread = omp_get_thread_num()
|
|
||||||
"""
|
|
||||||
else:
|
|
||||||
txt += """
|
|
||||||
ithread = 0
|
|
||||||
"""
|
|
||||||
txt += """
|
|
||||||
if (.not.alloc) return
|
if (.not.alloc) return
|
||||||
print *, 'Stack trace: ', ithread
|
print *, 'Stack trace: '
|
||||||
print *, '-------------------------'
|
print *, '-------------------------'
|
||||||
do i=1,stack_index(ithread)
|
do i=1,stack_index
|
||||||
print *, trim(irp_stack(i,ithread))
|
print *, trim(irp_stack(i))
|
||||||
enddo
|
enddo
|
||||||
print *, '-------------------------'
|
print *, '-------------------------'
|
||||||
end subroutine
|
end subroutine
|
||||||
|
Loading…
Reference in New Issue
Block a user