diff --git a/bin/irpf90 b/bin/irpf90 index e537e26..d9d2360 120000 --- a/bin/irpf90 +++ b/bin/irpf90 @@ -1 +1 @@ -../src/irpf90.exe \ No newline at end of file +../src/irpf90_python.exe \ No newline at end of file diff --git a/src/codelet.py b/src/codelet.py new file mode 100644 index 0000000..c11d95e --- /dev/null +++ b/src/codelet.py @@ -0,0 +1,45 @@ +#!/usr/bin/python +from command_line import command_line +import irpf90_t + +def run(): + template = """ +program codelet_%(name)s + implicit none + integer :: i + double precision :: ticks_0, ticks_1, cpu_0, cpu_1 + integer, parameter :: irp_imax = %(NMAX)d + + %(precondition)s + + call provide_%(name)s + + double precision :: irp_rdtsc + + call cpu_time(cpu_0) + ticks_0 = irp_rdtsc() + do i=1,irp_imax + call bld_%(name)s + enddo + ticks_1 = irp_rdtsc() + call cpu_time(cpu_1) + print *, '%(name)s' + print *, '-----------' + print *, 'Cycles:' + print *, (ticks_1-ticks_0)/dble(irp_imax) + print *, 'Seconds:' + print *, (cpu_1-cpu_0)/dble(irp_imax) +end + + """ + + name, NMAX, precondition, filename = command_line.codelet + if precondition is None: + precondition = "" + else: + precondition = "PROVIDE "+precondition + file = open(filename,'w') + file.write(template%locals()) + file.close() + + diff --git a/src/command_line.py b/src/command_line.py index 4524ecf..35569d0 100644 --- a/src/command_line.py +++ b/src/command_line.py @@ -49,6 +49,7 @@ options['r'] = [ 'no_directives', 'Ignore all compiler directives !DEC$ and !DIR options['n'] = [ 'inline' , 'all|providers|builders : Force inlining of providers or builders', 1 ] options['u'] = [ 'unused' , 'Print unused providers', 0 ] options['I'] = [ 'include' , 'Include directory', 1 ] +options['c'] = [ 'codelet' , 'entity:NMAX or entity:precondition:NMAX : Generate a codelet to profile a provider running NMAX times', 1 ] class CommandLine(object): @@ -100,6 +101,28 @@ class CommandLine(object): return self._substituted substituted = property(fget=substituted) + def codelet(self): + if '_codelet' not in self.__dict__: + self._codelet = [] + for o,a in self.opts: + if o in [ "-c", '--'+options['c'][0] ]: + buffer = a.split(':') + filename = 'codelet_'+buffer[0]+'.irp.f' + if len(buffer) == 2: + self._codelet = [buffer[0], int(buffer[1]), None, filename] + elif len(buffer) == 3: + self._codelet = [buffer[0], int(buffer[2]), buffer[1], filename] + else: + print """ +Error in codelet definition. Use: +--codelet=provider:NMAX +or +--codelet=provider:precondition:NMAX +""" + sys.exit(1) + return self._codelet + codelet = property(fget=codelet) + def preprocessed(self): if '_preprocessed' not in self.__dict__: self._preprocessed = [] diff --git a/src/irpf90.py b/src/irpf90.py index 4cc43c1..eaed0e9 100644 --- a/src/irpf90.py +++ b/src/irpf90.py @@ -35,8 +35,9 @@ except: pass sys.setcheckinterval(1000) +from command_line import command_line + def main(): - from command_line import command_line vim.install() @@ -72,9 +73,14 @@ def main(): for x in parents: print "- %s"%(x,) - if not command_line.do_run: - return + if command_line.do_codelet: + import profile + profile.build_rdtsc() + import codelet + codelet.run() + if not command_line.do_run: + return init() @@ -102,3 +108,4 @@ def main(): if __name__ == '__main__': main() + diff --git a/src/irpf90_t.py b/src/irpf90_t.py index 1068ada..57658c4 100644 --- a/src/irpf90_t.py +++ b/src/irpf90_t.py @@ -351,6 +351,8 @@ def create_irpf90_files(): result = filter ( is_irpf90_file, os.listdir(os.getcwd()) ) for dir in command_line.include_dir: result += map(lambda x: dir+x, filter ( is_irpf90_file, os.listdir(dir) ) ) + if command_line.do_codelet: + result += [command_line.codelet[3]] return result irpf90_files = create_irpf90_files() diff --git a/src/makefile.py b/src/makefile.py index 03ea7fd..311b887 100644 --- a/src/makefile.py +++ b/src/makefile.py @@ -61,8 +61,7 @@ irpf90.make: $(wildcard *.irp.f) ###################################################################### def run(): - from modules import modules - if os.fork() == 0: + from modules import modules mod = [] for m in modules.values(): mod.append(m) @@ -94,6 +93,8 @@ def run(): print >>file, "OBJ1 = $(OBJ) %sirp_touches.irp.o"%(irpdir), if command_line.do_profile: print >>file, " %sirp_profile.irp.o"%(irpdir), " irp_rdtsc.o", + if command_line.do_codelet: + print >>file, " irp_rdtsc.o", if command_line.do_openmp: print >>file, " %sirp_locks.irp.o"%(irpdir), else: @@ -191,4 +192,3 @@ def run(): print >>file, "\t- rm -rf "+irpdir+" "+mandir+" irpf90.make irpf90_variables dist\n" file.close() - sys.exit(0) diff --git a/src/preprocessed_text.py b/src/preprocessed_text.py index 4941ea2..9eb2db3 100644 --- a/src/preprocessed_text.py +++ b/src/preprocessed_text.py @@ -788,6 +788,7 @@ def check_begin_end(text): error.fail(text[begin],"Missing 'end%s'"%(x,)) def find_matching_end_subfunpro(begin,x): + line = text[begin] for i in range(begin+1,len(text)): line = text[i] if type(line) == x: diff --git a/src/profile.py b/src/profile.py index f1321d6..abf0b92 100644 --- a/src/profile.py +++ b/src/profile.py @@ -20,7 +20,6 @@ import subprocess import tempfile import os import threading -from variables import variables def build_rdtsc(): file,filename = tempfile.mkstemp() @@ -36,6 +35,7 @@ def build_rdtsc(): threading.Thread(target=t).start() def build_module(): + from variables import variables data = """ module irp_timer double precision :: irp_profile(3,%(n)d)