2014-01-11 18:16:30 +05:30
|
|
|
#!/usr/bin/env python
|
2014-01-24 18:00:27 +05:30
|
|
|
import os,re,sys,string,subprocess,shutil
|
2014-01-14 02:47:28 +05:30
|
|
|
|
|
|
|
from optparse import OptionParser, Option
|
|
|
|
|
|
|
|
# -----------------------------
|
|
|
|
class extendableOption(Option):
|
|
|
|
# -----------------------------
|
|
|
|
# used for definition of new option parser action 'extend', which enables to take multiple option arguments
|
|
|
|
# taken from online tutorial http://docs.python.org/library/optparse.html
|
|
|
|
|
|
|
|
ACTIONS = Option.ACTIONS + ("extend",)
|
|
|
|
STORE_ACTIONS = Option.STORE_ACTIONS + ("extend",)
|
|
|
|
TYPED_ACTIONS = Option.TYPED_ACTIONS + ("extend",)
|
|
|
|
ALWAYS_TYPED_ACTIONS = Option.ALWAYS_TYPED_ACTIONS + ("extend",)
|
|
|
|
|
|
|
|
def take_action(self, action, dest, opt, value, values, parser):
|
|
|
|
if action == "extend":
|
|
|
|
lvalue = value.split(",")
|
|
|
|
values.ensure_value(dest, []).extend(lvalue)
|
|
|
|
else:
|
|
|
|
Option.take_action(self, action, dest, opt, value, values, parser)
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-08-21 03:43:38 +05:30
|
|
|
# -----------------------------
|
|
|
|
def filePresent(paths,files,warning=False):
|
|
|
|
|
|
|
|
for path in paths:
|
|
|
|
for file in files:
|
|
|
|
if os.path.isfile(os.path.join(path,file)): return True
|
|
|
|
|
|
|
|
if warning: print "Warning: %s not found in %s"%(','.join(files),','.join(paths))
|
|
|
|
|
|
|
|
return False
|
|
|
|
|
|
|
|
|
2014-01-11 19:58:07 +05:30
|
|
|
########################################################
|
|
|
|
# MAIN
|
|
|
|
########################################################
|
2014-01-11 18:16:30 +05:30
|
|
|
|
2014-01-11 19:58:07 +05:30
|
|
|
parser = OptionParser(option_class=extendableOption, usage='%prog options', description = """
|
2014-01-24 18:00:27 +05:30
|
|
|
Configures the compilation and installation of DAMASK
|
2014-01-11 18:16:30 +05:30
|
|
|
|
2014-01-11 19:58:07 +05:30
|
|
|
""" + string.replace('$Id$','\n','\\n')
|
|
|
|
)
|
2014-01-11 18:16:30 +05:30
|
|
|
|
2014-01-24 18:00:27 +05:30
|
|
|
#--- determine default compiler ----------------------------------------------------------------------
|
|
|
|
compiler = os.getenv('F90')
|
2014-08-21 03:43:38 +05:30
|
|
|
if compiler == None:
|
|
|
|
compiler = 'ifort' if subprocess.call(['which', 'ifort'], stdout=subprocess.PIPE, stderr=subprocess.PIPE) == 0 \
|
|
|
|
else 'gfortran'
|
2014-01-11 19:58:07 +05:30
|
|
|
|
2014-01-24 18:00:27 +05:30
|
|
|
#--- default option values --------------------------------------------------------------------------
|
2015-11-10 21:32:20 +05:30
|
|
|
BLAS_order = ['IMKL','ACML','LAPACK','OPENBLAS']
|
2014-02-10 21:00:18 +05:30
|
|
|
|
2014-02-28 13:17:11 +05:30
|
|
|
defaults={'DAMASK_BIN':'depending on access rights',
|
|
|
|
'F90':compiler,
|
2014-04-01 18:12:19 +05:30
|
|
|
'FFTW_ROOT':'/usr',
|
2014-02-10 21:46:41 +05:30
|
|
|
'MSC_ROOT' :'/msc',
|
|
|
|
'DAMASK_NUM_THREADS':4,
|
|
|
|
'blasType':'LAPACK',
|
2015-11-10 21:32:20 +05:30
|
|
|
'blasRoot':{'LAPACK' :'/usr',
|
|
|
|
'ACML' :'/opt/acml6.1.0',
|
|
|
|
'IMKL' : os.getenv('MKLROOT') if os.getenv('MKLROOT') else '/opt/intel/composerxe/mkl',
|
|
|
|
'OPENBLAS' :'/usr',
|
|
|
|
},
|
|
|
|
'spectralOptions':{},
|
|
|
|
}
|
2014-01-24 18:00:27 +05:30
|
|
|
|
2014-02-28 13:17:11 +05:30
|
|
|
|
|
|
|
|
2014-01-24 18:00:27 +05:30
|
|
|
#--- if local config file exists, read, otherwise assume global config file ------------------------
|
2014-08-21 03:43:38 +05:30
|
|
|
configFile = os.path.join(os.getenv('HOME'),'.damask/damask.conf') \
|
|
|
|
if os.path.isfile(os.path.join(os.getenv('HOME'),'.damask/damask.conf')) \
|
|
|
|
else '/etc/damask.conf'
|
2014-01-24 18:00:27 +05:30
|
|
|
|
|
|
|
#--- set default values according to read in values ------------------------------------------------
|
|
|
|
try:
|
|
|
|
with open(configFile,'r') as f:
|
2014-08-21 03:43:38 +05:30
|
|
|
print('\n<<<<< reading default values from %s\n'%configFile)
|
2014-01-24 18:00:27 +05:30
|
|
|
for line in f:
|
2014-08-27 20:49:04 +05:30
|
|
|
line = line.strip()
|
|
|
|
if line.startswith('#') or line == '':
|
2014-01-24 18:00:27 +05:30
|
|
|
pass
|
2014-08-27 20:49:04 +05:30
|
|
|
|
|
|
|
[key,value] = (re.split('[= ]',line)+[None,None])[:2]
|
|
|
|
|
2014-02-10 21:00:18 +05:30
|
|
|
if key == 'DAMASK_NUM_THREADS':
|
|
|
|
defaults['DAMASK_NUM_THREADS'] = int(value)
|
2014-02-28 13:17:11 +05:30
|
|
|
if key == 'DAMASK_BIN':
|
|
|
|
defaults['DAMASK_BIN'] = value
|
2015-04-08 23:34:01 +05:30
|
|
|
if key in ['F90','FFTW_ROOT','MSC_ROOT','spectralOptions']:
|
2014-08-27 20:49:04 +05:30
|
|
|
defaults[key] = value
|
2014-02-10 21:00:18 +05:30
|
|
|
for theKey in reversed(BLAS_order):
|
2014-08-27 20:49:04 +05:30
|
|
|
if key == theKey+'_ROOT' and value != None and value != '':
|
2014-02-28 13:17:11 +05:30
|
|
|
defaults['blasType'] = theKey
|
|
|
|
defaults['blasRoot'][theKey] = value
|
2014-01-24 18:00:27 +05:30
|
|
|
except IOError:
|
|
|
|
pass
|
|
|
|
|
2014-02-28 13:17:11 +05:30
|
|
|
parser.add_option('--prefix', dest='prefix', type='string', metavar='string',
|
|
|
|
help='location of (links to) DAMASK executables [%default]')
|
2014-03-15 18:39:53 +05:30
|
|
|
parser.add_option('--with-FC','--with-fc',
|
|
|
|
dest='compiler', type='string', metavar='string',
|
2014-01-14 19:42:35 +05:30
|
|
|
help='F90 compiler [%default]')
|
2014-03-15 18:39:53 +05:30
|
|
|
parser.add_option('--with-FFTW-dir','--with-fftw-dir',
|
|
|
|
dest='fftwRoot', type='string', metavar='string',
|
2014-01-14 19:42:35 +05:30
|
|
|
help='root directory of FFTW [%default]')
|
2014-03-15 18:39:53 +05:30
|
|
|
parser.add_option('--with-MSC-dir','--with-msc-dir',
|
|
|
|
dest='mscRoot', type='string', metavar='string',
|
2014-01-28 15:19:04 +05:30
|
|
|
help='root directory of MSC.Marc/Mentat [%default]')
|
2014-03-15 18:39:53 +05:30
|
|
|
parser.add_option('--with-OMP-threads','--with-omp-threads',
|
|
|
|
dest='threads', type='int', metavar='int',
|
2014-01-24 18:00:27 +05:30
|
|
|
help='number of openMP threads [%default]')
|
2014-03-15 18:39:53 +05:30
|
|
|
parser.add_option('--with-BLAS-type','--with-blas-type',
|
|
|
|
dest='blasType', type='string', metavar='string',
|
2015-11-10 21:32:20 +05:30
|
|
|
help='type of BLAS/LAPACK library [%default] {{{}}}'.format(','.join(BLAS_order)))
|
2014-03-15 18:39:53 +05:30
|
|
|
parser.add_option('--with-BLAS-dir','--with-blas-dir',
|
|
|
|
dest='blasRoot', type='string', metavar='string',
|
2014-01-24 18:00:27 +05:30
|
|
|
help='root directory of BLAS/LAPACK library [%default]')
|
2014-02-10 21:46:41 +05:30
|
|
|
parser.add_option('--with-spectral-options', dest='spectraloptions', type='string', action='extend', metavar='<string LIST>',
|
2014-01-24 18:00:27 +05:30
|
|
|
help='options for compilation of spectral solver')
|
|
|
|
|
2014-02-28 13:17:11 +05:30
|
|
|
parser.set_defaults(prefix = defaults['DAMASK_BIN'])
|
2014-01-24 18:00:27 +05:30
|
|
|
parser.set_defaults(compiler = defaults['F90'])
|
|
|
|
parser.set_defaults(fftwRoot = defaults['FFTW_ROOT'])
|
2014-01-28 15:19:04 +05:30
|
|
|
parser.set_defaults(mscRoot = defaults['MSC_ROOT'])
|
2014-01-24 18:00:27 +05:30
|
|
|
parser.set_defaults(threads = defaults['DAMASK_NUM_THREADS'])
|
|
|
|
parser.set_defaults(blasType = defaults['blasType'])
|
|
|
|
|
|
|
|
#--- set default for blasRoot depending on current option (or default) for blasType --------------------
|
|
|
|
blasType = defaults['blasType'].upper()
|
|
|
|
for i, arg in enumerate(sys.argv):
|
2014-03-25 14:09:00 +05:30
|
|
|
if arg.lower().startswith('--with-blas-type'):
|
|
|
|
if arg.lower().endswith('--with-blas-type'):
|
2014-01-24 18:00:27 +05:30
|
|
|
blasType = sys.argv[i+1].upper()
|
|
|
|
else:
|
|
|
|
blasType = sys.argv[i][17:].upper()
|
2014-02-10 21:00:18 +05:30
|
|
|
if blasType not in BLAS_order:
|
2014-08-21 03:43:38 +05:30
|
|
|
blasType = defaults['blasType'].upper()
|
2014-01-11 19:58:07 +05:30
|
|
|
|
2014-03-25 14:09:00 +05:30
|
|
|
parser.set_defaults(blasRoot = defaults['blasRoot'][blasType])
|
2014-01-15 00:33:41 +05:30
|
|
|
parser.set_defaults(spectraloptions = [])
|
2014-01-14 19:42:35 +05:30
|
|
|
|
2014-01-11 19:58:07 +05:30
|
|
|
(options,filenames) = parser.parse_args()
|
2014-01-14 19:42:35 +05:30
|
|
|
|
2014-01-24 18:00:27 +05:30
|
|
|
#--- consistency checks --------------------------------------------------------------------------------
|
2014-08-21 03:43:38 +05:30
|
|
|
options.compiler = options.compiler.lower()
|
|
|
|
options.blasType = options.blasType.upper()
|
|
|
|
options.fftwRoot = os.path.normpath(options.fftwRoot)
|
|
|
|
options.mscRoot = os.path.normpath(options.mscRoot)
|
|
|
|
options.blasRoot = os.path.normpath(options.blasRoot)
|
|
|
|
|
|
|
|
locations = {
|
|
|
|
'FFTW' : [os.path.join(options.fftwRoot,'lib64'),os.path.join(options.fftwRoot,'lib')],
|
|
|
|
'LAPACK' : [os.path.join(options.blasRoot,'lib64'),os.path.join(options.blasRoot,'lib')],
|
2015-11-10 21:32:20 +05:30
|
|
|
'OPENBLAS': [os.path.join(options.blasRoot,'lib64'),os.path.join(options.blasRoot,'lib')],
|
2014-08-21 03:43:38 +05:30
|
|
|
'ACML' : [os.path.join(options.blasRoot,'%s64/lib'%options.compiler)],
|
|
|
|
'ACML_mp' : [os.path.join(options.blasRoot,'%s64_mp/lib'%options.compiler)],
|
|
|
|
'IMKL' : [os.path.join(options.blasRoot,'lib/intel64')],
|
|
|
|
}
|
|
|
|
|
|
|
|
libraries = {
|
|
|
|
'FFTW' : [
|
|
|
|
'libfftw3.so','libfftw3.a',
|
|
|
|
'libfftw3_threads.so','libfftw3_threads.a',
|
|
|
|
],
|
|
|
|
'LAPACK' : [
|
|
|
|
'liblapack.so','liblapack.a','liblapack.dylib',
|
|
|
|
],
|
2015-11-10 21:32:20 +05:30
|
|
|
'OPENBLAS' : [
|
|
|
|
'libopenblas.so','libopenblas.a','libopenblas.dylib',
|
|
|
|
],
|
2014-08-21 03:43:38 +05:30
|
|
|
'ACML' : [
|
|
|
|
'libacml.so','libacml.a',
|
|
|
|
],
|
|
|
|
'ACML_mp' : [
|
|
|
|
'libacml_mp.so','libacml_mp.a',
|
|
|
|
],
|
|
|
|
'IMKL' : [
|
|
|
|
'libmkl_core.so','libmkl_core.a',
|
|
|
|
'libmkl_sequential.so','libmkl_sequential.a',
|
|
|
|
'libmkl_intel_thread.so','libmkl_intel_thread.a',
|
|
|
|
'libmkl_intel_lp64.so','libmkl_intel_lp64.a',
|
|
|
|
'libmkl_gnu_thread.so','libmkl_gnu_thread.a',
|
|
|
|
'libmkl_gf_lp64.so','libmkl_gf_lp64.a',
|
|
|
|
],
|
|
|
|
|
|
|
|
}
|
2014-01-24 18:00:27 +05:30
|
|
|
if options.compiler not in ['ifort','gfortran']:
|
|
|
|
print('Error: Unknown compiler option: %s'%options.compiler)
|
|
|
|
sys.exit(1)
|
|
|
|
|
2014-08-21 03:43:38 +05:30
|
|
|
if not subprocess.call(['which', options.compiler], stdout=subprocess.PIPE, stderr=subprocess.PIPE) == 0:
|
2014-01-24 18:00:27 +05:30
|
|
|
print('Compiler Warning: executable %s not found!'%options.compiler)
|
|
|
|
|
2014-01-28 15:19:04 +05:30
|
|
|
if not os.path.isdir(options.mscRoot):
|
2014-08-21 03:43:38 +05:30
|
|
|
print('Warning: MSC root directory %s not found!'%options.mscRoot)
|
|
|
|
|
|
|
|
filePresent(locations['FFTW'],libraries['FFTW'],warning=True)
|
2014-01-24 18:00:27 +05:30
|
|
|
|
2015-11-10 21:32:20 +05:30
|
|
|
if options.blasType in ['LAPACK','OPENBLAS','IMKL']:
|
2014-08-21 03:43:38 +05:30
|
|
|
filePresent(locations[options.blasType],libraries[options.blasType],warning=True)
|
2014-01-24 18:00:27 +05:30
|
|
|
elif options.blasType == 'ACML':
|
2014-08-21 03:43:38 +05:30
|
|
|
filePresent(locations[options.blasType],libraries[options.blasType],warning=True)
|
|
|
|
filePresent(locations[options.blasType+'_mp'],libraries[options.blasType+'_mp'],warning=True)
|
2014-01-24 18:00:27 +05:30
|
|
|
else:
|
|
|
|
print('Error: Unknown BLAS/LAPACK library: %s'%options.blasType)
|
|
|
|
sys.exit(1)
|
|
|
|
|
2014-01-29 17:50:56 +05:30
|
|
|
#--- read config file if present to keep comments and order ---------------------------------------
|
2014-01-14 19:42:35 +05:30
|
|
|
output = []
|
2014-01-24 18:00:27 +05:30
|
|
|
try:
|
|
|
|
with open(configFile,'r') as f:
|
|
|
|
for line in f:
|
2015-04-21 08:04:42 +05:30
|
|
|
line = line.strip()
|
2014-01-24 18:00:27 +05:30
|
|
|
items = re.split('[= ]',line)
|
2014-01-14 19:42:35 +05:30
|
|
|
|
2015-04-21 08:04:42 +05:30
|
|
|
if (not line or items[0].startswith('#')):
|
2014-01-24 18:00:27 +05:30
|
|
|
pass
|
2014-02-28 13:17:11 +05:30
|
|
|
if items[0] == 'DAMASK_BIN':
|
2014-08-21 03:43:38 +05:30
|
|
|
line = '%s=%s'%(items[0],options.prefix)
|
2014-02-28 13:17:11 +05:30
|
|
|
options.prefix ='depending on access rights'
|
2014-01-24 18:00:27 +05:30
|
|
|
if items[0] == 'F90':
|
2014-08-21 03:43:38 +05:30
|
|
|
line = '%s=%s'%(items[0],options.compiler)
|
2014-01-24 18:00:27 +05:30
|
|
|
options.compiler =''
|
|
|
|
if items[0] == 'FFTW_ROOT':
|
2014-08-21 03:43:38 +05:30
|
|
|
line = '%s=%s'%(items[0],options.fftwRoot)
|
2014-01-24 18:00:27 +05:30
|
|
|
options.fftwRoot =''
|
2014-01-28 15:19:04 +05:30
|
|
|
if items[0] == 'MSC_ROOT':
|
2014-08-21 03:43:38 +05:30
|
|
|
line = '%s=%s'%(items[0],options.mscRoot)
|
2014-01-28 15:19:04 +05:30
|
|
|
options.mscRoot =''
|
2014-01-24 18:00:27 +05:30
|
|
|
if items[0] == 'DAMASK_NUM_THREADS':
|
2014-08-21 03:43:38 +05:30
|
|
|
line = '%s=%s'%(items[0],options.threads)
|
2014-01-24 18:00:27 +05:30
|
|
|
options.threads =''
|
|
|
|
for blasType in defaults['blasRoot'].keys():
|
|
|
|
if items[0] == '%s_ROOT'%blasType and items[0] == '%s_ROOT'%options.blasType:
|
2014-08-21 03:43:38 +05:30
|
|
|
line = '%s=%s'%(items[0],options.blasRoot)
|
2014-01-24 18:00:27 +05:30
|
|
|
options.blasType=''
|
2014-01-29 17:50:56 +05:30
|
|
|
elif items[0] == '#%s_ROOT'%blasType and items[0] == '#%s_ROOT'%options.blasType:
|
2014-08-21 03:43:38 +05:30
|
|
|
line = '%s=%s'%(items[0][1:],options.blasRoot)
|
2014-01-29 17:50:56 +05:30
|
|
|
options.blasType=''
|
2014-01-24 18:00:27 +05:30
|
|
|
elif items[0] == '%s_ROOT'%blasType: line = '#'+line
|
|
|
|
for spectralOption in options.spectraloptions:
|
|
|
|
[key,value] = re.split('[= ]',spectralOption)[0:2]
|
|
|
|
if key == items[0]:
|
2014-08-21 03:43:38 +05:30
|
|
|
line = '%s=%s'%(items[0],value)
|
2014-01-24 18:00:27 +05:30
|
|
|
options.spectraloptions.remove(spectralOption)
|
|
|
|
output.append(line)
|
|
|
|
except IOError:
|
|
|
|
pass
|
|
|
|
|
|
|
|
#--- write remaining options --------------------------------------------------------------------------
|
|
|
|
for opt, value in options.__dict__.items():
|
2014-08-21 03:43:38 +05:30
|
|
|
if opt == 'prefix' and value != 'depending on access rights':
|
|
|
|
output.append('DAMASK_BIN=%s'%value)
|
|
|
|
if opt == 'compiler' and value != '':
|
|
|
|
output.append('F90=%s'%value)
|
|
|
|
if opt == 'fftwRoot' and value != '':
|
|
|
|
output.append('FFTW_ROOT=%s'%value)
|
|
|
|
if opt == 'mscRoot' and value != '':
|
|
|
|
output.append('MSC_ROOT=%s'%value)
|
|
|
|
if opt == 'threads' and value != '':
|
|
|
|
output.append('DAMASK_NUM_THREADS=%s'%value)
|
|
|
|
if opt == 'blasType' and value != '':
|
|
|
|
output.append('%s_ROOT=%s'%(options.blasType,options.blasRoot))
|
2014-01-24 18:00:27 +05:30
|
|
|
|
2014-01-15 00:33:41 +05:30
|
|
|
for spectralOption in options.spectraloptions:
|
2014-08-21 03:43:38 +05:30
|
|
|
output.append(spectralOption)
|
2014-01-14 19:42:35 +05:30
|
|
|
|
2014-02-28 13:17:11 +05:30
|
|
|
#--- decide where do save the data -------------------------------------------------------------------
|
2014-08-21 03:43:38 +05:30
|
|
|
configDir = '/etc' if os.access('/etc/', os.W_OK) \
|
|
|
|
else os.path.join(os.getenv('HOME'),'.damask') # use system-wide config if possible
|
2014-02-28 13:17:11 +05:30
|
|
|
configFileNew = os.path.join(configDir,'damask.conf')
|
2014-01-24 18:00:27 +05:30
|
|
|
|
2014-03-02 21:12:05 +05:30
|
|
|
if not os.path.isdir(configDir):
|
|
|
|
os.mkdir(configDir)
|
|
|
|
|
2014-08-21 03:43:38 +05:30
|
|
|
print('\n>>>>> writing values to %s\n'%configFileNew)
|
2014-01-24 18:00:27 +05:30
|
|
|
with open(configFileNew,'w') as f:
|
2014-01-14 19:42:35 +05:30
|
|
|
for line in output:
|
2014-08-21 03:43:38 +05:30
|
|
|
print(line)
|
|
|
|
f.write(line+'\n')
|