From e0f8e66e7e58e586bca537e05c30fade1e38f58c Mon Sep 17 00:00:00 2001 From: Anthony Scemama Date: Wed, 6 Feb 2019 11:19:26 +0100 Subject: [PATCH] Cleaned irp_stack --- src/irp_stack.py | 150 +++++++---------------------------------------- 1 file changed, 22 insertions(+), 128 deletions(-) diff --git a/src/irp_stack.py b/src/irp_stack.py index 9a90f9c..ee08f88 100644 --- a/src/irp_stack.py +++ b/src/irp_stack.py @@ -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