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

Omp #21

Closed
wants to merge 19 commits into from
Closed
File renamed without changes.
1,795 changes: 1,795 additions & 0 deletions source/#wrappergenerator.py#

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion source/Forthon.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ void
Py_XDECREF(m);

PyMem_Free(cname);
if (PyErr_Occurred()) PyErr_Print();
if (PyErr_Occurred()){

PyErr_Print();}
}

void
Expand Down
10 changes: 5 additions & 5 deletions source/ForthonTimer.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@


def ForthonTimerdoc():
import ForthonTimer
print ForthonTimer.__doc__
from . import ForthonTimer
print((ForthonTimer.__doc__))


#############################################################################
Expand Down Expand Up @@ -77,8 +77,8 @@ def out(self, maxlevel, mintime=0.):
if self.level > maxlevel:
return
if self.time > mintime:
print "%2d%s%s %d %f"%(self.level, self.level*' ', self.name, self.ncalls, self.time)
for v in self.subtimers.itervalues():
print(("%2d%s%s %d %f"%(self.level, self.level*' ', self.name, self.ncalls, self.time)))
for v in list(self.subtimers.values()):
v.out(maxlevel, mintime)


Expand Down Expand Up @@ -155,7 +155,7 @@ def profiler(self, frame, event, arg):
# --- at the proper time relative to the trace.
sys.stdout.flush()
sys.stderr.flush()
print "%s %s %s %s %d"%(self.level*' ', event, name, frame.f_code.co_filename, frame.f_lineno)
print(("%s %s %s %s %d"%(self.level*' ', event, name, frame.f_code.co_filename, frame.f_lineno)))
if event == 'call':
self.level = self.level + 1
self.timer = self.timer.newtimer(name)
Expand Down
33 changes: 22 additions & 11 deletions source/Forthon_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@
from distutils.dist import Distribution
from distutils.command.build import build

from Forthon_options import args
from .Forthon_options import args
from Forthon.compilers import FCompiler

# --- Get the package name, which is assumed to be the first argument.
pkg = args.pkgname

print "Building package " + pkg
print(("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 All @@ -38,7 +38,7 @@
build_base = args.build_base
build_temp = args.build_temp
builddir = args.builddir
cargs = args.cargs
cargslist = args.cargslist
compile_first = args.compile_first
debug = args.debug
defines = args.defines
Expand Down Expand Up @@ -72,6 +72,12 @@
with_feenableexcept = args.with_feenableexcept
writemodules = args.writemodules

#JG: omp related arguments
ompvarlistfile=args.ompvarlistfile
ompverbose=args.ompverbose
ompforceall=args.ompforceall
omppkg=args.omppkg

# --- These args require special handling

if initialgallot:
Expand All @@ -85,7 +91,7 @@
f90 = '--f77'

fargs = ' '.join(fargslist)

cargs = ' '.join(cargslist)
if not fortranfile:
# --- Find the main fortran file, which should have a name like pkg.suffix
# --- where suffix is one of the free or fixed suffices.
Expand All @@ -106,7 +112,12 @@
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))
if ompverbose:
forthonargs.append('--ompverbose')
if ompforceall:
forthonargs.append('--ompforceall')
# --- Get the numpy headers path
import numpy
if numpy.__version__ < '1.1.0':
Expand Down Expand Up @@ -148,7 +159,7 @@ def fixpath(path, dos=1):
# --- Find place where packages are placed. This imports one of the
# --- Forthon files and gets the path from that. It uses fvars.py since
# --- that is a small file which doesn't have other dependencies.
import fvars
from . import fvars
forthonhome = os.path.dirname(fvars.__file__)
forthonhome = fixpath(forthonhome)
del fvars
Expand Down Expand Up @@ -207,8 +218,8 @@ def fixpath(path, dos=1):
popt = fcompiler.popt
forthonargs = forthonargs + fcompiler.forthonargs
if fopt is None: fopt = fcompiler.fopt
extra_link_args = fcompiler.extra_link_args
extra_compile_args = fcompiler.extra_compile_args
extra_link_args = fcompiler.extra_link_args
extra_compile_args = fcompiler.extra_compile_args
define_macros = fcompiler.define_macros

# --- Create path to fortran files for the Makefile since they will be
Expand Down Expand Up @@ -305,9 +316,9 @@ def getpathbasename(f):
fargs = fargs + ' -I'+i+' '

# --- Add in any user supplied cargs
#print('>>>>>>>>>> Cargs:',cargs)
if cargs is not None:
extra_compile_args.append(cargs)

extra_compile_args.append(cargs)
pypreproc = '%(python)s -c "from Forthon.preprocess import main;main()" %(f90)s -t%(machine)s %(forthonargs)s'%locals()
forthon = '%(python)s -c "from Forthon.wrappergenerator import wrappergenerator_main;wrappergenerator_main()"'%locals()
noprintdirectory = ''
Expand Down Expand Up @@ -479,7 +490,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
12 changes: 9 additions & 3 deletions source/Forthon_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import sys
import os.path
import optparse
from version import version
from .version import version

parser = optparse.OptionParser(
usage="Forthon [options] pkgname [extra Fortran or C files to be compiled or objects to link] [options for distutils]",
Expand Down Expand Up @@ -48,7 +48,9 @@
parser.add_option('--build-temp', default='', help='Location where the *pymodule.o files should be placed. This is relative to the builddir. This defaults to the builddir.')
parser.add_option('--builddir', help='Location where the temporary compilation files (such as object files) should be placed. This defaults to build/temp-osname.')

parser.add_option('--cargs', help='Additional options for the C compiler. These are passed through distutils, which does the compilation of C code. If there are any spaces in options, it must be surrounded in double quotes.')
parser.add_option('--cargs', default=[],action='append',dest='cargslist', metavar="CARGS",help='Additional options for the C compiler. These are passed through distutils, which does the compilation of C code. If there are any spaces in options, it must be surrounded in double quotes.')


parser.add_option('--compile_first', default='', metavar="FILE", help='The specified file is compiled first. Normally the file that is compiled first is the fortran file generated by Forthon, which would normally contain all of the modules. But if the modules are in a different file, for example, then that file would need to be compiled first and should be specified here.')

parser.add_option('-g', '--debug', action='store_true', default=False, help='Turns off optimization for fortran compiler.')
Expand Down Expand Up @@ -100,12 +102,16 @@

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('--ompverbose', action='store_true', default=False, dest='ompverbose', help="Verbose mode for omp options")
parser.add_option('--ompforceall', action='store_true', default=False, dest='ompforceall',help="Force all variables to threadprivated (for debug purpose only)")
parser.add_option('--ompvarlistfile', default=None, help="Path to a file containing the list of variables the omp directive threadprivate must be applied to")

# --- Print help and then exit if no arguments are given
if len(sys.argv) == 1:
parser.print_help()
sys.exit(0)

# --- Only process the true argument list when this is called from Forthon.
# --- Otherwise ignore the arguments. This is needed since for example this
# --- module may be imported by the compilers module which is used by some
Expand Down
Loading