2009-09-04 15:11:42 +02:00
|
|
|
#!/usr/bin/python
|
2009-09-23 12:51:27 +02:00
|
|
|
# IRPF90 is a Fortran90 preprocessor written in Python for programming using
|
|
|
|
# the Implicit Reference to Parameters (IRP) method.
|
|
|
|
# Copyright (C) 2009 Anthony SCEMAMA
|
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation; either version 2 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License along
|
|
|
|
# with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
#
|
|
|
|
# Anthony Scemama
|
|
|
|
# LCPQ - IRSAMC - CNRS
|
|
|
|
# Universite Paul Sabatier
|
|
|
|
# 118, route de Narbonne
|
|
|
|
# 31062 Toulouse Cedex 4
|
2009-09-25 00:04:49 +02:00
|
|
|
# scemama@irsamc.ups-tlse.fr
|
2009-09-23 12:51:27 +02:00
|
|
|
|
2009-09-04 15:11:42 +02:00
|
|
|
|
|
|
|
from irpf90_t import *
|
|
|
|
from util import *
|
|
|
|
import error
|
2009-09-07 18:02:06 +02:00
|
|
|
from command_line import command_line
|
2009-09-04 15:11:42 +02:00
|
|
|
|
|
|
|
class Variable(object):
|
|
|
|
|
|
|
|
############################################################
|
2011-09-30 19:10:18 +02:00
|
|
|
def __init__(self,text,label,name = None):
|
2010-10-02 23:42:55 +02:00
|
|
|
assert type(text) == list
|
2009-09-04 15:11:42 +02:00
|
|
|
assert len(text) > 0
|
2010-10-02 23:42:55 +02:00
|
|
|
assert type(text[0]) == Begin_provider
|
2011-09-30 19:10:18 +02:00
|
|
|
self.label = label
|
2009-09-04 15:11:42 +02:00
|
|
|
self.text = text
|
|
|
|
if name is not None:
|
2010-09-01 15:10:16 +02:00
|
|
|
self._name = name
|
2009-09-09 16:59:43 +02:00
|
|
|
|
|
|
|
############################################################
|
|
|
|
def is_touched(self):
|
|
|
|
if '_is_touched' not in self.__dict__:
|
|
|
|
from variables import variables
|
2009-09-25 09:44:56 +02:00
|
|
|
result = self.is_read
|
2009-09-09 17:55:17 +02:00
|
|
|
for i in self.children:
|
|
|
|
if variables[i].is_touched:
|
|
|
|
result = True
|
|
|
|
break
|
2009-09-09 16:59:43 +02:00
|
|
|
self._is_touched = result
|
|
|
|
return self._is_touched
|
|
|
|
is_touched = property(is_touched)
|
|
|
|
|
2014-05-23 22:03:23 +02:00
|
|
|
############################################################
|
|
|
|
def has_openmp(self):
|
|
|
|
if '_has_openmp' not in self.__dict__:
|
2014-05-23 22:34:09 +02:00
|
|
|
self._has_openmp = False
|
|
|
|
self.builder()
|
2014-05-23 22:03:23 +02:00
|
|
|
return self._has_openmp
|
|
|
|
has_openmp = property(has_openmp)
|
|
|
|
|
2009-09-25 09:44:56 +02:00
|
|
|
############################################################
|
|
|
|
def is_written(self):
|
|
|
|
if '_is_written' not in self.__dict__:
|
|
|
|
from variables import variables
|
|
|
|
result = False
|
|
|
|
for i in self.parents:
|
|
|
|
if variables[i].is_written:
|
|
|
|
result = True
|
|
|
|
break
|
|
|
|
self._is_written = result
|
|
|
|
return self._is_written
|
|
|
|
is_written = property(is_written)
|
|
|
|
|
|
|
|
############################################################
|
|
|
|
def is_read(self):
|
|
|
|
if '_is_read' not in self.__dict__:
|
|
|
|
from variables import variables
|
|
|
|
result = False
|
|
|
|
for i in self.parents:
|
|
|
|
if variables[i].is_read:
|
|
|
|
result = True
|
|
|
|
break
|
|
|
|
self._is_read = result
|
|
|
|
return self._is_read
|
|
|
|
is_read = property(is_read)
|
|
|
|
|
2009-09-09 16:59:43 +02:00
|
|
|
############################################################
|
|
|
|
def is_main(self):
|
|
|
|
if '_is_main' not in self.__dict__:
|
|
|
|
self._is_main = (self.name == self.same_as)
|
|
|
|
return self._is_main
|
|
|
|
is_main = property(is_main)
|
2009-09-04 15:11:42 +02:00
|
|
|
|
|
|
|
############################################################
|
|
|
|
def name(self):
|
|
|
|
'''Name is lowercase'''
|
|
|
|
if '_name' not in self.__dict__:
|
|
|
|
buffer = None
|
2010-11-22 11:48:11 +01:00
|
|
|
text = self.text
|
|
|
|
for line in text:
|
2010-10-02 23:42:55 +02:00
|
|
|
if type(line) == Begin_provider:
|
2009-09-09 16:59:43 +02:00
|
|
|
self._name = line.filename[1]
|
2009-09-04 15:11:42 +02:00
|
|
|
break
|
|
|
|
return self._name
|
|
|
|
name = property(name)
|
|
|
|
|
|
|
|
############################################################
|
|
|
|
def doc(self):
|
|
|
|
if '_doc' not in self.__dict__:
|
2010-11-22 11:48:11 +01:00
|
|
|
text = self.text
|
|
|
|
buffer = filter(lambda l:type(l) == Doc, text)
|
2014-03-13 15:10:02 +01:00
|
|
|
self._doc = map(lambda l: l.text.lstrip()[1:], buffer)
|
2009-09-04 15:11:42 +02:00
|
|
|
if buffer == []:
|
|
|
|
error.warn(None,"Variable %s is not documented"%(self.name))
|
|
|
|
return self._doc
|
|
|
|
doc = property(doc)
|
|
|
|
|
2009-09-08 16:00:46 +02:00
|
|
|
############################################################
|
|
|
|
def documented(self):
|
|
|
|
if '_documented' not in self.__dict__:
|
|
|
|
self._documented = (self.doc != [])
|
|
|
|
return self._documented
|
|
|
|
documented = property(documented)
|
|
|
|
|
2010-11-22 11:48:11 +01:00
|
|
|
############################################################
|
|
|
|
def includes(self):
|
|
|
|
if '_includes' not in self.__dict__:
|
|
|
|
self._includes = []
|
|
|
|
text = self.text
|
|
|
|
for line in filter(lambda x: type(x) == Include,text):
|
|
|
|
self._includes.append(line.filename)
|
|
|
|
make_single(self._includes)
|
|
|
|
return self._includes
|
|
|
|
includes = property(includes)
|
|
|
|
|
2014-03-13 14:44:47 +01:00
|
|
|
############################################################
|
|
|
|
def calls(self):
|
|
|
|
if '_calls' not in self.__dict__:
|
|
|
|
self._calls = []
|
|
|
|
text = self.text
|
|
|
|
for line in filter(lambda x: type(x) == Call,text):
|
|
|
|
sub = line.text.split('(',1)[0].split()[1].lower()
|
|
|
|
self._calls.append(sub)
|
|
|
|
make_single(self._calls)
|
|
|
|
return self._calls
|
|
|
|
calls=property(fget=calls)
|
|
|
|
|
2009-09-04 15:11:42 +02:00
|
|
|
############################################################
|
|
|
|
def others(self):
|
|
|
|
if '_others' not in self.__dict__:
|
|
|
|
result = []
|
2010-04-06 15:24:24 +02:00
|
|
|
append = result.append
|
2009-09-05 15:37:23 +02:00
|
|
|
f = lambda l: type(l) in [Begin_provider, Cont_provider]
|
2010-11-22 11:48:11 +01:00
|
|
|
text = self.text
|
|
|
|
lines = filter(f, text)
|
2009-09-04 15:11:42 +02:00
|
|
|
for line in lines:
|
2010-04-06 15:24:24 +02:00
|
|
|
append(line.filename[1])
|
2009-09-04 15:11:42 +02:00
|
|
|
result.remove(self.name)
|
|
|
|
self._others = result
|
|
|
|
return self._others
|
|
|
|
others = property(others)
|
|
|
|
|
|
|
|
############################################################
|
|
|
|
def same_as(self):
|
|
|
|
if '_same_as' not in self.__dict__:
|
2010-10-02 23:42:55 +02:00
|
|
|
if type(self.line) == Begin_provider:
|
2009-09-07 18:02:06 +02:00
|
|
|
result = self.name
|
2009-09-04 15:11:42 +02:00
|
|
|
else:
|
2009-09-09 16:59:43 +02:00
|
|
|
result = self.text[0].filename[1]
|
2009-09-04 15:11:42 +02:00
|
|
|
self._same_as = result
|
|
|
|
return self._same_as
|
|
|
|
same_as = property(same_as)
|
|
|
|
|
|
|
|
############################################################
|
|
|
|
def allocate(self):
|
|
|
|
if '_allocate' not in self.__dict__:
|
2009-09-09 16:59:43 +02:00
|
|
|
if not self.is_main:
|
|
|
|
self._allocate = []
|
|
|
|
else:
|
|
|
|
from variables import variables
|
|
|
|
def f(var):
|
|
|
|
return variables[var].dim != []
|
|
|
|
self._allocate = filter ( f, self.others + [self.name] )
|
2009-09-04 15:11:42 +02:00
|
|
|
return self._allocate
|
|
|
|
allocate = property(allocate)
|
|
|
|
|
|
|
|
############################################################
|
|
|
|
def dim(self):
|
|
|
|
if '_dim' not in self.__dict__:
|
2009-09-09 00:46:42 +02:00
|
|
|
line = self.line.text.split('!')[0]
|
2009-09-04 15:11:42 +02:00
|
|
|
buffer = line.replace(']','').split(',',2)
|
|
|
|
if len(buffer) == 2:
|
|
|
|
self._dim = []
|
|
|
|
else:
|
|
|
|
buffer = buffer[2].strip()[1:-1].split(',')
|
|
|
|
self._dim = map(strip,buffer)
|
|
|
|
return self._dim
|
|
|
|
dim = property(dim)
|
|
|
|
|
|
|
|
############################################################
|
|
|
|
def type(self):
|
|
|
|
if '_type' not in self.__dict__:
|
|
|
|
line = self.line.text
|
|
|
|
buffer = line.split(',')[0]
|
2011-09-12 10:02:14 +02:00
|
|
|
try:
|
|
|
|
buffer = buffer.split('[')[1].strip()
|
|
|
|
except IndexError:
|
|
|
|
error.fail(None,"Error in definition of %s."%(self.name))
|
2009-09-09 16:59:43 +02:00
|
|
|
if self.dim != []:
|
2009-09-04 15:11:42 +02:00
|
|
|
buffer = "%s, allocatable"%(buffer)
|
|
|
|
self._type = buffer
|
|
|
|
return self._type
|
|
|
|
type = property(type)
|
|
|
|
|
|
|
|
############################################################
|
|
|
|
def fmodule(self):
|
|
|
|
if '_fmodule' not in self.__dict__:
|
2013-12-11 14:00:27 +01:00
|
|
|
self._fmodule = self.line.filename[0].replace('/','__').split('.irp.f')[0]+'_mod'
|
2009-09-04 15:11:42 +02:00
|
|
|
return self._fmodule
|
|
|
|
fmodule = property(fmodule)
|
|
|
|
|
|
|
|
############################################################
|
|
|
|
def regexp(self):
|
|
|
|
if '_regexp' not in self.__dict__:
|
|
|
|
import re
|
|
|
|
self._regexp = re.compile( \
|
2009-09-09 16:59:43 +02:00
|
|
|
r"([^a-z0-9'\"_]|^)%s([^a-z0-9_]|$)"%(self.name),re.I)
|
2009-09-04 15:11:42 +02:00
|
|
|
return self._regexp
|
|
|
|
regexp = property(regexp)
|
|
|
|
|
|
|
|
############################################################
|
|
|
|
def line(self):
|
|
|
|
if '_line' not in self.__dict__:
|
2009-09-05 15:37:23 +02:00
|
|
|
f = lambda l: type(l) in [Begin_provider, Cont_provider]
|
2010-11-22 11:48:11 +01:00
|
|
|
text = self.text
|
|
|
|
lines = filter(f, text)
|
2009-09-04 15:11:42 +02:00
|
|
|
for line in lines:
|
2009-09-09 16:59:43 +02:00
|
|
|
buffer = line.filename[1]
|
|
|
|
if self._name == buffer:
|
2009-09-04 15:11:42 +02:00
|
|
|
self._line = line
|
|
|
|
break
|
|
|
|
assert '_line' in self.__dict__
|
|
|
|
return self._line
|
|
|
|
line = property(line)
|
|
|
|
|
|
|
|
############################################################
|
|
|
|
def header(self):
|
|
|
|
if '_header' not in self.__dict__:
|
|
|
|
name = self.name
|
2009-09-25 16:57:22 +02:00
|
|
|
self._header = [ " %s :: %s %s"%(self.type, name, build_dim_colons(self) ) ]
|
2014-10-02 09:42:04 +02:00
|
|
|
if command_line.coarray:
|
|
|
|
if self.dim == []:
|
|
|
|
self._header[0] += " [*]"
|
|
|
|
else:
|
|
|
|
self._header[0] += " [:]"
|
2012-12-07 15:12:10 +01:00
|
|
|
if self.dim != [] and command_line.align != '1':
|
|
|
|
self._header += [" !DIR$ ATTRIBUTES ALIGN: %s :: %s"%(command_line.align,name)]
|
2009-09-09 16:59:43 +02:00
|
|
|
if self.is_main:
|
|
|
|
self._header += [ " logical :: %s_is_built = .False."%(name) ]
|
2009-09-04 15:11:42 +02:00
|
|
|
return self._header
|
|
|
|
header = property(header)
|
|
|
|
|
2009-09-07 18:02:06 +02:00
|
|
|
############################################################
|
|
|
|
def toucher(self):
|
|
|
|
if '_toucher' not in self.__dict__:
|
2009-09-09 16:59:43 +02:00
|
|
|
if not self.is_main:
|
|
|
|
self._toucher = []
|
2009-09-07 18:02:06 +02:00
|
|
|
else:
|
2009-09-14 17:16:52 +02:00
|
|
|
from modules import modules
|
|
|
|
from variables import variables
|
2009-09-07 18:02:06 +02:00
|
|
|
if '_needed_by' not in self.__dict__:
|
|
|
|
import parsed_text
|
2009-09-14 17:16:52 +02:00
|
|
|
parents = self.parents
|
|
|
|
parents.sort()
|
|
|
|
mods = map(lambda x: variables[x].fmodule, parents)
|
|
|
|
mods = make_single(mods)+[self.fmodule]
|
2009-09-07 18:02:06 +02:00
|
|
|
name = self.name
|
2009-09-14 17:16:52 +02:00
|
|
|
result = [ "subroutine touch_%s"%(name) ]
|
|
|
|
result += map(lambda x: " Use %s"%(x),mods)
|
|
|
|
result.append(" implicit none")
|
2009-09-07 18:02:06 +02:00
|
|
|
if command_line.do_debug:
|
|
|
|
length = str(len("touch_%s"%(name)))
|
2011-09-30 19:10:18 +02:00
|
|
|
result += [ " character*(%s) :: irp_here = 'touch_%s'"%(length,name) ]
|
|
|
|
if command_line.do_debug:
|
|
|
|
result += [ " call irp_enter(irp_here)" ]
|
2009-09-14 17:16:52 +02:00
|
|
|
result += map( lambda x: " %s_is_built = .False."%(x), parents)
|
|
|
|
result.append(" %s_is_built = .True."%(name))
|
2009-09-07 18:02:06 +02:00
|
|
|
if command_line.do_debug:
|
2009-09-08 16:00:46 +02:00
|
|
|
result.append(" call irp_leave(irp_here)")
|
|
|
|
result.append("end subroutine touch_%s"%(name))
|
|
|
|
result.append("")
|
2009-09-07 18:02:06 +02:00
|
|
|
self._toucher = result
|
|
|
|
return self._toucher
|
|
|
|
toucher = property(toucher)
|
|
|
|
|
2011-05-26 11:14:48 +02:00
|
|
|
##########################################################
|
|
|
|
def locker(self):
|
|
|
|
if '_locker' not in self.__dict__:
|
|
|
|
if not command_line.do_openmp:
|
|
|
|
self._locker = []
|
|
|
|
else:
|
|
|
|
from modules import modules
|
|
|
|
from variables import variables
|
|
|
|
name = self.name
|
|
|
|
result = [ "subroutine irp_lock_%s(set)"%(name) ]
|
|
|
|
result += [ " use omp_lib",
|
|
|
|
" implicit none",
|
|
|
|
" logical, intent(in) :: set",
|
|
|
|
" integer(kind=omp_nest_lock_kind),save :: %s_lock"%(name),
|
|
|
|
" integer,save :: ifirst",
|
|
|
|
]
|
|
|
|
if command_line.do_debug:
|
|
|
|
length = str(len("irp_lock_%s"%(name)))
|
|
|
|
result += [ " character*(%s) :: irp_here = 'irp_lock_%s'"%(length,name),
|
|
|
|
" call irp_enter(irp_here)" ]
|
|
|
|
result += [ " if (ifirst == 0) then",
|
|
|
|
" ifirst = 1",
|
|
|
|
" call omp_init_nest_lock(%s_lock)"%(name),
|
|
|
|
" endif",
|
|
|
|
" if (set) then",
|
|
|
|
" call omp_set_nest_lock(%s_lock)"%(name),
|
|
|
|
" else",
|
|
|
|
" call omp_unset_nest_lock(%s_lock)"%(name),
|
|
|
|
" endif",
|
|
|
|
]
|
|
|
|
if command_line.do_debug:
|
|
|
|
result.append(" call irp_leave(irp_here)")
|
|
|
|
result.append("end subroutine irp_lock_%s"%(name))
|
|
|
|
result.append("")
|
|
|
|
self._locker = result
|
|
|
|
return self._locker
|
|
|
|
locker = property(locker)
|
|
|
|
|
2009-09-08 16:00:46 +02:00
|
|
|
##########################################################
|
|
|
|
def reader(self):
|
|
|
|
if '_reader' not in self.__dict__:
|
2009-09-09 16:59:43 +02:00
|
|
|
if not self.is_main:
|
|
|
|
self._reader = []
|
|
|
|
else:
|
|
|
|
if '_needs' not in self.__dict__:
|
|
|
|
import parsed_text
|
|
|
|
from variables import variables
|
|
|
|
name = self.name
|
|
|
|
result = [ \
|
|
|
|
"subroutine reader_%s(irp_num)"%(name),
|
|
|
|
" use %s"%(self.fmodule),
|
|
|
|
" implicit none",
|
|
|
|
" character*(*), intent(in) :: irp_num",
|
|
|
|
" logical :: irp_is_open",
|
|
|
|
" integer :: irp_iunit" ]
|
|
|
|
if command_line.do_debug:
|
|
|
|
length = len("reader_%s"%(self.name))
|
|
|
|
result += [\
|
2009-09-16 15:59:13 +02:00
|
|
|
" character*(%d) :: irp_here = 'reader_%s'"%(length,name),
|
2009-09-09 16:59:43 +02:00
|
|
|
" call irp_enter(irp_here)" ]
|
|
|
|
result += map(lambda x: " call reader_%s(irp_num)"%(x),self.needs)
|
|
|
|
result += [ \
|
|
|
|
" irp_is_open = .True.",
|
|
|
|
" irp_iunit = 9",
|
|
|
|
" do while (irp_is_open)",
|
|
|
|
" irp_iunit = irp_iunit+1",
|
|
|
|
" inquire(unit=irp_iunit,opened=irp_is_open)",
|
|
|
|
" enddo"]
|
|
|
|
for n in [ name ]+self.others:
|
|
|
|
result += [\
|
|
|
|
" open(unit=irp_iunit,file='irpf90_%s_'//trim(irp_num),form='FORMATTED',status='OLD',action='READ')"%(n),
|
2009-09-25 16:57:22 +02:00
|
|
|
" read(irp_iunit,*) %s%s"%(n,build_dim_colons(variables[n])),
|
2009-09-09 16:59:43 +02:00
|
|
|
" close(irp_iunit)" ]
|
2009-09-14 14:36:39 +02:00
|
|
|
result += [ \
|
2009-09-09 16:59:43 +02:00
|
|
|
" call touch_%s"%(name),
|
|
|
|
" %s_is_built = .True."%(name) ]
|
|
|
|
if command_line.do_debug:
|
|
|
|
result.append(" call irp_leave(irp_here)")
|
|
|
|
result.append("end subroutine reader_%s"%(name))
|
|
|
|
result.append("")
|
|
|
|
self._reader = result
|
2009-09-08 16:00:46 +02:00
|
|
|
return self._reader
|
|
|
|
reader = property(reader)
|
|
|
|
|
|
|
|
##########################################################
|
|
|
|
def writer(self):
|
|
|
|
if '_writer' not in self.__dict__:
|
2009-09-09 16:59:43 +02:00
|
|
|
if not self.is_main:
|
|
|
|
self._writer = []
|
|
|
|
else:
|
|
|
|
from variables import variables
|
|
|
|
if '_needs' not in self.__dict__:
|
|
|
|
import parsed_text
|
|
|
|
name = self.name
|
|
|
|
result = [ \
|
|
|
|
"subroutine writer_%s(irp_num)"%(name),
|
|
|
|
" use %s"%(self.fmodule),
|
|
|
|
" implicit none",
|
|
|
|
" character*(*), intent(in) :: irp_num",
|
|
|
|
" logical :: irp_is_open",
|
|
|
|
" integer :: irp_iunit" ]
|
|
|
|
if command_line.do_debug:
|
|
|
|
length = len("writer_%s"%(self.name))
|
|
|
|
result += [\
|
2009-09-16 15:59:13 +02:00
|
|
|
" character*(%d) :: irp_here = 'writer_%s'"%(length,name),
|
2009-09-09 16:59:43 +02:00
|
|
|
" call irp_enter(irp_here)" ]
|
|
|
|
result += [ \
|
|
|
|
" if (.not.%s_is_built) then"%(self.same_as),
|
|
|
|
" call provide_%s"%(self.same_as),
|
|
|
|
" endif" ]
|
|
|
|
result += map(lambda x: " call writer_%s(irp_num)"%(x),self.needs)
|
|
|
|
result += [ \
|
|
|
|
" irp_is_open = .True.",
|
|
|
|
" irp_iunit = 9",
|
|
|
|
" do while (irp_is_open)",
|
|
|
|
" irp_iunit = irp_iunit+1",
|
|
|
|
" inquire(unit=irp_iunit,opened=irp_is_open)",
|
|
|
|
" enddo" ]
|
|
|
|
for n in [ name ] + self.others:
|
|
|
|
result += [\
|
|
|
|
" open(unit=irp_iunit,file='irpf90_%s_'//trim(irp_num),form='FORMATTED',status='UNKNOWN',action='WRITE')"%(n),
|
2009-09-25 16:57:22 +02:00
|
|
|
" write(irp_iunit,*) %s%s"%(n,build_dim_colons(variables[n])),
|
2009-09-09 16:59:43 +02:00
|
|
|
" close(irp_iunit)" ]
|
|
|
|
if command_line.do_debug:
|
|
|
|
result.append(" call irp_leave(irp_here)")
|
|
|
|
result.append("end subroutine writer_%s"%(name))
|
|
|
|
result.append("")
|
|
|
|
self._writer = result
|
2009-09-08 16:00:46 +02:00
|
|
|
return self._writer
|
|
|
|
writer = property(writer)
|
|
|
|
|
|
|
|
##########################################################
|
|
|
|
def free(self):
|
|
|
|
if '_free' not in self.__dict__:
|
|
|
|
name = self.name
|
2014-10-07 11:41:48 +02:00
|
|
|
result = [ "!","! >>> FREE %s"%(name),
|
2009-09-08 16:00:46 +02:00
|
|
|
" %s_is_built = .False."%(self.same_as) ]
|
|
|
|
if self.dim != []:
|
2009-12-09 09:42:36 +01:00
|
|
|
if command_line.do_memory:
|
|
|
|
result += [ \
|
|
|
|
" if (allocated(%s)) then"%(name),
|
|
|
|
" deallocate (%s)"%(name),
|
|
|
|
" print *, 'Deallocating %s'"%(name),
|
|
|
|
" endif" ]
|
|
|
|
else:
|
|
|
|
result += [ \
|
|
|
|
" if (allocated(%s)) then"%(name),
|
|
|
|
" deallocate (%s)"%(name),
|
|
|
|
" endif" ]
|
2009-09-09 16:59:43 +02:00
|
|
|
result.append("! <<< END FREE")
|
2009-09-08 16:00:46 +02:00
|
|
|
self._free = result
|
|
|
|
return self._free
|
|
|
|
free = property(free)
|
|
|
|
|
|
|
|
##########################################################
|
|
|
|
def provider(self):
|
|
|
|
if '_provider' not in self.__dict__:
|
2009-09-09 16:59:43 +02:00
|
|
|
if not self.is_main:
|
|
|
|
self._provider = []
|
|
|
|
else:
|
2009-09-08 16:00:46 +02:00
|
|
|
if '_to_provide' not in self.__dict__:
|
|
|
|
import parsed_text
|
|
|
|
from variables import variables, build_use, call_provides
|
|
|
|
name = self.name
|
|
|
|
same_as = self.same_as
|
|
|
|
|
2014-05-23 22:51:36 +02:00
|
|
|
def check_openmp():
|
2014-10-08 21:14:35 +02:00
|
|
|
if not do_openmp:
|
2014-05-23 22:51:36 +02:00
|
|
|
result = [ "!$ nthreads = omp_get_num_threads()" ,
|
|
|
|
"!$ if (nthreads > 1) then" ,
|
|
|
|
"!$ print *, irp_here//': Error: Provider in an openMP section'" ,
|
|
|
|
"!$ stop 1",
|
|
|
|
"!$ endif" ]
|
2014-10-08 21:14:35 +02:00
|
|
|
else:
|
2014-10-08 16:24:01 +02:00
|
|
|
result = []
|
2014-10-08 21:14:35 +02:00
|
|
|
return result
|
2014-05-23 22:51:36 +02:00
|
|
|
|
2009-09-08 16:00:46 +02:00
|
|
|
def build_alloc(name):
|
|
|
|
self = variables[name]
|
|
|
|
if self.dim == []:
|
|
|
|
return []
|
|
|
|
|
|
|
|
def do_size():
|
|
|
|
result = " print *, ' size: ("
|
|
|
|
result += ','.join(self.dim)
|
|
|
|
return result+")'"
|
|
|
|
|
|
|
|
def check_dimensions():
|
|
|
|
result = map(lambda x: "(%s>0)"%(dimsize(x)), self.dim)
|
|
|
|
result = ".and.".join(result)
|
|
|
|
result = " if (%s) then"%(result)
|
|
|
|
return result
|
|
|
|
|
|
|
|
def dimensions_OK():
|
|
|
|
result = [ " irp_dimensions_OK = .True." ]
|
|
|
|
for i,k in enumerate(self.dim):
|
|
|
|
result.append(" irp_dimensions_OK = irp_dimensions_OK.AND.(SIZE(%s,%d)==(%s))"%(name,i+1,dimsize(k)))
|
|
|
|
return result
|
|
|
|
|
|
|
|
def do_allocate():
|
2014-10-07 11:41:48 +02:00
|
|
|
if command_line.coarray:
|
|
|
|
result = " allocate(%s(%s)[*],stat=irp_err)"
|
|
|
|
else:
|
|
|
|
result = " allocate(%s(%s),stat=irp_err)"
|
2009-09-08 16:00:46 +02:00
|
|
|
result = result%(name,','.join(self.dim))
|
2009-12-09 09:42:36 +01:00
|
|
|
if command_line.do_memory:
|
2012-12-19 11:35:21 +01:00
|
|
|
tmp = "\n print *, %s, 'Allocating %s(%s)'"
|
2009-11-02 16:16:13 +01:00
|
|
|
d = ','.join(self.dim)
|
2012-12-19 11:35:21 +01:00
|
|
|
result += tmp%('size('+name+')',name,d)
|
2009-09-08 16:00:46 +02:00
|
|
|
return result
|
|
|
|
|
|
|
|
result = [ " if (allocated (%s) ) then"%(name) ]
|
|
|
|
result += dimensions_OK()
|
|
|
|
result += [\
|
|
|
|
" if (.not.irp_dimensions_OK) then",
|
2009-11-02 16:16:13 +01:00
|
|
|
" deallocate(%s,stat=irp_err)"%(name),
|
|
|
|
" if (irp_err /= 0) then",
|
|
|
|
" print *, irp_here//': Deallocation failed: %s'"%(name),
|
|
|
|
do_size(),
|
|
|
|
" endif"]
|
2009-12-09 09:42:36 +01:00
|
|
|
if command_line.do_memory:
|
|
|
|
result += [\
|
|
|
|
" print *, 'Deallocating %s'"%(name) ]
|
2009-09-08 16:00:46 +02:00
|
|
|
result.append(check_dimensions())
|
|
|
|
result.append(do_allocate())
|
|
|
|
result += [\
|
|
|
|
" if (irp_err /= 0) then",
|
|
|
|
" print *, irp_here//': Allocation failed: %s'"%(name),
|
|
|
|
do_size(),
|
|
|
|
" endif",
|
|
|
|
" endif",
|
|
|
|
" endif",
|
|
|
|
" else" ]
|
|
|
|
result.append(check_dimensions())
|
|
|
|
result.append(do_allocate())
|
|
|
|
result += [\
|
|
|
|
" if (irp_err /= 0) then",
|
|
|
|
" print *, irp_here//': Allocation failed: %s'"%(name),
|
|
|
|
do_size(),
|
|
|
|
" endif",
|
|
|
|
" endif",
|
|
|
|
" endif" ]
|
|
|
|
return result
|
|
|
|
|
2011-10-21 09:10:40 +02:00
|
|
|
result = []
|
|
|
|
if command_line.directives and command_line.inline in ["all","providers"]:
|
|
|
|
result += [ "!DEC$ ATTRIBUTES FORCEINLINE :: provide_%s"%(name) ]
|
|
|
|
result += [ "subroutine provide_%s"%(name) ]
|
2009-09-08 16:00:46 +02:00
|
|
|
result += build_use( [same_as]+self.to_provide )
|
2014-05-23 22:51:36 +02:00
|
|
|
result += ["!$ use omp_lib"]
|
2009-09-08 16:00:46 +02:00
|
|
|
result.append(" implicit none")
|
|
|
|
length = len("provide_%s"%(name))
|
|
|
|
result += [\
|
2009-09-16 15:59:13 +02:00
|
|
|
" character*(%d) :: irp_here = 'provide_%s'"%(length,name),
|
2009-09-08 16:00:46 +02:00
|
|
|
" integer :: irp_err ",
|
2014-05-23 22:51:36 +02:00
|
|
|
" logical :: irp_dimensions_OK",
|
|
|
|
"!$ integer :: nthreads"]
|
2011-05-26 11:14:48 +02:00
|
|
|
if command_line.do_openmp:
|
|
|
|
result.append(" call irp_lock_%s(.True.)"%(same_as))
|
2014-05-23 22:51:36 +02:00
|
|
|
else:
|
|
|
|
result += check_openmp()
|
2009-09-08 16:00:46 +02:00
|
|
|
if command_line.do_assert or command_line.do_debug:
|
|
|
|
result.append(" call irp_enter(irp_here)")
|
|
|
|
result += call_provides(self.to_provide)
|
|
|
|
result += flatten( map(build_alloc,[self.same_as]+self.others) )
|
2011-05-26 11:14:48 +02:00
|
|
|
result += [ " if (.not.%s_is_built) then"%(same_as),
|
|
|
|
" call bld_%s"%(same_as),
|
|
|
|
" %s_is_built = .True."%(same_as), "" ]
|
|
|
|
result += [ " endif" ]
|
2009-09-08 16:00:46 +02:00
|
|
|
if command_line.do_assert or command_line.do_debug:
|
|
|
|
result.append(" call irp_leave(irp_here)")
|
2011-05-26 11:14:48 +02:00
|
|
|
if command_line.do_openmp:
|
|
|
|
result.append(" call irp_lock_%s(.False.)"%(same_as))
|
2009-09-08 16:00:46 +02:00
|
|
|
result.append("end subroutine provide_%s"%(name) )
|
|
|
|
result.append("")
|
|
|
|
self._provider = result
|
|
|
|
return self._provider
|
|
|
|
provider = property(provider)
|
|
|
|
|
2009-09-08 18:20:20 +02:00
|
|
|
##########################################################
|
|
|
|
def builder(self):
|
|
|
|
if '_builder' not in self.__dict__:
|
2009-09-09 16:59:43 +02:00
|
|
|
if not self.is_main:
|
|
|
|
self._builder = []
|
2009-09-14 14:36:39 +02:00
|
|
|
else:
|
|
|
|
import parsed_text
|
|
|
|
from variables import build_use, call_provides
|
|
|
|
for filename,buffer in parsed_text.parsed_text:
|
|
|
|
if self.line.filename[0].startswith(filename):
|
|
|
|
break
|
|
|
|
text = []
|
|
|
|
same_as = self.same_as
|
|
|
|
inside = False
|
|
|
|
for vars,line in buffer:
|
2010-10-02 23:42:55 +02:00
|
|
|
if type(line) == Begin_provider:
|
2009-09-14 14:36:39 +02:00
|
|
|
if line.filename[1] == same_as:
|
|
|
|
inside = True
|
|
|
|
vars = []
|
2009-09-09 16:59:43 +02:00
|
|
|
if inside:
|
2009-09-14 14:36:39 +02:00
|
|
|
text.append( (vars,line) )
|
|
|
|
text += map( lambda x: ([],Simple_line(line.i,x,line.filename)), call_provides(vars) )
|
2011-09-30 19:10:18 +02:00
|
|
|
if command_line.do_profile and type(line) == Begin_provider:
|
2011-09-30 23:18:17 +02:00
|
|
|
text.append( ( [], Declaration(line.i," double precision :: irp_rdtsc, irp_rdtsc1, irp_rdtsc2",line.filename) ) )
|
2011-09-30 19:10:18 +02:00
|
|
|
text.append( ( [], Simple_line(line.i," irp_rdtsc1 = irp_rdtsc()",line.filename) ) )
|
2010-10-02 23:42:55 +02:00
|
|
|
if type(line) == End_provider:
|
2009-09-14 14:36:39 +02:00
|
|
|
if inside:
|
|
|
|
break
|
|
|
|
name = self.name
|
|
|
|
text = parsed_text.move_to_top(text,Declaration)
|
|
|
|
text = parsed_text.move_to_top(text,Implicit)
|
|
|
|
text = parsed_text.move_to_top(text,Use)
|
|
|
|
text = map(lambda x: x[1], text)
|
2014-05-23 22:34:09 +02:00
|
|
|
inside_omp = False
|
2009-09-14 14:36:39 +02:00
|
|
|
for line in filter(lambda x: type(x) not in [ Begin_doc, End_doc, Doc], text):
|
|
|
|
if type(line) == Begin_provider:
|
2011-10-21 09:10:40 +02:00
|
|
|
result = []
|
|
|
|
if command_line.directives and command_line.inline in ["all","builders"]:
|
2011-10-21 10:21:49 +02:00
|
|
|
result += [ "!DEC$ ATTRIBUTES INLINE :: bld_%s"%(same_as) ]
|
2011-10-21 09:10:40 +02:00
|
|
|
result += [ "subroutine bld_%s"%(name) ]
|
2009-09-14 14:36:39 +02:00
|
|
|
result += build_use([name]+self.needs)
|
|
|
|
elif type(line) == Cont_provider:
|
|
|
|
pass
|
|
|
|
elif type(line) == End_provider:
|
2011-09-30 19:10:18 +02:00
|
|
|
if command_line.do_profile:
|
|
|
|
result += [ " irp_rdtsc2 = irp_rdtsc()" ,
|
|
|
|
" call irp_set_timer(%d,(irp_rdtsc2-irp_rdtsc1))"%self.label ]
|
2009-09-14 14:36:39 +02:00
|
|
|
result.append( "end subroutine bld_%s"%(name) )
|
2009-09-09 16:59:43 +02:00
|
|
|
break
|
2014-05-23 22:34:09 +02:00
|
|
|
elif type(line) == Openmp:
|
|
|
|
# Detect OpenMP blocks
|
|
|
|
buffer = line.text.lower().split()
|
|
|
|
if buffer[1] == "parallel":
|
|
|
|
inside_omp = True
|
|
|
|
self._has_openmp = True
|
|
|
|
if buffer[1] == "end" and buffer[2] == "parallel":
|
|
|
|
inside_omp = False
|
|
|
|
result.append(line.text)
|
2009-09-14 14:36:39 +02:00
|
|
|
else:
|
2014-05-23 22:34:09 +02:00
|
|
|
# if inside_omp:
|
|
|
|
# if type(line) in [ Provide_all, Provide, Touch, SoftTouch ]:
|
|
|
|
# error.fail(line,str(type(line))+"is not allowed in an OpenMP block.")
|
2009-09-14 14:36:39 +02:00
|
|
|
result.append(line.text)
|
|
|
|
self._builder = result
|
2009-09-08 18:20:20 +02:00
|
|
|
return self._builder
|
|
|
|
builder = property(builder)
|
|
|
|
|
2009-09-09 16:59:43 +02:00
|
|
|
##########################################################
|
|
|
|
def children(self):
|
|
|
|
if '_children' not in self.__dict__:
|
|
|
|
if not self.is_main:
|
|
|
|
self._children = []
|
|
|
|
from variables import variables
|
|
|
|
if '_needs' not in self.__dict__:
|
|
|
|
import parsed_text
|
|
|
|
result = []
|
|
|
|
for x in self.needs:
|
|
|
|
result.append(x)
|
|
|
|
try:
|
|
|
|
result += variables[x].children
|
|
|
|
except RuntimeError:
|
|
|
|
pass # Exception will be checked after
|
|
|
|
self._children = make_single(result)
|
|
|
|
if self.name in result:
|
|
|
|
error.fail(self.line,"Cyclic dependencies:\n%s"%(str(self._children)))
|
|
|
|
return self._children
|
|
|
|
children = property(children)
|
|
|
|
|
|
|
|
##########################################################
|
|
|
|
def parents(self):
|
|
|
|
if '_parents' not in self.__dict__:
|
2010-09-01 15:10:16 +02:00
|
|
|
if not self.is_main:
|
2009-09-09 16:59:43 +02:00
|
|
|
self._parents = []
|
|
|
|
else:
|
|
|
|
from variables import variables
|
|
|
|
if '_needed_by' not in self.__dict__:
|
|
|
|
import parsed_text
|
2013-01-21 12:27:44 +01:00
|
|
|
if command_line.do_unused and self.needed_by == []:
|
|
|
|
error.warn(None, "Provider %s is not used"%self.name)
|
2009-09-09 16:59:43 +02:00
|
|
|
result = []
|
|
|
|
for x in self.needed_by:
|
|
|
|
result.append(x)
|
|
|
|
try:
|
|
|
|
result += variables[x].parents
|
|
|
|
except RuntimeError:
|
|
|
|
pass # Exception will be checked after
|
|
|
|
self._parents = make_single(result)
|
|
|
|
if self.name in result:
|
|
|
|
error.fail(self.line,"Cyclic dependencies:\n%s"%(str(self._parents)))
|
|
|
|
return self._parents
|
|
|
|
parents = property(parents)
|
|
|
|
|
2009-09-04 15:11:42 +02:00
|
|
|
######################################################################
|
|
|
|
if __name__ == '__main__':
|
|
|
|
from preprocessed_text import preprocessed_text
|
|
|
|
from variables import variables
|
2009-09-08 16:00:46 +02:00
|
|
|
#for v in variables.keys():
|
|
|
|
# print v
|
2009-09-09 16:59:43 +02:00
|
|
|
for line in variables['e_loc'].parents:
|
2009-09-07 18:02:06 +02:00
|
|
|
print line
|