Source code for BuildOSMPS
import sys
#from MPSPyLib import write_makefile, BuildMPSFortLib, CleanMPSFortLib
#from MPSPyLib import InstallMPSFortLib, InstallMPSCLIUtility
[docs]def main():
"""
Install the MPSFortLib
**Arguments**
--clean : run make clean, executed first. If clean is the only argument,
nothing is build (not even the default ubuntu)
--option=option:value : a sequence to override default `option` with `value`. Accepts the following structure:
PY:/path/to/python ... python override
FC:/path/to/fortran ... fortran override
OFLAGS:-O3 ... optimization flags
OPENMP:-fopenmp ... option for OpenMP
BLAS_FLAG:-lblas ... linker flag for BLAS
LAPACK_FLAG:-llapack ... linker flag for LAPACK
ARPACK_FLAG:-larpack ... linker flag for ARPACK
INCLUDES:-I/path/to/include ... additional include directory flags
LIBFLAGS:-framework accelerate ... additional library flags
Default option may be overridden with `--option=setting:value` (e.g.)
--option=PY:/path/to/python \
--option=FC:/path/to/fortran \
...
--tests : specify if Fortran test should be compiled. Tests are compiled
for values ``T``, ``True``, and ``true``. Otherwise not tests
are compiled.
--prefix=path : specify path for local installation. Default is set to
`/usr/local/bin` for global installation
Any argument in the default according to options can be overwritten. Keys
are FC (fortran compiler), PY (python), OFLAGS (flags for compiler, e.g.,
optimization), OPENMP (linking openmp if used),
BLAS_FLAG (linking to BLAS libary), LAPACK_FLAG (linking to LAPACK library),
ARPACK_FLAG (linking to ARPACK, only necessary for iMPS), LIBFLAGS
(linking to other libraries), HDF5_FLAG (linking to the HDF5 library,
if not present not used).
...
"""
# Set default command line arguments and overwrite if necessary
path = '/usr/local/bin'
tests = False
manual = {}
options = []
defaults = {
'PY': 'python',
'FC': 'gfortran',
'OFLAGS': '-O3',
'OPENMP': '',
'BLAS_FLAG': '-lblas',
'LAPACK_FLAG': '-llapack',
'ARPACK_FLAG': '-larpack',
'HDF5_FLAG' : '',
'INCFLAGS': '',
'LIBFLAGS': ''
}
for elem in sys.argv[1:]:
if(elem == '--clean'):
pass
elif(elem.split('=')[0] == '--option'):
options.append(elem.split('=')[1])
elif(elem.split('=')[0] == '--prefix'):
path = elem.split('=')[1]
elif(elem.split('=')[0] == '--tests'):
tests = (elem.split('=')[1] in ['T', 'True', 'true'])
else:
key, val = elem.split('=')
manual[key] = val
# If requested, clean first
if('--clean' in sys.argv):
CleanMPSFortLib()
if(len(sys.argv) == 2):
return
# Retrieve default values
settings = default_settings(defaults, options)
# Overwrite default value with manually passed arguments
for key in manual.keys():
settings[key] = manual[key]
# Write makefile
parallel = write_makefile(settings)
status = BuildMPSFortLib(parallel, tests)
if(sum(status) != 0):
# Error occured
sys.exit(1)
status = InstallMPSFortLib(path, parallel)
if(status != 0): sys.exit(1)
status = InstallMPSCLIUtility(path)
if(status != 0): sys.exit(1)
return
[docs]def default_settings(defaults, options):
"""
Return the default settings overridden by values specified in options.
**Arguments**
defaults : dictionary list
options : list, str
...
"""
if(options == ''):
return defaults
for option in options:
if option.split(':')[0] == 'PY': defaults['PY'] = option.split(':')[1]
if option.split(':')[0] == 'FC': defaults['FC'] = option.split(':')[1]
if option.split(':')[0] == 'OFLAGS': defaults['OFLAGS'] = option.split(':')[1]
if option.split(':')[0] == 'OPENMP': defaults['OPENMP'] = option.split(':')[1]
if option.split(':')[0] == 'BLAS_FLAG': defaults['BLAS_FLAG'] = option.split(':')[1]
if option.split(':')[0] == 'LAPACK_FLAG': defaults['LAPACK_FLAG'] = option.split(':')[1]
if option.split(':')[0] == 'ARPACK_FLAG': defaults['ARPACK_FLAG'] = option.split(':')[1]
if option.split(':')[0] == 'HDF5_FLAG': defaults['HDF5_FLAG'] = option.split(':')[1]
if option.split(':')[0] == 'INCFLAGS': defaults['INCFLAGS'] = option.split(':')[1]
if option.split(':')[0] == 'LIBFLAGS': defaults['LIBFLAGS'] = option.split(':')[1]
return defaults
if(__name__ == '__main__'):
main()