Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add parser of data block to dynamically declare size of data block #22

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Add omp extension to set privatethreaded variables: extension of the …
…wrappergenerator with a subclass, additional Forthon option to handle omp settings.
  • Loading branch information
jguterl committed Oct 4, 2020
commit 94060f17c3daf9816e80e228672b3646e46a5112
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
print('Permissions on License.txt and Src files needs to be set by hand')

# --- Write out version information to the version.py file.
version = '0.8.49'
version = '0.9.0'
try:
# --- In python3, check_output or Popen returns a byte string that needs to be decoded to get the string.
# --- The decode method is mostly harmless in python2.
Expand Down
10 changes: 8 additions & 2 deletions source/Forthon_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
# --- Get the package name, which is assumed to be the first argument.
pkg = args.pkgname

print "Building package " + pkg
print(">>> Forthon: Building package " + pkg)

# --- Get any extra fortran, C or object files listed.
# --- This scans through args until the end or until it finds an optional
Expand Down Expand Up @@ -72,6 +72,10 @@
with_feenableexcept = args.with_feenableexcept
writemodules = args.writemodules

#omp related arguments
ompvarlistfile=args.ompvarlistfile
omppkg=args.omppkg
ompdebug=args.ompdebug
# --- These args require special handling

if initialgallot:
Expand Down Expand Up @@ -106,6 +110,8 @@
else: forthonargs.append('--no2underscores')
if not writemodules: forthonargs.append('--nowritemodules')
if timeroutines: forthonargs.append('--timeroutines')
forthonargs.append('--omppkg {}'.format(omppkg))
forthonargs.append('--ompvarlistfile {}'.format(ompvarlistfile))

# --- Get the numpy headers path
import numpy
Expand Down Expand Up @@ -478,7 +484,7 @@ def getpathbasename(f):
extra_link_args += ['-Wl,-z,lazy']

if not verbose:
print " Setup " + pkg
print(" Setup " + pkg)
sys.stdout = open(os.devnull, 'w')

if with_feenableexcept:
Expand Down
6 changes: 6 additions & 0 deletions source/Forthon_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,12 @@
parser.add_option('--writemodules', action='store_true', default=True, dest='writemodules')
parser.add_option('--nowritemodules', action='store_false', default=True, dest='writemodules', help="Don't write out the module definitions. Useful if the modules have been written already. Note that if variables of derived type are used, the original code will need to be modified. See example2. Also note that if this option is used, no checks are made to ensure the consistency between the interface file description and the actual module.")

# OMP related options
parser.add_option('--omppkg',default=None, help="Activate implementation of omp declarations for the listed packages")
parser.add_option('--ompvarlistfile', default=None, help="Path to a file containing the list of variables the omp directive threadprivate must be applied to")
parser.add_option('--ompdebug', action='store_true',default=False, help="flag to activate printing of omp debug log.")


# --- Print help and then exit if no arguments are given
if len(sys.argv) == 1:
parser.print_help()
Expand Down
5 changes: 3 additions & 2 deletions source/compilers.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class FCompiler:
appropriate block for the machine.
"""

def __init__(self, machine=None, debug=0, fcompname=None, fcompexec=None, implicitnone=1, twounderscores=0):
def __init__(self, machine=None, debug=0, fcompname=None, fcompexec=None, implicitnone=1, twounderscores=0,omp=False):
if machine is None:
machine = sys.platform
self.machine = machine
Expand Down Expand Up @@ -129,7 +129,8 @@ def __init__(self, machine=None, debug=0, fcompname=None, fcompexec=None, implic
self.popt = '-g'
self.extra_link_args += ['-g']
self.extra_compile_args += ['-g', '-O0']

if omp:
self.extra_compile_args += ['-fopenmp']
# --- Add the compiler name to the forthon arguments
self.forthonargs += ['-F ' + self.fcompname]

Expand Down
44 changes: 34 additions & 10 deletions source/wrappergenerator.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,17 @@
from Forthon_options import args
from cfinterface import *
import wrappergen_derivedtypes
from wrappergenerator_ompextension import PyWrap_OMPExtension
if sys.hexversion >= 0x20501f0:
import hashlib
else:
# --- hashlib was not available in python earlier than 2.5.
import md5 as hashlib



class PyWrap:

class PyWrap(PyWrap_OMPExtension):
"""
Usage:
-a All groups will be allocated on initialization
Expand All @@ -39,7 +42,7 @@ class PyWrap:

def __init__(self, varfile, pkgname, pkgsuffix, pkgbase, initialgallot=1, writemodules=1,
otherinterfacefiles=[], other_scalar_vars=[], timeroutines=0,
otherfortranfiles=[], fcompname=None):
otherfortranfiles=[], fcompname=None,ompvarlistfile=None,omppkg=None,ompdebug=False):
self.varfile = varfile
self.pkgname = pkgname
self.pkgsuffix = pkgsuffix
Expand All @@ -54,6 +57,7 @@ def __init__(self, varfile, pkgname, pkgsuffix, pkgbase, initialgallot=1, writem
self.isz = isz # isz defined in cfinterface

self.processvariabledescriptionfile()
self.OMPInit(ompvarlistfile,omppkg,ompdebug)

def cname(self, n):
# --- Standard name of the C interface to a Fortran routine
Expand Down Expand Up @@ -1080,7 +1084,6 @@ def maparraydimsctof(dim):
# --- Write out f90 modules, including any data statements
if self.writemodules:
self.writef90modules()

###########################################################################
self.fw('subroutine ' + self.fsub('passpointers') + '()')

Expand Down Expand Up @@ -1119,19 +1122,26 @@ def maparraydimsctof(dim):
# --- Pointers must be explicitly nullified in order to get
# --- associated to return a false value.
self.fw('subroutine ' + self.fsub('nullifypointers') + '()')

# --- Write out the Use statements
for g in self.groups + self.hidden_groups:
self.fw(' use ' + g)

if self.ompactive:
self.fw('integer::tid,omp_get_thread_num')
for i in range(len(self.slist)):
s = self.slist[i]
if s.dynamic:
self.fw(' nullify(' + s.name + ')')
if self.ompactive:
self.ThreadedNullify(s)
else:
self.fw(' nullify(' + s.name + ')')
for i in range(len(self.alist)):
a = self.alist[i]
if a.dynamic:
self.fw(' nullify(' + a.name + ')')
if self.ompactive:
self.ThreadedNullify(a)
else:
self.fw(' nullify(' + a.name + ')')

self.fw(' return')
self.fw('end')
Expand Down Expand Up @@ -1197,7 +1207,10 @@ def maparraydimsctof(dim):
else:
self.fw(' ' + fvars.ftof(a.type) + ', target:: p__' +
self.prefixdimsf(re.sub('[ \t\n]', '', a.dimstring)))
self.fw(' ' + a.name + ' => p__')
if self.ompactive:
self.ThreadedAssociation(a)
else:
self.fw(' ' + a.name + ' => p__')
self.fw(' return')
self.fw('end')
if re.search('fassign', a.attr):
Expand Down Expand Up @@ -1277,7 +1290,11 @@ def writef90modules(self):
# --- multiple lines.
dd = re.sub(r'\n', '&\n', a.data)
self.fw(' data ' + a.name + dd)
if self.ompactive:
self.DeclareThreadPrivate(g)
self.fw('end module ' + g)
if self.ompactive:
self.writef90OMPCopyHelper()

###############################################################################
###############################################################################
Expand Down Expand Up @@ -1306,7 +1323,7 @@ def wrappergenerator_main(argv=None, writef90modulesonly=0):
varfile = args.remainder[0]
otherfortranfiles = args.remainder[1:]
except IndexError:
print PyWrap.__doc__
print(PyWrap.__doc__)
sys.exit(1)

# --- get other command line args and default actions
Expand All @@ -1317,6 +1334,9 @@ def wrappergenerator_main(argv=None, writef90modulesonly=0):
writemodules = args.writemodules
timeroutines = args.timeroutines
otherinterfacefiles = args.othermacros
ompvarlistfile=args.ompvarlistfile
omppkg=args.omppkg
ompdebug=args.ompdebug

# --- a list of scalar dictionaries from other modules.
other_scalar_vars = []
Expand All @@ -1325,7 +1345,7 @@ def wrappergenerator_main(argv=None, writef90modulesonly=0):

cc = PyWrap(varfile, pkgname, pkgsuffix, pkgbase, initialgallot, writemodules,
otherinterfacefiles, other_scalar_vars, timeroutines,
otherfortranfiles, fcompname)
otherfortranfiles, fcompname,ompvarlistfile,omppkg,ompdebug)
if writef90modulesonly:
cc.writef90modules()
else:
Expand All @@ -1335,6 +1355,10 @@ def wrappergenerator_main(argv=None, writef90modulesonly=0):
writeforthonf2c()






# --- This might make some of the write statements cleaner.
# --- From http://aspn.activestate.com/ASPN/Python/Cookbook/
class PrintEval:
Expand Down
Loading