Skip to content

Commit

Permalink
[SCons] Modify build system to exclude unused Fortran and f2c code
Browse files Browse the repository at this point in the history
Cantera no longer requires BLAS / LAPACK (but can use them if available), so it
is never necessary to compile any of the external Fortran or f2c-converted code.
  • Loading branch information
speth committed May 15, 2016
1 parent efb068e commit df43a47
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 120 deletions.
46 changes: 16 additions & 30 deletions SConstruct
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ if 'clean' in COMMAND_LINE_TARGETS:
removeFile('.sconsign.dblite')
removeFile('include/cantera/base/config.h')
removeDirectory('include/cantera/ext')
removeFile('ext/f2c_libs/arith.h')
removeFile('interfaces/cython/cantera/_cantera.cpp')
removeFile('interfaces/cython/setup2.py')
removeFile('interfaces/cython/setup3.py')
Expand Down Expand Up @@ -385,7 +384,8 @@ config_options = [
PathVariable(
'FORTRAN',
"""The Fortran (90) compiler. If unspecified, the builder will look for
a compatible compiler (gfortran, ifort, g95) in the $PATH.""",
a compatible compiler (gfortran, ifort, g95) in the $PATH. Used only
for compiling the Fortran 90 interface.""",
'', PathVariable.PathAccept),
('FORTRANFLAGS',
'Compilation options for the Fortran (90) compiler.',
Expand Down Expand Up @@ -433,12 +433,12 @@ config_options = [
e.g. /usr/lib.""",
'', PathVariable.PathAccept),
('blas_lapack_libs',
"""Cantera comes with Fortran (or C) versions of those parts of BLAS and
LAPACK it requires. But performance may be better if you use a version
of these libraries optimized for your machine hardware. If you want to
use your own libraries, set blas_lapack_libs to the the list of
libraries that should be passed to the linker, separated by commas,
e.g. "lapack,blas" or "lapack,f77blas,cblas,atlas".""",
"""Cantera can use BLAS and LAPACK libraries available on your system if
you have optimized versions available (e.g. Intel MKL). Otherwise,
Cantera will use Eigen for linear algebra support. To use BLAS
and LAPACK, set blas_lapack_libs to the the list of libraries
that should be passed to the linker, separated by commas, e.g.
"lapack,blas" or "lapack,f77blas,cblas,atlas".""",
''),
PathVariable('blas_lapack_dir',
"""Directory containing the libraries specified by 'blas_lapack_libs'.""",
Expand Down Expand Up @@ -516,13 +516,6 @@ config_options = [
'boost_inc_dir',
'Location of the Boost header files.',
defaults.boostIncDir, PathVariable.PathAccept),
BoolVariable(
'build_with_f2c',
"""For external procedures written in Fortran 77, both the
original F77 source code and C source code generated by the
'f2c' program are included. Set this to "n" if you want to
build Cantera using the F77 sources in the ext directory.""",
True),
PathVariable(
'stage_dir',
""" Directory relative to the Cantera source directory to be
Expand Down Expand Up @@ -661,15 +654,14 @@ if env['system_sundials'] in ('y','default'):
# BLAS / LAPACK configuration
if env['blas_lapack_libs'] != '':
env['blas_lapack_libs'] = env['blas_lapack_libs'].split(',')
env['BUILD_BLAS_LAPACK'] = False
env['use_lapack'] = True
elif env['OS'] == 'Darwin':
env['blas_lapack_libs'] = []
env['BUILD_BLAS_LAPACK'] = False
env['use_lapack'] = True
env.Append(FRAMEWORKS=['Accelerate'])
else:
# External BLAS/LAPACK were not given, so we need to compile them
env['BUILD_BLAS_LAPACK'] = True
env['blas_lapack_libs'] = [] # built into libcantera
env['blas_lapack_libs'] = []
env['use_lapack'] = False

# ************************************
# *** Compiler Configuration Tests ***
Expand Down Expand Up @@ -895,25 +887,23 @@ if env['system_sundials'] == 'y':

# In the case where a user is trying to link Cantera to an external BLAS/LAPACK
# library, but Sundials was configured without this support, print a Warning.
if not env['has_sundials_lapack'] and not env['BUILD_BLAS_LAPACK']:
if not env['has_sundials_lapack'] and env['use_lapack']:
print ('WARNING: External BLAS/LAPACK has been specified for Cantera '
'but Sundials was built without this support.')
else: # env['system_sundials'] == 'n'
print """INFO: Using private installation of Sundials version 2.6."""
env['sundials_version'] = '2.6'
env['has_sundials_lapack'] = int(not env['BUILD_BLAS_LAPACK'])
env['has_sundials_lapack'] = int(env['use_lapack'])


# Try to find a working Fortran compiler:
env['FORTRANSYSLIBS'] = []
fortran_libs = {'gfortran':'gfortran', 'g95':'f95'}
def check_fortran(compiler, expected=False):
if which(compiler) is not None:
lib = fortran_libs.get(compiler)
if lib:
have_lib = conf.CheckLib(lib)
if have_lib:
env.Append(FORTRANSYSLIBS=lib)
env['FORTRAN'] = compiler
return True
else:
Expand Down Expand Up @@ -1241,7 +1231,7 @@ else:

configh['SUNDIALS_VERSION'] = env['sundials_version'].replace('.','')

if env.get('has_sundials_lapack') and not env['BUILD_BLAS_LAPACK']:
if env.get('has_sundials_lapack') and env['use_lapack']:
configh['SUNDIALS_USE_LAPACK'] = 1
else:
configh['SUNDIALS_USE_LAPACK'] = 0
Expand All @@ -1250,7 +1240,7 @@ cdefine('LAPACK_FTN_STRING_LEN_AT_END', 'lapack_ftn_string_len_at_end')
cdefine('LAPACK_FTN_TRAILING_UNDERSCORE', 'lapack_ftn_trailing_underscore')
cdefine('FTN_TRAILING_UNDERSCORE', 'lapack_ftn_trailing_underscore')
cdefine('LAPACK_NAMES_LOWERCASE', 'lapack_names', 'lower')
configh['CT_USE_LAPACK'] = 0 if env['BUILD_BLAS_LAPACK'] else 1
cdefine('CT_USE_LAPACK', 'use_lapack')
cdefine('CT_USE_SYSTEM_EIGEN', env['system_eigen'])

config_h = env.Command('include/cantera/base/config.h',
Expand Down Expand Up @@ -1345,10 +1335,6 @@ if env['blas_lapack_libs']:
linkLibs.extend(env['blas_lapack_libs'])
linkSharedLibs.extend(env['blas_lapack_libs'])

if not env['build_with_f2c']:
linkLibs.extend(env['FORTRANSYSLIBS'])
linkSharedLibs.append(env['FORTRANSYSLIBS'])

# Store the list of needed static link libraries in the environment
env['cantera_libs'] = linkLibs
env['cantera_shared_libs'] = linkSharedLibs
Expand Down
18 changes: 0 additions & 18 deletions doc/sphinx/compiling.rst
Original file line number Diff line number Diff line change
Expand Up @@ -390,24 +390,6 @@ Building Documentation

scons build doxygen_docs=y sphinx_docs=y

MinGW Compilation problems
--------------------------

* If you get a compiler error while compiling some of the "f2c" code, then your
version of MinGW has a problem with the order of its internal include paths,
such that it sees the GCC float.h before its own special version. To fix this
problem edit the GCC float.h located at (roughly)::

c:\MinGW\lib\gcc\mingw32\4.6.1\include\float.h

and add the following just before the end (before the final #endif)

.. code-block:: c++

#ifndef _MINGW_FLOAT_H_
#include_next <float.h>
#endif

.. _sec-dependencies:

Software used by Cantera
Expand Down
7 changes: 0 additions & 7 deletions doc/sphinx/scons-options.txt
Original file line number Diff line number Diff line change
Expand Up @@ -272,13 +272,6 @@ running 'scons build'. The format of this file is:
Location of the Boost header files.
- default: ''

* build_with_f2c: [ yes | no ]
For external procedures written in Fortran 77, both the original F77
source code and C source code generated by the 'f2c' program are
included. Set this to "n" if you want to build Cantera using the F77
sources in the ext directory.
- default: 'yes'

* F77: [ string ]
Compiler used to build the external Fortran 77 procedures from the
Fortran source code.
Expand Down
55 changes: 5 additions & 50 deletions ext/SConscript
Original file line number Diff line number Diff line change
Expand Up @@ -13,27 +13,6 @@ def prep_default(env):
return localenv


def prep_fortran(env):
localenv = prep_default(env)
localenv.Prepend(CPPPATH='#include/cantera/base') # for config.h
return localenv


def prep_f2c(env):
localenv = prep_default(env)

localenv.Prepend(CPPPATH=Dir('#ext/f2c_libs'))
if not localenv['HAS_TIMES_H']:
localenv.Append(CPPDEFINES=['USE_CLOCK'])
if not localenv['HAS_UNISTD_H']:
localenv.Append(CPPDEFINES=['MSDOS'])
if env['VERBOSE']:
print "INFO 2: prep_f2c: adding MSDOS to CPPDEFINES"
print "INFO 2: CPPDEFINES ", localenv['CPPDEFINES']

return localenv


def prep_gtest(env):
localenv = prep_default(env)
localenv.Prepend(CPPPATH=[Dir('#ext/googletest'),
Expand All @@ -52,33 +31,6 @@ def prep_fmt(env):
libs = [('libexecstream', ['cpp'], prep_default),
('fmt/fmt', ['cc'], prep_fmt)]

if env['build_with_f2c']:
libs.append(('f2c_math', ['cpp','c'], prep_f2c))

# Create arith.h using the arithchk program
if not os.path.exists('arith.h'):
arithenv = prep_f2c(env)

# TODO: make link flag more general
arithenv.Append(CPPFLAGS='-DNO_FPINIT')
arithenv.Program('f2c_libs/arithchk/arithchk', source='f2c_libs/arithchk/arithchk.c',
LIBS=env['LIBM'])
arithenv.Command('#ext/f2c_libs/arith.h', 'f2c_libs/arithchk/arithchk$PROGSUFFIX',
'$SOURCE > $TARGET')

libs.append(('f2c_libs', 'c', prep_f2c))

if env['BUILD_BLAS_LAPACK']:
libs.append(('f2c_blas', ['c'], prep_f2c))
libs.append(('f2c_lapack', ['c'], prep_f2c))

else:
libs.append(('math', ['cpp','c','f'], prep_fortran))

if env['BUILD_BLAS_LAPACK']:
libs.append(('blas', ['f'], prep_default))
libs.append(('lapack', ['f'], prep_default))

for subdir, extensions, prepFunction in libs:
localenv = prepFunction(env)
objects = localenv.SharedObject(mglob(localenv, subdir, *extensions))
Expand All @@ -92,7 +44,7 @@ if env['system_sundials'] == 'n':
sundials_configh = {}
if env['OS'] != 'Windows':
sundials_configh['SUNDIALS_USE_GENERIC_MATH'] = 1
if not env['BUILD_BLAS_LAPACK']:
if env['use_lapack']:
sundials_configh['SUNDIALS_BLAS_LAPACK'] = 1
localenv.AlwaysBuild(env.Command('#include/cantera/ext/sundials/sundials_config.h',
'sundials_config.h.in',
Expand All @@ -106,10 +58,13 @@ if env['system_sundials'] == 'n':
Copy('$TARGET', '$SOURCE')))

# Compile Sundials source files
exclude = ['_klu', '_superlumt']
if not env['use_lapack']:
exclude.append('_lapack')
for subdir in ('sundials', 'nvec_ser', 'cvodes', 'ida'):
libraryTargets.extend(localenv.SharedObject(
[f for f in mglob(localenv, 'sundials/src/'+subdir, 'c')
if '_klu' not in f.name and '_superlumt' not in f.name]))
if not any(pattern in f.name for pattern in exclude)]))

if not env['system_eigen']:
build(localenv.Command('#include/cantera/ext/Eigen', '#ext/eigen/Eigen',
Expand Down
4 changes: 1 addition & 3 deletions platform/posix/Cantera.mak.in
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,6 @@ CANTERA_FORTRAN_MODS=$(CANTERA_INSTALL_ROOT)/include/cantera

CANTERA_FORTRAN_SYSLIBS=@mak_fort_threadflags@ -lstdc++

CANTERA_SYSLIBS=@mak_syslibs@

###############################################################################
# BOOST
###############################################################################
Expand Down Expand Up @@ -79,7 +77,7 @@ CANTERA_DEFINES = -DCANTERA_VERSION=@cantera_version@

CANTERA_LIBS=$(CANTERA_CORE_LIBS) \
$(CANTERA_EXTRA_LIBDIRS) $(CANTERA_SUNDIALS_LIBS) \
$(CANTERA_BLAS_LAPACK_LIBS) $(CANTERA_SYSLIBS)
$(CANTERA_BLAS_LAPACK_LIBS)

CANTERA_TOTAL_LIBS=$(CANTERA_LIBS)

Expand Down
6 changes: 0 additions & 6 deletions platform/posix/SConscript
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,6 @@ if '-pthread' in localenv['thread_flags']:
else:
localenv['mak_fort_threadflags'] = ''

if not localenv['build_with_f2c']:
localenv['mak_syslibs'] = ' '.join('-l%s' % s for s in localenv['FORTRANSYSLIBS'])
pc_libs.extend(localenv['FORTRANSYSLIBS'])
else:
localenv['mak_syslibs'] = ''

mak = build(localenv.SubstFile('Cantera.mak', 'Cantera.mak.in'))
install('$inst_incdir', mak)

Expand Down
7 changes: 1 addition & 6 deletions src/SConscript
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,11 @@ def baseSetup(env, subdir, extensions):
env.Append(CPPDEFINES={'CANTERA_DATA': escaped_datadir})
return defaultSetup(env, subdir, extensions)

def equilSetup(env, subdir, extensions):
env.Append(CPPPATH=['#ext/f2c_libs'])
return defaultSetup(env, subdir, extensions)

# (subdir, (file extensions), (extra setup(env)))
libs = [('base', ['cpp'], baseSetup),
('thermo', ['cpp'], defaultSetup),
('tpx', ['cpp'], defaultSetup),
('equil', ['cpp','c'], equilSetup),
('equil', ['cpp','c'], defaultSetup),
('numerics', ['cpp'], defaultSetup),
('kinetics', ['cpp'], defaultSetup),
('transport', ['cpp'], defaultSetup),
Expand Down Expand Up @@ -47,7 +43,6 @@ env['cantera_staticlib'] = lib

# Windows and OS X require shared libraries at link time
if localenv['OS'] in ('Darwin', 'Windows', 'Cygwin'):
localenv.Append(LIBS=localenv['FORTRANSYSLIBS'])
if (localenv['system_sundials'] == 'y'):
localenv.Append(LIBS=localenv['sundials_libs'],
LIBPATH=localenv['sundials_libdir'])
Expand Down

0 comments on commit df43a47

Please sign in to comment.