Skip to content

Instantly share code, notes, and snippets.

@migueldiascosta
Created March 7, 2017 01:45
Show Gist options
  • Save migueldiascosta/78f6fbf6123d2de399d60884158732bf to your computer and use it in GitHub Desktop.
Save migueldiascosta/78f6fbf6123d2de399d60884158732bf to your computer and use it in GitHub Desktop.
siesta easyblock for versions 4.1-b2 and above
##
# Copyright 2009-2016 Ghent University
#
# This file is part of EasyBuild,
# originally created by the HPC team of Ghent University (http://ugent.be/hpc/en),
# with support of Ghent University (http://ugent.be/hpc),
# the Flemish Supercomputer Centre (VSC) (https://vscentrum.be/nl/en),
# Flemish Research Foundation (FWO) (http://www.fwo.be/en)
# and the Department of Economy, Science and Innovation (EWI) (http://www.ewi-vlaanderen.be/en).
#
# http://github.com/hpcugent/easybuild
#
# EasyBuild is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation v2.
#
# EasyBuild is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with EasyBuild. If not, see <http://www.gnu.org/licenses/>.
##
"""
EasyBuild support for Siesta, implemented as an easyblock
@author: Miguel Dias Costa (National university of Singapore)
"""
import os
from distutils.version import LooseVersion
from easybuild.framework.easyconfig import CUSTOM
from easybuild.easyblocks.generic.makecp import MakeCp
from easybuild.tools import toolchain
from easybuild.tools.build_log import EasyBuildError
class EB_Siesta(MakeCp):
"""Support for building and installing Siesta."""
def __init__(self, *args, **kwargs):
"""Initialisation of custom class variables for Siesta."""
super(EB_Siesta, self).__init__(*args, **kwargs)
self.build_in_installdir = True
def extract_step(self):
"""Extract sources."""
# strip off 'siesta-<version>' part to avoid having everything in a subdirectory
self.cfg['unpack_options'] = "--strip-components=1"
super(EB_Siesta, self).extract_step()
@staticmethod
def extra_options(extra_vars=None):
"""Define extra options for Siesta."""
extra = {
'hybrid': [False, "Enable hybrid build (with OpenMP)", CUSTOM],
'with_netcdf': [False, "Enable netCDF support", CUSTOM],
'files_to_copy': [[], "List of files or dirs to copy", CUSTOM],
'with_transiesta': [True, "Build transiesta", CUSTOM],
'with_utils': [True, "Build all utils", CUSTOM],
}
return MakeCp.extra_options(extra_vars=extra)
def build_step(self):
"""Custom build procedure for Siesta."""
if LooseVersion(self.version) < LooseVersion("4.1-b2"):
raise EasyBuildError("Siesta versions before 4.1-b2 are not supported by this easyblock")
self.cfg.update('prebuildopts', 'cd Obj && ../Src/obj_setup.sh &&')
if self.toolchain.comp_family() in [toolchain.INTELCOMP]:
self.cfg.update('prebuildopts', 'cp intel.make arch.make &&')
else:
self.cfg.update('prebuildopts', 'cp gfortran.make arch.make &&')
if self.toolchain.options.get('usempi', None):
self.cfg.update('prebuildopts', 'sed -i "s/^CC = .*/CC = $MPICC/" arch.make &&')
self.cfg.update('prebuildopts', 'sed -i "s/^FC = .*/FC = $MPIF90/" arch.make &&')
self.cfg.update('prebuildopts', 'sed -i "s/^FPPFLAGS = /FPPFLAGS = -DMPI /" arch.make &&')
self.cfg.update('prebuildopts', 'sed -i "26i MPI_INTERFACE = libmpi_f90.a" arch.make &&')
self.cfg.update('prebuildopts', 'sed -i "27i MPI_INCLUDE = ." arch.make &&')
if self.cfg['hybrid']:
complibs = os.environ['LIBSCALAPACK_MT']
ompflag = self.toolchain.get_flag('openmp')
self.cfg.update('prebuildopts', 'sed -i "s/^FFLAGS = /FFLAGS = ' + ompflag + ' /" arch.make &&')
else:
complibs = os.environ['LIBSCALAPACK']
self.cfg.update('prebuildopts', 'sed -i "s/libsiestaLAPACK.a libsiestaBLAS.a//" arch.make &&')
self.cfg.update('prebuildopts', 'sed -i "s/^LIBS = /LIBS = ' + complibs + ' /" arch.make &&')
if self.cfg['with_netcdf']:
self.cfg.update('prebuildopts', 'sed -i "s/^LIBS = /LIBS = -lnetcdff -lnetcdf /" arch.make &&')
self.cfg.update('prebuildopts', 'sed -i "s/^FPPFLAGS = /FPPFLAGS = -DCDF /" arch.make &&')
if self.cfg['with_transiesta']:
self.cfg.update('buildopts', '&& cd .. && mkdir Obj2 && cd Obj2 && ../Src/obj_setup.sh &&')
self.cfg.update('buildopts', 'cp ../Obj/arch.make . && make transiesta &&')
if self.cfg['with_utils']:
self.cfg.update('buildopts', 'cd ../Util && sh ./build_all.sh')
super(EB_Siesta, self).build_step()
def install_step(self):
"""Custom install procedure for Siesta."""
bins = ['Obj/siesta']
if self.cfg['with_transiesta']:
bins.extend(['Obj2/transiesta'])
self.cfg['files_to_copy'] = [(bins, 'bin')]
super(EB_Siesta, self).install_step()
def sanity_check_step(self):
"""Custom sanity check for Siesta."""
bins = ['bin/siesta']
if self.cfg['with_transiesta']:
bins.extend(['bin/transiesta'])
custom_paths = {
'files': bins,
'dirs': []
}
super(EB_Siesta, self).sanity_check_step(custom_paths=custom_paths)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment