10
0
mirror of https://gitlab.com/scemama/irpf90.git synced 2024-06-24 06:02:07 +02:00
irpf90/src/profile.py

102 lines
2.2 KiB
Python
Raw Normal View History

2011-09-30 19:10:18 +02:00
#!/usr/bin/python
rdtsc = """
2011-09-30 21:46:08 +02:00
#ifdef __i386
2011-09-30 23:18:17 +02:00
double irp_rdtsc_(void) {
unsigned long long x;
2011-09-30 19:10:18 +02:00
__asm__ volatile ("rdtsc" : "=A" (x));
2011-09-30 23:18:17 +02:00
return (double) x;
2011-09-30 19:10:18 +02:00
}
2011-09-30 21:46:08 +02:00
#elif __amd64
2011-09-30 23:18:17 +02:00
double irp_rdtsc_(void) {
unsigned long long a, d;
2011-09-30 19:10:18 +02:00
__asm__ volatile ("rdtsc" : "=a" (a), "=d" (d));
2011-09-30 23:18:17 +02:00
return (double)((d<<32) | a);
2011-09-30 19:10:18 +02:00
}
#endif
"""
import subprocess
import tempfile
import os
2011-09-30 23:18:17 +02:00
import threading
2011-09-30 19:10:18 +02:00
from variables import variables
def build_rdtsc():
file,filename = tempfile.mkstemp()
filename += ".c"
file = open(filename,'w')
file.write(rdtsc)
file.close()
2011-09-30 23:18:17 +02:00
def t():
p = subprocess.Popen(["gcc","-O2",filename,"-c","-o","IRPF90_temp/irp_rdtsc.o"])
p.communicate()
os.remove(filename)
threading.Thread(target=t).start()
2011-09-30 19:10:18 +02:00
def build_module():
data = """
module irp_timer
double precision :: irp_profile(2,%(n)d)
character*(64) :: irp_profile_label(%(n)d)
end module
subroutine irp_init_timer
use irp_timer
implicit none
irp_profile = 0.
%(text)s
end
subroutine irp_set_timer(i,value)
use irp_timer
implicit none
integer, intent(in) :: i
2011-09-30 23:18:17 +02:00
double precision, intent(in) :: value
irp_profile(1,i) = irp_profile(1,i) + value
irp_profile(2,i) = irp_profile(2,i) + 1.d0
2011-09-30 19:10:18 +02:00
end
subroutine irp_print_timer()
use irp_timer
implicit none
integer :: i
2011-09-30 23:18:17 +02:00
print '(A24,A8,4(X,A14))', 'Calls', 'Tot Cycles', 'Avge Cycles', &
2011-09-30 19:10:18 +02:00
'Tot Secs(1GHz)', 'Avge Secs(1GHz)'
2011-09-30 23:18:17 +02:00
print '(A)', '----------------------------------------------'// &
'----------------------------------------------'
2011-09-30 19:10:18 +02:00
do i=1,%(n)d
if (irp_profile(2,i) > 0.) then
2011-09-30 23:18:17 +02:00
print '(A24,F8.0,2(X,F14.0),2(X,F14.8))', &
irp_profile_label(i), irp_profile(2,i), &
2011-09-30 19:10:18 +02:00
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)
endif
enddo
end
"""
label = {}
for i in variables:
vi = variables[i]
label[vi.label] = vi.name
text = []
2011-09-30 23:18:17 +02:00
lmax = 0
2011-09-30 19:10:18 +02:00
for l in label:
text.append(" irp_profile_label(%d) = '%s'"%(l,label[l]))
2011-09-30 23:18:17 +02:00
lmax = max(lmax,l)
2011-09-30 19:10:18 +02:00
text.sort()
text = '\n'.join(text)
2011-09-30 23:18:17 +02:00
data = data%{'text': text, 'n':lmax}
2011-09-30 19:10:18 +02:00
file = open("IRPF90_temp/irp_profile.irp.F90",'w')
file.write(data)
file.close()
def run():
build_module()
build_rdtsc()
if __name__ == "__main__":
build_rdtsc()