From 2ac343e92ea0213121f05e4edaf51da4abfd79c9 Mon Sep 17 00:00:00 2001 From: Erik Schnetter Date: Thu, 9 Mar 2017 09:14:13 -0500 Subject: [PATCH] cosmomc: New package CosmoMC (#3292) * cosmomc: New package CosmoMC * cosmomc: Improve version numbering scheme * planck-likelihood: New package * cosmomc: Pacify flake8 * cosmomc: Code cleanup as requested in the review * cosmomc: Various updates suggested during review * cosmomc: Limit compiler versions (as documented in the build instructions) * cosmomc: Correct flake8 error * cosmomc: Use `libs` instead of `lapack_libs` * planck-likelihood: Make makefile output more verbose and readable * planck-likelilhood: Correct order of libraries when calling linker * cosmomc: Clean up check for suitable compiler * planck-likelihood: Use modern mechanism to set environment variables --- .../builtin/packages/cosmomc/Makefile.patch | 26 +++ .../builtin/packages/cosmomc/errorstop.patch | 11 + .../repos/builtin/packages/cosmomc/package.py | 201 ++++++++++++++++++ .../packages/planck-likelihood/fortran.patch | 11 + .../packages/planck-likelihood/make.patch | 21 ++ .../packages/planck-likelihood/package.py | 148 +++++++++++++ 6 files changed, 418 insertions(+) create mode 100644 var/spack/repos/builtin/packages/cosmomc/Makefile.patch create mode 100644 var/spack/repos/builtin/packages/cosmomc/errorstop.patch create mode 100644 var/spack/repos/builtin/packages/cosmomc/package.py create mode 100644 var/spack/repos/builtin/packages/planck-likelihood/fortran.patch create mode 100644 var/spack/repos/builtin/packages/planck-likelihood/make.patch create mode 100644 var/spack/repos/builtin/packages/planck-likelihood/package.py diff --git a/var/spack/repos/builtin/packages/cosmomc/Makefile.patch b/var/spack/repos/builtin/packages/cosmomc/Makefile.patch new file mode 100644 index 0000000000..f7241af3d0 --- /dev/null +++ b/var/spack/repos/builtin/packages/cosmomc/Makefile.patch @@ -0,0 +1,26 @@ +--- a/Makefile ++++ b/Makefile +@@ -7,8 +7,7 @@ + + rebuild: clean delete cosmomc + +-cosmomc: BUILD ?= MPI +-cosmomc_debug: BUILD ?= MPI ++BUILD ?= MPI + + getdist: ./source/*.*90 + cd ./source && make getdist BUILD=$(BUILD) +--- a/source/Makefile ++++ b/source/Makefile +@@ -57,11 +57,7 @@ + #commented above is (I think) for Mac; this is standard linux (sudo apt-get install liblapack-dev) + LAPACKL = -lblas -llapack + +-#march native does not work on Mac, otherwise use (comment out if your cluster is inhomogeneous) +-ifneq ($(shell uname -s),Darwin) +-#native optimization does not work on Mac + FFLAGS+=-march=native +-endif + + endif + diff --git a/var/spack/repos/builtin/packages/cosmomc/errorstop.patch b/var/spack/repos/builtin/packages/cosmomc/errorstop.patch new file mode 100644 index 0000000000..b23e925daf --- /dev/null +++ b/var/spack/repos/builtin/packages/cosmomc/errorstop.patch @@ -0,0 +1,11 @@ +--- a/camb/constants.f90 ++++ b/camb/constants.f90 +@@ -87,7 +87,7 @@ + global_error_message='' + end if + if (present(id)) then +- if (id==0) error stop('Error id must be non-zero') ++ if (id==0) error stop + global_error_flag=id + else + global_error_flag=-1 diff --git a/var/spack/repos/builtin/packages/cosmomc/package.py b/var/spack/repos/builtin/packages/cosmomc/package.py new file mode 100644 index 0000000000..a6a4409b25 --- /dev/null +++ b/var/spack/repos/builtin/packages/cosmomc/package.py @@ -0,0 +1,201 @@ +############################################################################## +# Copyright (c) 2013-2016, Lawrence Livermore National Security, LLC. +# Produced at the Lawrence Livermore National Laboratory. +# +# This file is part of Spack. +# Created by Todd Gamblin, tgamblin@llnl.gov, All rights reserved. +# LLNL-CODE-647188 +# +# For details, see https://github.com/llnl/spack +# Please also see the LICENSE file for our notice and the LGPL. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License (as +# published by the Free Software Foundation) version 2.1, February 1999. +# +# This program 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 terms and +# conditions of the GNU Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +############################################################################## + +from spack import * +import fnmatch +import os + + +class Cosmomc(Package): + """CosmoMC is a Fortran 2008 Markov-Chain Monte-Carlo (MCMC) engine + for exploring cosmological parameter space, together with + Fortran and python code for analysing Monte-Carlo samples and + importance sampling (plus a suite of scripts for building grids + of runs, plotting and presenting results).""" + + homepage = "http://cosmologist.info/cosmomc/" + url = "https://github.com/cmbant/CosmoMC/archive/Nov2016.tar.gz" + + version('2016.11', '98620cb746352f68fb0c1196e9a070ac') + version('2016.06', '92dc651d1407cca6ea9228992165f5cb') + + def url_for_version(self, version): + names = {'2016.11': "Nov2016", + '2016.06': "June2016"} + return ("https://github.com/cmbant/CosmoMC/archive/%s.tar.gz" % + names[str(version)]) + + variant('mpi', default=True, description='Enable MPI support') + variant('planck', default=False, + description='Enable Planck Likelihood code and baseline data') + + patch('Makefile.patch') + patch('errorstop.patch') + + depends_on('mpi', when='+mpi') + depends_on('planck-likelihood', when='+planck') + depends_on('python @2.7:2.999,3.4:') + + parallel = False + + def install(self, spec, prefix): + # Clean up environment to avoid configure problems + os.environ.pop('LINKMPI', '') + os.environ.pop('NERSC_HOST', '') + os.environ.pop('NONCLIKLIKE', '') + os.environ.pop('PICO', '') + os.environ.pop('PRECISION', '') + os.environ.pop('RECOMBINATION', '') + os.environ.pop('WMAP', '') + + # Set up Planck data if requested + clikdir = join_path('data', 'clik') + try: + os.remove(clikdir) + except OSError: + pass + if '+planck' in spec: + os.symlink(join_path(os.environ['CLIK_DATA'], 'plc_2.0'), clikdir) + else: + os.environ.pop('CLIK_DATA', '') + os.environ.pop('CLIK_PATH', '') + os.environ.pop('CLIK_PLUGIN', '') + + # Choose compiler + # Note: Instead of checking the compiler vendor, we should + # rewrite the Makefile to use Spack's options all the time + if spec.satisfies('%gcc'): + if not spec.satisfies('%gcc@6:'): + raise InstallError( + "When using GCC, " + "CosmoMC requires version gcc@6: for building") + choosecomp = 'ifortErr=1' # choose gfortran + elif spec.satisfies('%intel'): + if not spec.satifies('%intel@14:'): + raise InstallError( + "When using the Intel compiler, " + "CosmoMC requires version intel@14: for building") + choosecomp = 'ifortErr=0' # choose ifort + else: + raise InstallError("Only GCC and Intel compilers are supported") + + # Configure MPI + if '+mpi' in spec: + wantmpi = 'BUILD=MPI' + mpif90 = 'MPIF90C=%s' % spec['mpi'].mpifc + else: + wantmpi = 'BUILD=NOMPI' + mpif90 = 'MPIF90C=' + + # Choose BLAS and LAPACK + lapack = ("LAPACKL=%s" % + (spec['lapack'].libs + spec['blas'].libs).ld_flags) + + # Build + make(choosecomp, wantmpi, mpif90, lapack) + + # Install + mkdirp(prefix.bin) + install('cosmomc', prefix.bin) + root = join_path(prefix.share, 'cosmomc') + mkdirp(root) + entries = [ + 'batch1', + 'batch2', + 'batch3', + 'camb', + 'chains', + 'clik_latex.paramnames', + 'clik_units.paramnames', + 'cosmomc.cbp', + 'data', + 'distgeneric.ini', + 'distparams.ini', + 'disttest.ini', + 'docs', + 'job_script', + 'job_script_MOAB', + 'job_script_SLURM', + 'paramnames', + 'params_generic.ini', + 'planck_covmats', + 'python', + 'scripts', + # don't copy 'source' + 'test.ini', + 'test_pico.ini', + 'test_planck.ini', + 'tests', + ] + for entry in entries: + if os.path.isfile(entry): + install(entry, root) + else: + install_tree(entry, join_path(root, entry)) + for dirpath, dirnames, filenames in os.walk(prefix): + for filename in fnmatch.filter(filenames, '*~'): + os.remove(os.path.join(dirpath, filename)) + + @on_package_attributes(run_tests=True) + @run_after('install') + def check_install(self): + prefix = self.prefix + spec = self.spec + + os.environ.pop('LINKMPI', '') + os.environ.pop('NERSC_HOST', '') + os.environ.pop('NONCLIKLIKE', '') + os.environ.pop('PICO', '') + os.environ.pop('PRECISION', '') + os.environ.pop('RECOMBINATION', '') + os.environ.pop('WMAP', '') + + os.environ.pop('COSMOMC_LOCATION', '') + os.environ.pop('PLC_LOCATION', '') + + os.environ.pop('CLIKPATH', '') + os.environ.pop('PLANCKLIKE', '') + + exe = join_path(prefix.bin, 'cosmomc') + args = [] + if '+mpi' in spec: + # Add mpirun prefix + args = ['-np', '1', exe] + exe = join_path(spec['mpi'].prefix.bin, 'mpiexec') + cosmomc = Executable(exe) + with working_dir('spack-check', create=True): + for entry in [ + 'camb', + 'chains', + 'data', + 'paramnames', + 'planck_covmats', + ]: + os.symlink(join_path(prefix.share, 'cosmomc', entry), entry) + inifile = join_path(prefix.share, 'cosmomc', 'test.ini') + cosmomc(*(args + [inifile])) + if '+planck' in spec: + inifile = join_path(prefix.share, 'cosmomc', 'test_planck.ini') + cosmomc(*(args + [inifile])) diff --git a/var/spack/repos/builtin/packages/planck-likelihood/fortran.patch b/var/spack/repos/builtin/packages/planck-likelihood/fortran.patch new file mode 100644 index 0000000000..b63d268eca --- /dev/null +++ b/var/spack/repos/builtin/packages/planck-likelihood/fortran.patch @@ -0,0 +1,11 @@ +--- a/src/bflike/bflike_smw.f90 ++++ b/src/bflike/bflike_smw.f90 +@@ -1600,6 +1600,8 @@ + ok = .false. + + call fid%init() ++ ++ unit = 3001 + + open(unit = unit,file=trim(filein),status='old',action='read',& + iostat=istat) diff --git a/var/spack/repos/builtin/packages/planck-likelihood/make.patch b/var/spack/repos/builtin/packages/planck-likelihood/make.patch new file mode 100644 index 0000000000..6f3ce81b80 --- /dev/null +++ b/var/spack/repos/builtin/packages/planck-likelihood/make.patch @@ -0,0 +1,21 @@ +--- a/Makefile ++++ b/Makefile +@@ -336,15 +336,15 @@ + + $(BDIR)/libclik_f90.$(SO): $(BDIR)/libclik.$(SO) $(addprefix $(ODIR)/,clik_fortran.o clik.f90.o) + @$(ECHO) "build $(BLUE_COLOR)$(@) $(NO_COLOR)" +- @$(LD) $(SHARED) $(LDFLAG) $(LAPACK) -L$(BDIR) -lclik $^ -o $@ ++ @$(LD) -o $@ $(addprefix $(ODIR)/,clik_fortran.o clik.f90.o) -L$(BDIR) -lclik $(SHARED) $(LAPACK) $(LDFLAG) + + $(BDIR)/clik_example_C: $(ODIR)/clik_example_c.o $(BDIR)/libclik.$(SO) + @$(ECHO) "build $(BLUE_COLOR)$(@) $(NO_COLOR)" +- @$(CC) $(LDFLAG) $(LAPACK) -L$(BDIR) -lclik $< -o $@ ++ @$(CC) -o $@ $(ODIR)/clik_example_c.o -L$(BDIR) -lclik $(LAPACK) $(LDFLAG) + + $(BDIR)/clik_example_f90: $(ODIR)/clik_example_f90.f90.o $(BDIR)/libclik_f90.$(SO) + @$(ECHO) "build $(BLUE_COLOR)$(@) $(NO_COLOR)" +- @$(FC) $(LDFLAG) $(LAPACK) -L$(BDIR) -lclik_f90 -lclik $< -o $@ ++ @$(FC) -o $@ $(ODIR)/clik_example_f90.f90.o -L$(BDIR) -lclik_f90 -lclik $(LAPACK) $(LDFLAG) + + $(BDIR)/liblapack_clik.$(SO): |$(BDIR) + ifndef MKL_LIB_FULLPATH diff --git a/var/spack/repos/builtin/packages/planck-likelihood/package.py b/var/spack/repos/builtin/packages/planck-likelihood/package.py new file mode 100644 index 0000000000..c5c5cac6cf --- /dev/null +++ b/var/spack/repos/builtin/packages/planck-likelihood/package.py @@ -0,0 +1,148 @@ +############################################################################## +# Copyright (c) 2013-2016, Lawrence Livermore National Security, LLC. +# Produced at the Lawrence Livermore National Laboratory. +# +# This file is part of Spack. +# Created by Todd Gamblin, tgamblin@llnl.gov, All rights reserved. +# LLNL-CODE-647188 +# +# For details, see https://github.com/llnl/spack +# Please also see the LICENSE file for our notice and the LGPL. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License (as +# published by the Free Software Foundation) version 2.1, February 1999. +# +# This program 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 terms and +# conditions of the GNU Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +############################################################################## + +from spack import * + + +class PlanckLikelihood(Package): + """2015 Cosmic Microwave Background (CMB) spectra and likelihood code""" + + homepage = "https://wiki.cosmos.esa.int/planckpla2015/index.php/CMB_spectrum_%26_Likelihood_Code" + url = "http://irsa.ipac.caltech.edu/data/Planck/release_2/software/COM_Likelihood_Code-v2.0.R2.00.tar.bz2" + + version('2.00', '7a081679ff249dc4f94fb7177e16e818', + url="http://irsa.ipac.caltech.edu/data/Planck/release_2/software/COM_Likelihood_Code-v2.0.R2.00.tar.bz2") + + variant('lensing-ext', default=False, + description="Provide lensing-ext data") + variant('plik-DS', default=False, + description="Provide plik-DS data") + variant('plik-HM-ext', default=False, + description="Provide plik-HM-ext data") + variant('plik-unbinned', default=False, + description="Provide plik-unbinned data") + + patch('fortran.patch') + patch('make.patch') + + resource( + name='baseline', + url="http://irsa.ipac.caltech.edu/data/Planck/release_2/software/COM_Likelihood_Data-baseline_R2.00.tar.gz", + md5='7e784819cea65dbc290ea3619420295a', + destination='.') + resource( + name='lensing-ext', + url="http://irsa.ipac.caltech.edu/data/Planck/release_2/software/COM_Likelihood_Data-extra-lensing-ext.R2.00.tar.gz", + md5='091736f73b47a09162050bee27d68399', + destination='.', + when='+lensing-ext') + resource( + name='plik-DS', + url="http://irsa.ipac.caltech.edu/data/Planck/release_2/software/COM_Likelihood_Data-extra-plik-DS.R2.00.tar.gz", + md5='76ac04f989025eecab3825aba7e41f36', + destination='.', + when='+plik-DS') + resource( + name='plik-HM-ext', + url="http://irsa.ipac.caltech.edu/data/Planck/release_2/software/COM_Likelihood_Data-extra-plik-HM-ext.R2.00.tar.gz", + md5='1c3bd8221f973b7bf7e76647451fd6e5', + destination='.', + when='+plik-HM-ext') + resource( + name='plik-unbinned', + url="http://irsa.ipac.caltech.edu/data/Planck/release_2/software/COM_Likelihood_Data-extra-plik-unbinned.R2.00.tar.gz", + md5='c5869aa6b6581b6863d2a6e0ffd3826c', + destination='.', + when='+plik-unbinned') + + depends_on('blas') + depends_on('cfitsio +shared') + depends_on('lapack') + + # Note: Could also install Python bindings + + parallel = False + + def install(self, spec, prefix): + # Configure + + # Don't hide build commands + filter_file("^\t@", "\t", "Makefile") + + makeflags = [ + 'PREFIX=%s' % prefix, + 'COLORS=0', + 'CFITSIOPATH=%s' % spec['cfitsio'].prefix, + 'CC=cc', + 'FC=fc', + 'IFORTLIBPATH=', + 'IFORTRUNTIME=-lintlc -limf -lsvml -liomp5 -lifportmt -lifcoremt', + 'GFORTRANLIBPATH=', + 'GFORTRANRUNTIME=-lgfortran -lgomp', + 'LAPACKLIBPATH=', + 'LAPACK=%s' % (spec['lapack'].libs + spec['blas'].libs).ld_flags, + 'COPENMP=%s' % self.compiler.openmp_flag, + 'FOPENMP=%s' % self.compiler.openmp_flag, + ] + + # Build + make(*makeflags) + + # Install + make('install', *makeflags) + fix_darwin_install_name(prefix.lib) + dirs = ['plc_2.0'] + if '+lensing-ext' in spec: + dirs.append('lensing_ext') + if '+plik-DS' in spec: + dirs.append('plik_DS') + if '+plik-HM-ext' in spec: + dirs.append('plik_HM_ext') + if '+plik-unbinned' in spec: + dirs.append('plik_unbinned') + for dir in dirs: + install_tree(dir, join_path(prefix, 'share', 'clik', dir)) + + def setup_dependent_environment(self, spack_env, run_env, dependent_spec): + prefix = self.prefix + spack_env.set('CLIK_PATH', prefix) + spack_env.set('CLIK_DATA', join_path(prefix, 'share', 'clik')) + spack_env.set('CLIK_PLUGIN', 'rel2015') + + def setup_environment(self, spack_env, run_env): + prefix = self.prefix + run_env.set('CLIK_PATH', prefix) + run_env.set('CLIK_DATA', join_path(prefix, 'share', 'clik')) + run_env.set('CLIK_PLUGIN', 'rel2015') + + @on_package_attributes(run_tests=True) + @run_after('install') + def check_install(self): + prefix = self.prefix + clik_example_C = Executable(join_path(prefix.bin, 'clik_example_C')) + with working_dir('spack-check', create=True): + clik_example_C(join_path(prefix, 'share', 'clik', + 'plc_2.0', 'hi_l', 'plik', + 'plik_dx11dr2_HM_v18_TT.clik'))