10
0
mirror of https://gitlab.com/scemama/irpf90.git synced 2024-12-22 04:13:33 +01:00
This commit is contained in:
Anthony Scemama 2011-09-30 23:18:17 +02:00
parent 1bda8f00e0
commit 3f2d536c65
3 changed files with 30 additions and 21 deletions

View File

@ -66,10 +66,6 @@ def main():
for x in parents: for x in parents:
print "- %s"%(x,) print "- %s"%(x,)
if command_line.do_profile:
import profile
profile.run()
if not command_line.do_run: if not command_line.do_run:
return return
@ -94,5 +90,9 @@ def main():
import create_man import create_man
create_man.run() create_man.run()
if command_line.do_profile:
import profile
profile.run()
if __name__ == '__main__': if __name__ == '__main__':
main() main()

View File

@ -1,18 +1,17 @@
#!/usr/bin/python #!/usr/bin/python
rdtsc = """ rdtsc = """
#define uint64_t unsigned long
#ifdef __i386 #ifdef __i386
uint64_t irp_rdtsc_() { double irp_rdtsc_(void) {
uint64_t x; unsigned long long x;
__asm__ volatile ("rdtsc" : "=A" (x)); __asm__ volatile ("rdtsc" : "=A" (x));
return x; return (double) x;
} }
#elif __amd64 #elif __amd64
uint64_t irp_rdtsc_() { double irp_rdtsc_(void) {
uint64_t a, d; unsigned long long a, d;
__asm__ volatile ("rdtsc" : "=a" (a), "=d" (d)); __asm__ volatile ("rdtsc" : "=a" (a), "=d" (d));
return (d<<32) | a; return (double)((d<<32) | a);
} }
#endif #endif
""" """
@ -20,6 +19,7 @@ uint64_t irp_rdtsc_() {
import subprocess import subprocess
import tempfile import tempfile
import os import os
import threading
from variables import variables from variables import variables
def build_rdtsc(): def build_rdtsc():
@ -28,9 +28,13 @@ def build_rdtsc():
file = open(filename,'w') file = open(filename,'w')
file.write(rdtsc) file.write(rdtsc)
file.close() file.close()
p = subprocess.Popen(["gcc","-O3",filename,"-c","-o","IRPF90_temp/irp_rdtsc.o"]) def t():
p.communicate() p = subprocess.Popen(["gcc","-O2",filename,"-c","-o","IRPF90_temp/irp_rdtsc.o"])
os.remove(filename)
p.communicate()
os.remove(filename)
threading.Thread(target=t).start()
def build_module(): def build_module():
data = """ data = """
@ -50,20 +54,23 @@ subroutine irp_set_timer(i,value)
use irp_timer use irp_timer
implicit none implicit none
integer, intent(in) :: i integer, intent(in) :: i
integer*8, intent(in) :: value double precision, intent(in) :: value
irp_profile(1,i) = dble(value) irp_profile(1,i) = irp_profile(1,i) + value
irp_profile(2,i) = irp_profile(2,i)+1.d0 irp_profile(2,i) = irp_profile(2,i) + 1.d0
end end
subroutine irp_print_timer() subroutine irp_print_timer()
use irp_timer use irp_timer
implicit none implicit none
integer :: i integer :: i
print '(16X,5(2X,A16))', 'Num Calls', 'Tot Cycles', 'Avge Cycles', & print '(A24,A8,4(X,A14))', 'Calls', 'Tot Cycles', 'Avge Cycles', &
'Tot Secs(1GHz)', 'Avge Secs(1GHz)' 'Tot Secs(1GHz)', 'Avge Secs(1GHz)'
print '(A)', '----------------------------------------------'// &
'----------------------------------------------'
do i=1,%(n)d do i=1,%(n)d
if (irp_profile(2,i) > 0.) then if (irp_profile(2,i) > 0.) then
print '(A16,5(2X,F16.4))', irp_profile_label(i), irp_profile(2,i), & print '(A24,F8.0,2(X,F14.0),2(X,F14.8))', &
irp_profile_label(i), irp_profile(2,i), &
irp_profile(1,i), irp_profile(1,i)/irp_profile(2,i), & irp_profile(1,i), irp_profile(1,i)/irp_profile(2,i), &
irp_profile(1,i)*1.d-9, 1.d-9*irp_profile(1,i)/irp_profile(2,i) irp_profile(1,i)*1.d-9, 1.d-9*irp_profile(1,i)/irp_profile(2,i)
endif endif
@ -75,11 +82,13 @@ end
vi = variables[i] vi = variables[i]
label[vi.label] = vi.name label[vi.label] = vi.name
text = [] text = []
lmax = 0
for l in label: for l in label:
text.append(" irp_profile_label(%d) = '%s'"%(l,label[l])) text.append(" irp_profile_label(%d) = '%s'"%(l,label[l]))
lmax = max(lmax,l)
text.sort() text.sort()
text = '\n'.join(text) text = '\n'.join(text)
data = data%{'text': text, 'n':len(label.keys())} data = data%{'text': text, 'n':lmax}
file = open("IRPF90_temp/irp_profile.irp.F90",'w') file = open("IRPF90_temp/irp_profile.irp.F90",'w')
file.write(data) file.write(data)
file.close() file.close()

View File

@ -558,7 +558,7 @@ class Variable(object):
text.append( (vars,line) ) text.append( (vars,line) )
text += map( lambda x: ([],Simple_line(line.i,x,line.filename)), call_provides(vars) ) text += map( lambda x: ([],Simple_line(line.i,x,line.filename)), call_provides(vars) )
if command_line.do_profile and type(line) == Begin_provider: if command_line.do_profile and type(line) == Begin_provider:
text.append( ( [], Declaration(line.i," integer*8 :: irp_rdtsc, irp_rdtsc1, irp_rdtsc2",line.filename) ) ) text.append( ( [], Declaration(line.i," double precision :: irp_rdtsc, irp_rdtsc1, irp_rdtsc2",line.filename) ) )
text.append( ( [], Simple_line(line.i," irp_rdtsc1 = irp_rdtsc()",line.filename) ) ) text.append( ( [], Simple_line(line.i," irp_rdtsc1 = irp_rdtsc()",line.filename) ) )
if type(line) == End_provider: if type(line) == End_provider:
if inside: if inside: