From 1c1f989f36d457d2009a4f06cec507ae5c3eca31 Mon Sep 17 00:00:00 2001 From: Anthony Scemama Date: Sun, 29 May 2016 15:56:27 +0200 Subject: [PATCH] Corrected irp_stack bug --- src/irp_stack.py | 46 +++++++++++++++++++++++----------------------- src/variable.py | 16 ++++++++++++++-- 2 files changed, 37 insertions(+), 25 deletions(-) diff --git a/src/irp_stack.py b/src/irp_stack.py index d60710b..4437c0f 100644 --- a/src/irp_stack.py +++ b/src/irp_stack.py @@ -85,9 +85,9 @@ subroutine irp_enter(irp_where) nthread = 1 """ txt += """ - print *, 'Allocating irp_stack(',STACKMAX,',',nthread,')' - print *, 'Allocating irp_cpu(',STACKMAX,',',nthread,')' - print *, 'Allocating stack_index(',nthread,')' + print *, 'Allocating irp_stack(',STACKMAX,',',0:nthread,')' + print *, 'Allocating irp_cpu(',STACKMAX,',',0:nthread,')' + print *, 'Allocating stack_index(',0:nthread,')' endif""" txt +=""" $2 @@ -128,9 +128,9 @@ $1 nthread = 1 """ txt +=""" - print *, 'Allocating irp_stack(',STACKMAX,',',nthread,')' - print *, 'Allocating irp_cpu(',STACKMAX,',',nthread,')' - print *, 'Allocating stack_index(',nthread,')' + print *, 'Allocating irp_stack(',STACKMAX,',',0:nthread,')' + print *, 'Allocating irp_cpu(',STACKMAX,',',0:nthread,')' + print *, 'Allocating stack_index(',0:nthread,')' endif """ txt += """ @@ -172,16 +172,16 @@ end subroutine !$OMP END PARALLEL !$OMP CRITICAL if (.not.alloc) then - allocate(irp_stack(0:STACKMAX,nthread)) - allocate(irp_cpu(0:STACKMAX,nthread)) - allocate(stack_index(nthread)) + allocate(irp_stack(0:STACKMAX,0:nthread)) + allocate(irp_cpu(0:STACKMAX,0:nthread)) + allocate(stack_index(0:nthread)) stack_index = 0 alloc = .True. endif !$OMP END CRITICAL endif - stack_index(ithread+1) = mod(stack_index(ithread+1)+1,STACKMAX) - irp_stack(stack_index(ithread+1),ithread+1) = irp_where""" + stack_index(ithread) = min(stack_index(ithread)+1,STACKMAX) + irp_stack(stack_index(ithread),ithread) = irp_where""" else: s += """ nthread = 1 @@ -193,13 +193,13 @@ end subroutine alloc = .True. endif endif - stack_index(1) = mod(stack_index(1)+1,STACKMAX) + stack_index(1) = min(stack_index(1)+1,STACKMAX) irp_stack(stack_index(1),1) = irp_where""" if do_memory: txt+=""" - print *, 'Allocating irp_stack(',STACKMAX,','nthread,')' - print *, 'Allocating irp_cpu(',STACKMAX,','nthread,')' - print *, 'Allocating stack_index(',nthread,')'""" + print *, 'Allocating irp_stack(',STACKMAX,','0:nthread,')' + print *, 'Allocating irp_cpu(',STACKMAX,','0:nthread,')' + print *, 'Allocating stack_index(',0:nthread,')'""" else: s = "" txt = txt.replace("$1",s) @@ -207,8 +207,8 @@ end subroutine # $2 if do_debug: txt = txt.replace("$2",""" - print *, ithread, ':', white(1:stack_index(ithread+1))//'-> ', trim(irp_where) - call cpu_time(irp_cpu(stack_index(ithread+1),ithread+1))""") + print *, ithread, ':', white(1:stack_index(ithread))//'-> ', trim(irp_where) + call cpu_time(irp_cpu(stack_index(ithread),ithread))""") else: txt = txt.replace("$2","") @@ -216,16 +216,16 @@ end subroutine if do_debug: txt = txt.replace("$3",""" call cpu_time(cpu) - print *, ithread, ':', white(1:stack_index(ithread+1))//'<- ', & - trim(irp_stack(stack_index(ithread+1),ithread+1)), & - cpu-irp_cpu(stack_index(ithread+1),ithread+1)""") + print *, ithread, ':', white(1:stack_index(ithread))//'<- ', & + trim(irp_stack(stack_index(ithread),ithread)), & + cpu-irp_cpu(stack_index(ithread),ithread)""") else: txt = txt.replace("$3","") # $4 if do_debug or do_assert: txt = txt.replace("$4",""" - stack_index(ithread+1) = stack_index(ithread+1)-1""") + stack_index(ithread) = max(0,stack_index(ithread)-1)""") else: txt = txt.replace("$4","") @@ -248,8 +248,8 @@ subroutine irp_trace if (.not.alloc) return print *, 'Stack trace: ', ithread print *, '-------------------------' - do i=1,stack_index(ithread+1) - print *, trim(irp_stack(i,ithread+1)) + do i=1,stack_index(ithread) + print *, trim(irp_stack(i,ithread)) enddo print *, '-------------------------' end subroutine diff --git a/src/variable.py b/src/variable.py index 56a61a8..43d0d59 100644 --- a/src/variable.py +++ b/src/variable.py @@ -681,5 +681,17 @@ if __name__ == '__main__': from variables import variables #for v in variables.keys(): # print v - for line in variables['e_loc'].parents: - print line + def print_dot(x,done): + if x.children == []: + return + for i in x.needs: + pair = (x.name, i) + if pair not in done: + print "%s -> %s"%( x.name, i ) + done[pair] = None + print_dot(variables[i],done) + + print "digraph G { " +# print_dot(variables['e_loc'], {}) + print_dot(variables['psi_value'], {}) + print "}"