From 01c8c434f7e2a825483a0be69c28672b830ab4f8 Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Tue, 14 Jan 2014 19:03:41 +0000 Subject: [PATCH] finished work on the new installation scheme (if no bugs are found ;)) --- DAMASK_env.sh | 18 +-- code/Makefile | 3 + configure | 26 +-- installation/compile_CoreModule.py | 148 ++++++++---------- .../apply_DAMASK_modifications | 16 +- installation/options | 23 +-- lib/damask/environment.py | 29 +--- 7 files changed, 116 insertions(+), 147 deletions(-) diff --git a/DAMASK_env.sh b/DAMASK_env.sh index 1704e2356..570e77caa 100644 --- a/DAMASK_env.sh +++ b/DAMASK_env.sh @@ -12,18 +12,16 @@ source $DAMASK_ROOT/installation/options if [ "x$DAMASK_NUM_THREADS" != "x" ] then export DAMASK_NUM_THREADS=$DAMASK_NUM_THREADS fi -export FFTWROOT=${FFTWROOT} -LD_NEW=$FFTWROOT/lib -if [ "x$LAPACKROOT" != "x" ] - then export LAPACKROOT=$LAPACKROOT - LD_NEW=$LD_NEW:$LAPACKROOT/lib:$LAPACKROOT/lib64 +export FFTW_ROOT=$FFTW_ROOT +LD_NEW=$FFTW_ROOT/lib +if [ "x$LAPACK_ROOT" != "x" ] + then LD_NEW=$LD_NEW:$LAPACK_ROOT/lib:$LAPACK_ROOT/lib64 fi -if [ "x$ACMLROOT" != "x" ] - then export ACMLROOT=$ACMLROOT - LD_NEW=$LD_NEW:$ACMLROOT/ifort64_mp/lib:$ACMLROOT/ifort64/lib:$ACMLROOT/gfortran64_mp/lib:$ACMLROOT/gfortran64/lib +if [ "x$ACML_ROOT" != "x" ] + then LD_NEW=$LD_NEW:$ACML_ROOT/ifort64_mp/lib:$ACML_ROOT/ifort64/lib:$ACML_ROOT/gfortran64_mp/lib:$ACML_ROOT/gfortran64/lib fi -if [ "x$IMKLROOT" != "x" ] - then export IMKLROOT=${IMKLROOT} +if [ "x$IMKL_ROOT" != "x" ] + then LD_NEW=$LD_NEW:$IMKL_ROOT/lib/intel64 fi if [ "x$F90" != "x" ] diff --git a/code/Makefile b/code/Makefile index 4f69900be..0e9ca95b5 100644 --- a/code/Makefile +++ b/code/Makefile @@ -467,8 +467,11 @@ endif tidy: @rm -rf *.o @rm -rf *.mod + @rm -rf src* + clean: @rm -rf *.o @rm -rf *.mod @rm -rf *.exe + @rm -rf src* diff --git a/configure b/configure index 146588d99..f78263239 100755 --- a/configure +++ b/configure @@ -46,8 +46,8 @@ parser.add_option('--with-blas-lapack-dir', dest='blasdir', type='string', help='root directory of LAPACK [%default]') parser.add_option('--with-blas-type', dest='blastype', type='string', help='type of BLAS/LAPACK library [%default]') -parser.add_option('--with-spectral-options', dest='spectraloptions', type='string', - help='options for spectral solver [%default]') +parser.add_option('--with-spectral-options', dest='spectraloptions', type='string', action='extend', + help='options for spectral solver %default') compiler = os.getenv('F90') if compiler == None: compiler ={True:'ifort',False:'gfortran'}[\ @@ -55,9 +55,10 @@ if compiler == None: compiler ={True:'ifort',False:'gfortran'}[\ stdout=subprocess.PIPE, stderr=subprocess.PIPE) == 0] parser.set_defaults(compiler = compiler) parser.set_defaults(blastype = 'LAPACK') -parser.set_defaults(fftwdir = "/usr/local") -parser.set_defaults(blasdir = "/usr") -parser.set_defaults(marcdir = "/msc") +parser.set_defaults(fftwdir = '/usr/local') +parser.set_defaults(blasdir = '/usr') +parser.set_defaults(marcdir = '/msc') +parser.set_defaults(spectraloptions = []) (options,filenames) = parser.parse_args() @@ -73,13 +74,20 @@ with open('installation/options','r') as f: items = re.split('[= ]',line) if items[0] == 'F90': line = '%s=%s\n'%(items[0],options.compiler) - if items[0] == 'FFTWROOT': line = '%s=%s\n'%(items[0],options.fftwdir) - if items[0] == 'MSCROOT': line = '%s=%s\n'%(items[0],options.marcdir) - for type in blastypes: - if options.blastype == type and items[0] == '%sROOT'%type: + if items[0] == 'FFTW_ROOT': line = '%s=%s\n'%(items[0],options.fftwdir) + if items[0] == 'MSC_ROOT': line = '%s=%s\n'%(items[0],options.marcdir) + for blastype in blastypes: + if options.blastype == blastype and items[0] == '%sROOT_'%type: line = '%s=%s\n'%(items[0],options.blasdir) + for spectralOption in options.spectraloptions: + [key,value] = re.split('[= ]',spectralOption)[0:2] + if key == items[0]: + line = '%s=%s\n'%(items[0],value) + options.spectraloptions.remove(spectralOption) output.append(line) +for spectralOption in options.spectraloptions: + output.append(spectralOption+'\n') with open('installation/options','w') as f: for line in output: diff --git a/installation/compile_CoreModule.py b/installation/compile_CoreModule.py index 241f3642a..bce96f37d 100755 --- a/installation/compile_CoreModule.py +++ b/installation/compile_CoreModule.py @@ -1,102 +1,84 @@ #!/usr/bin/env python -# Makes postprocessing routines acessible from everywhere. +# compiles fortran code for Python -import os,sys,glob,string,subprocess +import os,sys,glob,string,subprocess,shlex from damask import Environment damaskEnv = Environment() baseDir = damaskEnv.relPath('installation/') codeDir = damaskEnv.relPath('code/') -try: - imklroot = damaskEnv.options['IMKLROOT'] -except: - imklroot = os.getenv('IMKLROOT') - if imklroot == None: imklroot == '' # env not set +options={} -try: - acmlroot = damaskEnv.options['ACMLROOT'] -except: - acmlroot = os.getenv('ACMLROOT') - if acmlroot == None: acmlroot == '' # env not set - -try: - lapackroot = damaskEnv.options['LAPACKROOT'] -except: - lapackroot = os.getenv('LAPACKROOT') - if lapackroot == None: lapackroot == '' # env not set - -try: - fftwroot = damaskEnv.options['FFTWROOT'] -except: - fftwroot = os.getenv('FFTWROOT') - if fftwroot == None: fftwroot == '' # env not set - -try: - compiler = damaskEnv.options['F90'] -except: - compiler = os.getenv('F90') - if compiler == None: compiler == '' # env not set +for option in ['IMKL_ROOT','ACML_ROOT','LAPACK_ROOT','FFTW_ROOT','F90']: + try: + value = damaskEnv.options[option] + except: + value = os.getenv(option) + if value is None: value = '' # env not set + options[option]=value compilers = ['ifort','gfortran'] -if compiler not in compilers: - parser.error('compiler switch "F90" has to be one out of: %s'%(', '.join(compilers))) +if options['F90'] not in compilers: + sys.exit('compiler "F90" (in installation/options or as Shell variable) has to be one out of: %s'%(', '.join(compilers))) -f2py_compiler = { - 'gfortran': 'gnu95 --f90flags="-fPIC -fno-range-check -xf95-cpp-input -std=f2008 -fall-intrinsics -DSpectral -fdefault-real-8 -fdefault-double-8 -DFLOAT=8 -DINT=4 -I${DAMASK_ROOT}/lib"', - 'ifort': 'intelem --f90flags="-fPIC -fpp -stand f08 -diag-disable 5268 -assume byterecl -DSpectral -real-size 64 -integer-size 32 -DFLOAT=8 -DINT=4 -I${DAMASK_ROOT}/lib"', - }[compiler] +compileCommand = { + 'gfortran': 'gnu95 --f90flags="-fPIC -fno-range-check -xf95-cpp-input -std=f2008 -fall-intrinsics'+\ + ' -DSpectral -fdefault-real-8 -fdefault-double-8 -DFLOAT=8 -DINT=4 -I%s/lib"'%damaskEnv.rootDir(), + 'ifort': 'intelem --f90flags="-fPIC -fpp -stand f08 -diag-disable 5268 -assume byterecl'+\ + ' -DSpectral -real-size 64 -integer-size 32 -DFLOAT=8 -DINT=4 -I%s/lib"'%damaskEnv.rootDir(), + }[options['F90']] - - -if imklroot != '' and compiler != 'gfortran': - lib_lapack = '-L%s/lib/intel64 -lmkl_intel_lp64 -lmkl_sequential -lmkl_core -liomp5 -lpthread -lm'%(imklroot) -elif acmlroot != '': - lib_lapack = '-L%s/%s64/lib -lacml'%(acmlroot,compiler) +# see http://cens.ioc.ee/pipermail/f2py-users/2003-December/000621.html +if options['IMKL_ROOT'] != '' and options['F90'] != 'gfortran': + lib_lapack = '-L%s/lib/intel64 -I%s/include -lmkl_intel_lp64 -lmkl_sequential -lmkl_core -lm'%(options['IMKL_ROOT'],options['IMKL_ROOT']) +elif options['ACML_ROOT'] != '': + lib_lapack = '-L%s/%s64/lib -lacml'%(options['ACML_ROOT'],options['F90']) elif lapackroot != '': - lib_lapack = '-L%s -llapack'%(lapack) # see http://cens.ioc.ee/pipermail/f2py-users/2003-December/000621.html + lib_lapack = '-L%s -llapack'%(options['LAPACK_ROOT']) -execute = { \ - 'coreModule' : [ - # The following command is used to compile the fortran files and make the functions defined - # in damask.core.pyf available for python in the module core.so - # It uses the fortran wrapper f2py that is included in the numpy package to construct the - # module core.so out of the fortran code in the f90 files - # For the generation of the pyf file use the following lines: - ########################################################################### - #'f2py -h damask.core.pyf' +\ - #' --overwrite-signature --no-lower prec.f90 DAMASK_spectral_interface.f90 math.f90 mesh.f90', - ########################################################################### - 'rm `readlink -f %s`' %(os.path.join(damaskEnv.relPath('lib/damask'),'core.so')), # do this using system remove - 'f2py damask.core.pyf' +\ - ' --build-dir ./' +\ - ' -c --no-lower --fcompiler=%s'%(f2py_compiler) +\ - ' %s'%'prec.f90'+\ - ' %s'%'DAMASK_spectral_interface.f90'+\ - ' %s'%'IO.f90'+\ - ' %s'%'libs.f90'+\ - ' %s'%'numerics.f90'+\ - ' %s'%'debug.f90'+\ - ' %s'%'math.f90'+\ - ' %s'%'FEsolving.f90'+\ - ' %s'%'mesh.f90'+\ - ' %s'%'core_quit.f90'+\ - ' -L%s/lib -lfftw3'%(fftwroot)+\ - ' %s'%lib_lapack, - 'mv %s `readlink -f %s`' %(os.path.join(codeDir,'core.so'),os.path.join(damaskEnv.relPath('lib/damask'),'core.so')), # do this using system remove - ] - } +os.chdir(codeDir) # needed for compilation with gfortran and f2py +try: + os.remove(os.path.join(damaskEnv.relPath('lib/damask'),'core.so')) +except OSError, e: ## if failed, report it back to the user ## + print ("Error when deleting: %s - %s." % (e.filename,e.strerror)) -os.chdir(codeDir) # needed for compilation with gfortran and f2py -for tasks in execute: - for cmd in execute[tasks]: - try: - print 'executing...:',cmd - os.system(cmd) - except: - print 'failed..!' - pass + +# The following command is used to compile the fortran files and make the functions defined +# in damask.core.pyf available for python in the module core.so +# It uses the fortran wrapper f2py that is included in the numpy package to construct the +# module core.so out of the fortran code in the f90 files +# For the generation of the pyf file use the following lines: +########################################################################### +#'f2py -h damask.core.pyf' +\ +#' --overwrite-signature --no-lower prec.f90 DAMASK_spectral_interface.f90 math.f90 mesh.f90,...' + ########################################################################### +cmd = 'f2py damask.core.pyf' +\ + ' --build-dir %s'%codeDir +\ + ' -c --no-lower --fcompiler=%s'%(compileCommand) +\ + ' prec.f90'+\ + ' DAMASK_spectral_interface.f90'+\ + ' IO.f90'+\ + ' libs.f90'+\ + ' numerics.f90'+\ + ' debug.f90'+\ + ' math.f90'+\ + ' FEsolving.f90'+\ + ' mesh.f90'+\ + ' core_quit.f90'+\ + ' -L%s/lib -lfftw3'%(options['FFTW_ROOT'])+\ + ' %s'%lib_lapack + +print('Executing: '+cmd) +try: + subprocess.call(shlex.split(cmd)) +except subprocess.CalledProcessError: + print('build failed') +except OSError: + print ('f2py not found') + +os.rename(os.path.join(codeDir,'core.so'), os.path.join(damaskEnv.relPath('lib/damask'),'core.so')) modules = glob.glob('*.mod') for module in modules: @@ -108,5 +90,3 @@ try: with open(damaskEnv.relPath('lib/damask/core.so')) as f: pass except IOError as e: print '*********\n* core.so not found, compilation of core modules was not successful\n*********' - sys.exit() -f.close diff --git a/installation/mods_MarcMentat/apply_DAMASK_modifications b/installation/mods_MarcMentat/apply_DAMASK_modifications index cf2f80e39..88be878e7 100755 --- a/installation/mods_MarcMentat/apply_DAMASK_modifications +++ b/installation/mods_MarcMentat/apply_DAMASK_modifications @@ -16,8 +16,8 @@ do done echo "MSC version: $VERSION" -if [ "x$MSCROOT" != "x" ] - then INSTALLDIR=$MSCROOT +if [ "x$MSC_ROOT" != "x" ] + then INSTALLDIR=$MSC_ROOT fi while [ ! -d "$INSTALLDIR" ] || [ -z "$INSTALLDIR" ] @@ -31,16 +31,16 @@ echo "MSC installation path: $INSTALLDIR" BLASDIR='' BLASTYPE='' -if [ "x$LAPACKROOT" != "x" ] - BLASDIR=$LAPACKROOT +if [ "x$LAPACK_ROOT" != "x" ] + BLASDIR=$LAPACK_ROOT BLASTYPE='LAPACK' fi -if [ "x$ACMLROOT" != "x" ] - BLASDIR=$ACMLROOT +if [ "x$ACML_ROOT" != "x" ] + BLASDIR=$ACML_ROOT BLASTYPE='ACML' fi -if [ "x$IMKLROOT" != "x" ] - BLASDIR=$IMKLROOT +if [ "x$IMKL_ROOT" != "x" ] + BLASDIR=$IMKL_ROOT BLASTYPE='IMKL' fi diff --git a/installation/options b/installation/options index 6c07254ed..0b246808b 100644 --- a/installation/options +++ b/installation/options @@ -1,17 +1,18 @@ # $Id: pathinfo 2176 2013-02-19 13:35:38Z MPIE\p.eisenlohr $ # possible options are -# IMKLROOT base installation directory of Intel Math Kernel Library -# ACMLROOT base installation directory of AMD Core Math Library -# LAPACKROOT base installation directory of (system) LAPACK Library -# MSC base installation directory of MSC.Marc/Mentat -# FFTWROOT base installation directory of Fastest Fourier Transform in the West library +# IMKL_ROOT base installation directory of Intel Math Kernel Library +# ACML_ROOT base installation directory of AMD Core Math Library +# LAPAC_KROOT base installation directory of (system) LAPACK Library +# MSC_ROOT base installation directory of MSC.Marc/Mentat +# FFTW_ROOT base installation directory of Fastest Fourier Transform in the West library # Do NOT add any trailing /lib/ to the end # of the base installation path---this will be done automatically -FFTWROOT=/usr/local -LAPACKROOT=/usr -ACMLROOT= -IMKLROOT= -F90=gfortran -MSCROOT=/msc +FFTW_ROOT= +LAPACK_ROOT= +ACML_ROOT= +IMKL_ROOT= +MSC_ROOT= +F90= DAMASK_NUM_THREADS=2 + diff --git a/lib/damask/environment.py b/lib/damask/environment.py index f0a863105..27895b544 100644 --- a/lib/damask/environment.py +++ b/lib/damask/environment.py @@ -10,8 +10,8 @@ class Environment(): def __init__(self,rootRelation = '.'): self.rootRelation = rootRelation - self.pathInfo = {} - self.get_pathInfo() + self.options = {} + self.get_options() def relPath(self,relative = '.'): return os.path.join(self.rootDir(),relative) @@ -32,23 +32,6 @@ class Environment(): damask_bin = os.getenv('DAMASK_BIN') if damask_bin == '' or damask_bin == None: damask_bin = self.relPath('bin/') return damask_bin - - def get_pathInfo(self): - try: # check for user-defined pathinfo - file = open(self.relPath('lib/pathinfo')) - content = map(lambda string: string.strip(),file.readlines()) - file.close() - for line in content: - if not (line.startswith('#') or line == ''): - items = line.split() + ['',''] - if items[1] == '': # nothing specified - self.pathInfo[items[0].lower()] = '' - elif items[1].startswith(('/','$')): # absolute path specified ($shellVar is considered absolute) - self.pathInfo[items[0].lower()] = items[1] - else: # path relative to DAMASK_ROOT/lib - self.pathInfo[items[0].lower()] = os.path.normpath(os.path.join(self.relPath('lib/'),items[1])) - except: - pass def get_options(self): try: # check for user-defined pathinfo @@ -58,12 +41,8 @@ class Environment(): for line in content: if not (line.startswith('#') or line == ''): items = line.split('=') + ['',''] - if items[1] == '': # nothing specified - self.pathInfo[items[0].lower()] = '' - elif items[1].startswith(('/','$')): # absolute path specified ($shellVar is considered absolute) - self.pathInfo[items[0].lower()] = items[1] - else: # path relative to DAMASK_ROOT/lib - self.pathInfo[items[0].lower()] = os.path.normpath(os.path.join(self.relPath('lib/'),items[1])) + if items[1] != '': # nothing specified + self.options[items[0].upper()] = items[1] except: pass