From 61997d670aee58310dda9414d65e22208a3f1a34 Mon Sep 17 00:00:00 2001 From: Anthony Scemama Date: Tue, 7 Jan 2014 17:01:40 +0100 Subject: [PATCH 1/4] Added auto codelet generation --- bin/irpf90 | 2 +- src/codelet.py | 45 ++++++++++++++++++++++++++++++++++++++++ src/command_line.py | 23 ++++++++++++++++++++ src/irpf90.py | 13 +++++++++--- src/irpf90_t.py | 2 ++ src/makefile.py | 6 +++--- src/preprocessed_text.py | 1 + src/profile.py | 2 +- 8 files changed, 86 insertions(+), 8 deletions(-) create mode 100644 src/codelet.py 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) From 89ab32443ccb5badade8d311aa34ccfe3f292e04 Mon Sep 17 00:00:00 2001 From: Anthony Scemama Date: Thu, 27 Feb 2014 14:06:31 +0100 Subject: [PATCH 2/4] Corrected bug with unexisting directories --- README | 5 +++-- man/man1/irpf90.1.gz | Bin 1329 -> 1471 bytes src/command_line.py | 2 ++ src/init.py | 9 ++++++++- src/irpf90_t.py | 6 +++++- src/module.py | 2 +- src/version.py | 2 +- 7 files changed, 20 insertions(+), 6 deletions(-) diff --git a/README b/README index da145fc..a0d98c3 100644 --- a/README +++ b/README @@ -7,7 +7,7 @@ Dependencies - GNU make (>= 3.81 recommended) - Python > 2.3 -- Any Fortran 90 compiler (Intel recommended, for example) +- Any Fortran 90 compiler (Intel recommended) Installing IRPF90 ----------------- @@ -21,6 +21,7 @@ ${IRPF90_HOME} is the location of your irpf90 directory:: export PATH=${IRPF90_HOME}/bin:${PATH} export MANPATH=${IRPF90_HOME}/man:${MANPATH} EOF + . ${HOME}/.bash_profile Using IRPF90 @@ -43,6 +44,6 @@ Author ------ | Anthony Scemama, LCPQ-IRSAMC, CNRS-Universite Paul Sabatier -| scemama@irsamc.ups-tlse.fr +| | http://scemama.mooo.com diff --git a/man/man1/irpf90.1.gz b/man/man1/irpf90.1.gz index 19b980fd63735b02d03d8b8f66004f7460eb41ab..2e0b640df0b1ebd4d280207fad1caa290f8aa9f5 100644 GIT binary patch literal 1471 zcmV;w1wi^AiwFq7J^E4r18H(_W;rk}F#wfUZExE)5dO|zaWyia#bU*FR}AwoU|!<3 z1{%k(9Be}s6tqO!L?lupDLXFuwrw4qbCaC0`3#3ndJ9 zBBPbj1sM@LQ>CslB3psn%3k|2rwlT&B{|T&#o< zDi!23%{Zil6UM@!NEtHL4GONhQe{H9ZZ5VWr=H);MBneuMF|_%+^nTyNpjYwBvBu6 zq6kZOtUlrwpVHOt*V4l$&EDM;i~Xk-2X`!L;+RaY#?u9hkg@1dOn^=d zSw!=gd~_IngUYiWK8E6nvkjs@_Mb7Xts6FO((SbMljh?fU+ehB40d#$eJ7aDX1iPa zro`@hH6noTIZ%Z_LE`xD>CG&j#4M@4vQIg|d>6ZHkGV95|<~sN}F_DZbh^*$!Zp`xCt;k0(F7CKhP!3yqdWaXg+cPW97dMSN*7K4(T0dMlm~I%-ZE&8f~rF5DsVpO2CI znB0Ciy&nBV0JNE+=2NWzKG+rZ*pS-x3``n*KEdF^N&+2zO1#O8I`Q7ZA-Wd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@Rau%Yj*@C=4Drq6?k5uxQKj|=eXge?ER}|L9=$OX{Zn11hF=tpj+?Nig z-lHI^0AteBv#1c%IA(pP%_G@%;K#n|*j64&p_CiN#`F)|7{0gd)Jk<#qhQnW%dN1C zlvv@KAYM{Yjz7-c&ySTGQR6c4#IZv$>PPv1+zcTs&~(Z|(8DmF9PnnncLLVhQ&#sK z6RXz53d;}uX#&`6NQ_Q-fTZh8baownbqs7tjfO!t-UO10VA>*AtX?t;|z0o zB%^XVP@V+qR&ZK~^bvuP#f9EkL@`7oAfT+|*I*6K+C5dU5&w9MVs;WyAB#$$vQ${x z_-6x39?s|uL&-&WJ5)Vusy>2yD{@~#PUsf8Y(rTia?4V!5a`Goum#n**b}sDp-76VtJGvxp78i8cMBe zOJ=k7p%$#HMT&rz9-@biKkFseYH-@81)E4)ml)e-a1dHL8XMeDtdM{}9ASZl4Jn|4 zJ>u&Iol%4ZIAL&*djhkLD&MN|%3}uFx@$J4$~cj4TkS%ug2&PYUBdPM&VKhBllbqfFhh%R-t diff --git a/src/command_line.py b/src/command_line.py index 35569d0..593f807 100644 --- a/src/command_line.py +++ b/src/command_line.py @@ -74,6 +74,8 @@ class CommandLine(object): self._include_dir = [] for o,a in self.opts: if o in [ "-I", '--'+options['I'][0] ]: + if len(a) < 1: + print "Error: -I option needs a directory" if a[-1] != '/': a = a+'/' self._include_dir.append(a) diff --git a/src/init.py b/src/init.py index 4fd25d1..7bddb42 100644 --- a/src/init.py +++ b/src/init.py @@ -63,10 +63,17 @@ def init(): makefile.create() # Copy current files in the irpdir + ls = os.listdir(os.getcwd()) + print ls for dir in ['./']+command_line.include_dir: + try: + os.stat(dir) + except: + print dir,'not in dir' + continue for filename in os.listdir(dir): filename = dir+filename - if not filename[0].startswith(".") and not os.path.isdir(filename): + if not filename.startswith(".") and not os.path.isdir(filename): try: file = open(filename,"r") except IOError: diff --git a/src/irpf90_t.py b/src/irpf90_t.py index 57658c4..ae1b73a 100644 --- a/src/irpf90_t.py +++ b/src/irpf90_t.py @@ -350,7 +350,11 @@ def create_irpf90_files(): return filename.endswith(".irp.f") and not filename.startswith('.') 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) ) ) + try: + os.stat(dir) + result += map(lambda x: dir+x, filter ( is_irpf90_file, os.listdir(dir) ) ) + except: + continue if command_line.do_codelet: result += [command_line.codelet[3]] return result diff --git a/src/module.py b/src/module.py index 4bb9f49..a817f40 100644 --- a/src/module.py +++ b/src/module.py @@ -47,7 +47,7 @@ class Fmodule(object): def __init__(self,text,filename): self.text = put_info(text,filename) self.filename = filename[:-6] - self.name = "%s_mod"%(self.filename).replace('/','__') + self.name = "%s_mod"%(self.filename).replace('/','__').replace('.','Dot') def is_main(self): if '_is_main' not in self.__dict__: diff --git a/src/version.py b/src/version.py index 35ec9a3..cfa2db6 100644 --- a/src/version.py +++ b/src/version.py @@ -1 +1 @@ -version = "1.3.1" +version = "1.3.3" From d71c2c42297ce49f5bec0addbe880257ebc7ce3e Mon Sep 17 00:00:00 2001 From: Anthony Scemama Date: Thu, 27 Feb 2014 14:07:20 +0100 Subject: [PATCH 3/4] Fixed man error in make --- Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 31a6ddf..97732c1 100644 --- a/Makefile +++ b/Makefile @@ -1,10 +1,10 @@ .PHONY: all src man -all: src man - src: $(MAKE) -C $@ man: - $(MAKE) -C $@ +all: src man + From b508923bab68d1db0ecc4644de732a3abd1f6377 Mon Sep 17 00:00:00 2001 From: Anthony Scemama Date: Fri, 28 Feb 2014 11:12:20 +0100 Subject: [PATCH 4/4] Forgot to remove debug print --- src/init.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/init.py b/src/init.py index 7bddb42..94b82c1 100644 --- a/src/init.py +++ b/src/init.py @@ -63,8 +63,6 @@ def init(): makefile.create() # Copy current files in the irpdir - ls = os.listdir(os.getcwd()) - print ls for dir in ['./']+command_line.include_dir: try: os.stat(dir)