def prepare(self, onlymod=None): """ Prepare a set of environment parameters based on name/version of toolkit - load modules for toolkit and dependencies - generate extra variables and set them in the environment onlymod: Boolean/string to indicate if the toolkit should only load the enviornment with module (True) or also set all other variables (False) like compiler CC etc (If string: comma separated list of variables that will be ignored). """ if not self._toolkitExists(): self.log.error("No module found for toolkit name '%s' (%s)" % (self.name, self.version)) if self.name == 'dummy': if self.version == 'dummy': self.log.info('Toolkit: dummy mode') else: self.log.info('Toolkit: dummy mode, but loading dependencies') modules = Modules() modules.addModule(self.dependencies) modules.load() return ## Load the toolkit and dependencies modules modules = Modules() modules.addModule([(self.name, self.version)]) modules.addModule(self.dependencies) modules.load() ## Determine direct toolkit dependencies, so we can prepare for them self.toolkit_deps = modules.dependencies_for(self.name, self.version, depth=0) self.log.debug('List of direct toolkit dependencies: %s' % self.toolkit_deps) ## Generate the variables to be set self._generate_variables() ## set the variables if not (onlymod == True): self.log.debug("Variables being set: onlymod=%s" % onlymod) ## add LDFLAGS and CPPFLAGS from dependencies to self.vars self._addDependencyVariables() self._setVariables(onlymod) else: self.log.debug("No variables set: onlymod=%s" % onlymod)
def postproc(self): """ The mkl directory structure has thoroughly changed as from version 10.3. Hence post processing is quite different in both situations """ if LooseVersion(self.version()) >= LooseVersion('10.3'): #Add convenient wrapper libs #- form imkl 10.3 if self.getcfg('m32'): self.log.error("32-bit not supported yet for IMKL v%s (>=10.3)" % self.version()) extra = { 'libmkl.so': 'GROUP (-lmkl_intel_lp64 -lmkl_intel_thread -lmkl_core)', 'libmkl_em64t.a': 'GROUP (libmkl_intel_lp64.a libmkl_intel_thread.a libmkl_core.a)', 'libmkl_solver.a': 'GROUP (libmkl_solver_lp64.a)', 'libmkl_scalapack.a': 'GROUP (libmkl_scalapack_lp64.a)', 'libmkl_lapack.a': 'GROUP (libmkl_intel_lp64.a libmkl_intel_thread.a libmkl_core.a)', 'libmkl_cdft.a': 'GROUP (libmkl_cdft_core.a)' } for fil, txt in extra.items(): dest = os.path.join(self.installdir, 'mkl/lib/intel64', fil) if not os.path.exists(dest): try: f = open(dest, 'w') f.write(txt) f.close() self.log.info("File %s written" % dest) except: self.log.exception("Can't write file %s" % (dest)) # build the mkl interfaces (pic and no-pic) # load the dependencies m = Modules() m.addModule(self.cfg.dependencies()) m.load() if not self.getcfg('interfaces'): return # build the interfaces #- blas95 and lapack95 need more work, ignore for now #lis1=['blas95','fftw2xc','fftw2xf','lapack95'] # blas95 and lapack also need include/.mod to be processed lis1 = ['fftw2xc', 'fftw2xf'] lis2 = ['fftw3xc', 'fftw3xf'] lis3 = ['fftw2x_cdft', 'fftw3x_cdft'] interfacedir = os.path.join(self.installdir, 'mkl/interfaces') try: os.chdir(interfacedir) self.log.info("Changed to interfaces directory %s" % interfacedir) except: self.log.exception("Can't change to interfaces directory %s" % interfacedir) # compiler defaults to icc, but we could be using gcc to create gimkl. makeopts = '' if self.toolkit().comp_family() == toolkit.GCC: makeopts += 'compiler=gnu ' for i in lis1 + lis2 + lis3: if i in lis1: # use INSTALL_DIR and CFLAGS and COPTS cmd = "make -f makefile libintel64" if i in lis2: # use install_to and CFLAGS cmd = "make -f makefile libintel64 install_to=$INSTALL_DIR" if i in lis3: # use INSTALL_DIR and SPEC_OPT extramakeopts = '' if self.toolkit().mpi_type() == toolkit.MPICH2: extramakeopts += 'mpi=mpich2' cmd = "make -f makefile libintel64 %s" % extramakeopts for opt in ['', '-fPIC']: try: tmpbuild = tempfile.mkdtemp() self.log.debug("Created temporary directory %s" % tmpbuild) except: self.log.exception("Creating temporary directory failed") # always set INSTALL_DIR, SPEC_OPT, COPTS and CFLAGS env.set('INSTALL_DIR', tmpbuild) env.set('SPEC_OPT', opt) env.set('COPTS', opt) env.set('CFLAGS', opt) try: intdir = os.path.join(interfacedir, i) os.chdir(intdir) self.log.info("Changed to interface %s directory %s" % (i, intdir)) except: self.log.exception("Can't change to interface %s directory %s" % (i, intdir)) if not run_cmd(cmd, log_all=True, simple=True): self.log.error("Building %s (opt: %s) failed" % (i, opt)) for fil in os.listdir(tmpbuild): if opt == '-fPIC': # add _pic to filename ff = fil.split('.') newfil = '.'.join(ff[:-1]) + '_pic.' + ff[-1] else: newfil = fil dest = os.path.join(self.installdir, 'mkl/lib/intel64', newfil) try: src = os.path.join(tmpbuild, fil) if os.path.isfile(src): shutil.move(src, dest) self.log.info("Moved %s to %s" % (src, dest)) except: self.log.exception("Failed to move %s to %s" % (src, dest)) try: shutil.rmtree(tmpbuild) self.log.debug('Removed temporary directory %s' % tmpbuild) except: self.log.exception("Removing temporary directory %s failed" % tmpbuild) else: #Follow this procedure for mkl version lower than 10.3 #Extra #- build the mkl interfaces (pic and no-pic) #- add wrapper libs # Add convenient libs #- form imkl 10.1 if self.getcfg('m32'): extra = { 'libmkl.so': 'GROUP (-lmkl_intel -lmkl_intel_thread -lmkl_core)', 'libmkl_em64t.a': 'GROUP (libmkl_intel.a libmkl_intel_thread.a libmkl_core.a)', 'libmkl_solver.a': 'GROUP (libmkl_solver.a)', 'libmkl_scalapack.a': 'GROUP (libmkl_scalapack_core.a)', 'libmkl_lapack.a': 'GROUP (libmkl_intel.a libmkl_intel_thread.a libmkl_core.a)', 'libmkl_cdft.a': 'GROUP (libmkl_cdft_core.a)' } else: extra = { 'libmkl.so': 'GROUP (-lmkl_intel_lp64 -lmkl_intel_thread -lmkl_core)', 'libmkl_em64t.a': 'GROUP (libmkl_intel_lp64.a libmkl_intel_thread.a libmkl_core.a)', 'libmkl_solver.a': 'GROUP (libmkl_solver_lp64.a)', 'libmkl_scalapack.a': 'GROUP (libmkl_scalapack_lp64.a)', 'libmkl_lapack.a': 'GROUP (libmkl_intel_lp64.a libmkl_intel_thread.a libmkl_core.a)', 'libmkl_cdft.a': 'GROUP (libmkl_cdft_core.a)' } for fil, txt in extra.items(): if self.getcfg('m32'): dest = os.path.join(self.installdir, 'lib/32', fil) else: dest = os.path.join(self.installdir, 'lib/em64t', fil) if not os.path.exists(dest): try: f = open(dest, 'w') f.write(txt) f.close() self.log.info("File %s written" % dest) except: self.log.exception("Can't write file %s" % (dest)) # load the dependencies m = Modules() m.addModule(self.cfg.dependencies()) m.load() if not self.getcfg('interfaces'): return # build the interfaces # - blas95 and lapack95 need more work, ignore for now #lis1=['blas95','fftw2xc','fftw2x_cdft','fftw2xf','lapack95'] # blas95 and lapack also need include/.mod to be processed lis1 = ['fftw2xc', 'fftw2x_cdft', 'fftw2xf'] lis2 = ['fftw3xc', 'fftw3xf'] interfacedir = os.path.join(self.installdir, 'interfaces') try: os.chdir(interfacedir) except: self.log.exception("Can't change to interfaces directory %s" % interfacedir) interfacestarget = "libem64t" if self.getcfg('m32'): interfacestarget = "lib32" for i in lis1 + lis2: if i in lis1: # use INSTALL_DIR and SPEC_OPT cmd = "make -f makefile %s" % interfacestarget if i in lis2: # use install_to and CFLAGS cmd = "make -f makefile %s install_to=$INSTALL_DIR" % interfacestarget for opt in ['', '-fPIC']: try: tmpbuild = tempfile.mkdtemp() self.log.debug("Created temporary directory %s" % tmpbuild) except: self.log.exception("Creating temporary directory failed") # always set INSTALL_DIR, SPEC_OPT and CFLAGS env.set('INSTALL_DIR', tmpbuild) env.set('SPEC_OPT', opt) env.set('CFLAGS', opt) try: intdir = os.path.join(interfacedir, i) os.chdir(intdir) except: self.log.exception("Can't change to interface %s directory %s" % (i, intdir)) if not run_cmd(cmd, log_all=True, simple=True): self.log.error("Building %s (opt: %s) failed" % (i, opt)) for fil in os.listdir(tmpbuild): if opt == '-fPIC': # add _pic to filename ff = fil.split('.') newfil = '.'.join(ff[:-1]) + '_pic.' + ff[-1] else: newfil = fil if self.getcfg('m32'): dest = os.path.join(self.installdir, 'lib/32', newfil) else: dest = os.path.join(self.installdir, 'lib/em64t', newfil) try: src = os.path.join(tmpbuild, fil) shutil.move(src, dest) self.log.debug("Moved %s to %s" % (src, dest)) except: self.log.exception("Failed to move %s to %s" % (src, dest)) try: shutil.rmtree(tmpbuild) self.log.debug('Removed temporary directory %s' % tmpbuild) except: self.log.exception("Removing temporary directory %s failed" % (tmpbuild))