10
0
mirror of https://gitlab.com/scemama/irpf90.git synced 2024-10-30 10:48:15 +01:00

Cleaned irp_stack

This commit is contained in:
Anthony Scemama 2019-02-06 11:19:26 +01:00
parent 002db06d15
commit e0f8e66e7e

View File

@ -41,52 +41,25 @@ def create():
txt = """
module irp_stack_mod
integer, parameter :: STACKMAX=1000
character*(128),allocatable :: irp_stack(:,:)
double precision,allocatable :: irp_cpu(:,:)
integer,allocatable :: stack_index(:)
character*(128),allocatable :: irp_stack(:)
double precision,allocatable :: irp_cpu(:)
integer :: stack_index
logical :: alloc = .False.
integer :: nthread
character*(128) :: white = ''
end module
subroutine irp_enter(irp_where)
use irp_stack_mod
integer :: ithread
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"
if do_memory:
txt+="""
if (.not.alloc) then
"""
if do_openmp:
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,')'
print *, 'Allocating irp_stack(',STACKMAX+1,')'
print *, 'Allocating irp_cpu(',STACKMAX+1,')'
endif"""
txt +="""
$2
@ -94,42 +67,14 @@ end subroutine
subroutine irp_enter_f(irp_where)
use irp_stack_mod
integer :: ithread
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
"""
if do_memory:
txt+="""
if (.not.alloc) then
"""
if do_openmp:
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,')'
print *, 'Allocating irp_stack(',STACKMAX+1,')'
print *, 'Allocating irp_cpu(',STACKMAX+1,')'
endif
"""
txt += """
@ -139,19 +84,7 @@ end subroutine
subroutine irp_leave (irp_where)
use irp_stack_mod
character*(*) :: irp_where
integer :: ithread
double precision :: cpu
"""
if do_openmp:
txt += """
integer, external :: omp_get_thread_num
ithread = omp_get_thread_num()
"""
else:
txt += """
ithread = 0
"""
txt += """
$3
$4
end subroutine
@ -161,44 +94,17 @@ end subroutine
if do_debug:
s = """
if (.not.alloc) then
"""
if do_openmp:
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))
allocate(irp_stack(0:STACKMAX))
allocate(irp_cpu(0:STACKMAX))
stack_index = 0
alloc = .True.
endif
!$OMP END CRITICAL
endif
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"""
stack_index = min(stack_index+1,STACKMAX)
irp_stack(stack_index) = irp_where"""
if do_memory:
txt+="""
print *, 'Allocating irp_stack(',STACKMAX,','0:nthread,')'
print *, 'Allocating irp_cpu(',STACKMAX,','0:nthread,')'
print *, 'Allocating stack_index(',0:nthread,')'"""
print *, 'Allocating irp_stack(',STACKMAX+1,')'
print *, 'Allocating irp_cpu(',STACKMAX+1,')' """
else:
s = ""
txt = txt.replace("$1",s)
@ -206,8 +112,8 @@ end subroutine
# $2
if do_debug:
txt = txt.replace("$2","""
print *, ithread, ':', white(1:stack_index(ithread))//'-> ', trim(irp_where)
call cpu_time(irp_cpu(stack_index(ithread),ithread))""")
print *, white(1:stack_index)//'-> ', trim(irp_where)
call cpu_time(irp_cpu(stack_index))""")
else:
txt = txt.replace("$2","")
@ -215,40 +121,28 @@ end subroutine
if do_debug:
txt = txt.replace("$3","""
call cpu_time(cpu)
print *, ithread, ':', white(1:stack_index(ithread))//'<- ', &
trim(irp_stack(stack_index(ithread),ithread)), &
cpu-irp_cpu(stack_index(ithread),ithread)""")
print *, white(1:stack_index)//'<- ', &
trim(irp_stack(stack_index)), &
cpu-irp_cpu(stack_index)""")
else:
txt = txt.replace("$3","")
# $4
if do_debug:
txt = txt.replace("$4","""
stack_index(ithread) = max(0,stack_index(ithread)-1)""")
stack_index = max(0,stack_index-1)""")
else:
txt = txt.replace("$4","")
txt += """
subroutine irp_trace
use irp_stack_mod
integer :: ithread
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
print *, 'Stack trace: ', ithread
print *, 'Stack trace: '
print *, '-------------------------'
do i=1,stack_index(ithread)
print *, trim(irp_stack(i,ithread))
do i=1,stack_index
print *, trim(irp_stack(i))
enddo
print *, '-------------------------'
end subroutine