From 3c2a665954ab2145589df9f5dbad294b93f0f587 Mon Sep 17 00:00:00 2001 From: Paul Leopardi Date: Wed, 13 Mar 2024 17:36:00 +1100 Subject: [PATCH 1/9] First draft of um7 package finds oasis3-mct headers but is missing dummygrib --- packages/um7/package.py | 131 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 131 insertions(+) create mode 100644 packages/um7/package.py diff --git a/packages/um7/package.py b/packages/um7/package.py new file mode 100644 index 0000000..d05e1b5 --- /dev/null +++ b/packages/um7/package.py @@ -0,0 +1,131 @@ +# Copyright 2013-2023 Lawrence Livermore National Security, LLC and other +# Spack Project Developers. See the top-level COPYRIGHT file for details. +# +# Copyright 2024 ACCESS-NRI +# Based on https://github.com/nci/spack-repo/blob/main/packages/um/package.py +# and https://github.com/coecms/access-esm-build-gadi +# +# SPDX-License-Identifier: (Apache-2.0 OR MIT) + + +from spack.package import * + +import os +import os.path +import llnl.util.tty as tty + +class Um7(Package): + """ + UM is a numerical weather prediction and climate modelling software package. + Um7 is a package for UM vn7.3 for ACCESS ESM 1.5 + """ + + homepage = "https://code.metoffice.gov.uk/trac/um" + git = "git@github.com:ACCESS-NRI/UM_v7.git" + + # https://code.metoffice.gov.uk/trac/um/wiki/PastReleases + version("7.3") + + maintainers("penguian") + + depends_on("fcm", type="build") + depends_on("gcom4+mpi", type=("build","link")) + depends_on("mpi", type=("build","run")) + depends_on("netcdf-fortran", type=("build","link")) + depends_on("oasis3-mct", type=("build","link")) + + + variant("platform", default="intel", description="Compiler", + values=("oneapi","intel"), multi=False) + variant("omp",default=True,description="Use OpenMP") + variant("netcdf",default=True,description="NetCDF") + variant("opt",default="high",description="Optimization level", + values=("high","debug"), multi=False) + + + def setup_build_environment(self, env): + env.prepend_path("PATH", self.spec["fcm"].prefix.bin) + env.prepend_path("CPATH", self.spec["gcom4"].prefix.include) + env.prepend_path("CPATH", self.spec["netcdf-c"].prefix.include) + env.prepend_path("CPATH", self.spec["netcdf-fortran"].prefix.include) + env.prepend_path("CPATH", self.spec["oasis3-mct"].prefix.include) + oasis3_mct_includes = [] + for header in self.spec["oasis3-mct"].headers: + include = os.path.dirname(header) + if not include in oasis3_mct_includes: + oasis3_mct_includes.append(include) + env.prepend_path("CPATH", include) + env.prepend_path("LIBRARY_PATH", self.spec["gcom4"].prefix.lib) + env.prepend_path("LIBRARY_PATH", self.spec["netcdf-c"].prefix.lib) + env.prepend_path("LIBRARY_PATH", self.spec["netcdf-fortran"].prefix.lib) + env.prepend_path("LIBRARY_PATH", self.spec["oasis3-mct"].prefix.lib) + + ''' + env.set("config_root_path","./") + env.set("config_type","atmos") + env.set("fcflags_overrides","") + env.set("gwd_ussp_precision","double") + env.set("land_surface_model","jules") + env.set("ldflags_overrides_prefix","") + env.set("ldflags_overrides_suffix","") + env.set("ls_precipitation_precision","double") + env.set("mirror","mirror") + env.set("mpp_version","1C") + env.set("platagnostic","false") + env.set("portio_version","2A") + env.set("stash_version","1A") + env.set("timer_version","3A") + ''' + + def setup_run_environment(self, env): + env.prepend_path("LD_LIBRARY_PATH", self.spec["netcdf-c"].prefix.lib) + env.prepend_path("LD_LIBRARY_PATH", self.spec["netcdf-fortran"].prefix.lib) + + + def install(self, spec, prefix): + + fcm=which("fcm") + + env["platform_config_dir"]="nci-x86-ifort" + platform = "nci-x86-ifort" + if "platform=oneapi" in spec: + env["platform_config_dir"]="nci-x86-ifx" + platform = "nci-x86-ifx" + + env["optimisation_level"]=spec.variants["opt"].value + opt_value=spec.variants["opt"].value + + env["openmp"]="true" + if "~omp" in spec: + env["openmp"]="false" + + env["netcdf"] = "true" + if "~netcdf" in spec: + env["netcdf"] = "false" + + hg = 3 # build HadGEM3 ONLY here + + # Whether to build debug --jhan: adjust path to configs + bld_config = f"bld-hadgem{hg}-mct.cfg" + um_exe = f"um_hg${hg}.exe" + if opt_value == "debug": + bld_config = f"bld-dbg-hadgem{hg}-C2.cfg" + um_exe = f"um_hg{hg}_dbg.exe-{opt_value}" + + bld_dir = f"ummodel_hg{hg}" + # Build with fcm + fcm("build", "-f", "-j", "4", + join_path(bld_dir, "cfg", bld_config)) + + # Install + mkdirp(prefix.bin) + install( + join_path(bld_dir, "bin", um_exe), + join_path(prefix.bin, um_exe)) + + ''' + install("build-atmos/bin/um-atmos.exe", prefix.bin + "/um-atmos.exe") + install("build-atmos/bin/um_script_functions", prefix.bin + "/um_script_functions") + install("build-recon/bin/um-recon", prefix.bin + "/um-recon") + install("build-recon/bin/um-recon.exe", prefix.bin + "/um-recon.exe") + ''' From 166c55cc0a40483043c375cd2d6c941cfd525f77 Mon Sep 17 00:00:00 2001 From: Paul Leopardi Date: Wed, 27 Mar 2024 10:59:01 +1100 Subject: [PATCH 2/9] Add dependence on dummygrib. Fix um_exe. Tidy up --- packages/um7/package.py | 34 +++++++--------------------------- 1 file changed, 7 insertions(+), 27 deletions(-) diff --git a/packages/um7/package.py b/packages/um7/package.py index d05e1b5..230f009 100644 --- a/packages/um7/package.py +++ b/packages/um7/package.py @@ -28,6 +28,7 @@ class Um7(Package): maintainers("penguian") + depends_on("dummygrib", type=("build","link")) depends_on("fcm", type="build") depends_on("gcom4+mpi", type=("build","link")) depends_on("mpi", type=("build","run")) @@ -55,27 +56,12 @@ def setup_build_environment(self, env): if not include in oasis3_mct_includes: oasis3_mct_includes.append(include) env.prepend_path("CPATH", include) + env.prepend_path("LIBRARY_PATH", self.spec["dummygrib"].prefix.lib) env.prepend_path("LIBRARY_PATH", self.spec["gcom4"].prefix.lib) env.prepend_path("LIBRARY_PATH", self.spec["netcdf-c"].prefix.lib) env.prepend_path("LIBRARY_PATH", self.spec["netcdf-fortran"].prefix.lib) env.prepend_path("LIBRARY_PATH", self.spec["oasis3-mct"].prefix.lib) - ''' - env.set("config_root_path","./") - env.set("config_type","atmos") - env.set("fcflags_overrides","") - env.set("gwd_ussp_precision","double") - env.set("land_surface_model","jules") - env.set("ldflags_overrides_prefix","") - env.set("ldflags_overrides_suffix","") - env.set("ls_precipitation_precision","double") - env.set("mirror","mirror") - env.set("mpp_version","1C") - env.set("platagnostic","false") - env.set("portio_version","2A") - env.set("stash_version","1A") - env.set("timer_version","3A") - ''' def setup_run_environment(self, env): env.prepend_path("LD_LIBRARY_PATH", self.spec["netcdf-c"].prefix.lib) @@ -84,7 +70,7 @@ def setup_run_environment(self, env): def install(self, spec, prefix): - fcm=which("fcm") + fcm = which("fcm") env["platform_config_dir"]="nci-x86-ifort" platform = "nci-x86-ifort" @@ -93,11 +79,11 @@ def install(self, spec, prefix): platform = "nci-x86-ifx" env["optimisation_level"]=spec.variants["opt"].value - opt_value=spec.variants["opt"].value + opt_value = spec.variants["opt"].value - env["openmp"]="true" + env["openmp"] = "true" if "~omp" in spec: - env["openmp"]="false" + env["openmp"] = "false" env["netcdf"] = "true" if "~netcdf" in spec: @@ -107,7 +93,7 @@ def install(self, spec, prefix): # Whether to build debug --jhan: adjust path to configs bld_config = f"bld-hadgem{hg}-mct.cfg" - um_exe = f"um_hg${hg}.exe" + um_exe = f"um_hg{hg}.exe" if opt_value == "debug": bld_config = f"bld-dbg-hadgem{hg}-C2.cfg" um_exe = f"um_hg{hg}_dbg.exe-{opt_value}" @@ -123,9 +109,3 @@ def install(self, spec, prefix): join_path(bld_dir, "bin", um_exe), join_path(prefix.bin, um_exe)) - ''' - install("build-atmos/bin/um-atmos.exe", prefix.bin + "/um-atmos.exe") - install("build-atmos/bin/um_script_functions", prefix.bin + "/um_script_functions") - install("build-recon/bin/um-recon", prefix.bin + "/um-recon") - install("build-recon/bin/um-recon.exe", prefix.bin + "/um-recon.exe") - ''' From f853fdefb9f5908c382e52fb3a3ed2706c08cae7 Mon Sep 17 00:00:00 2001 From: Paul Leopardi Date: Wed, 27 Mar 2024 16:13:01 +1100 Subject: [PATCH 3/9] Do not import tty as it is unused --- packages/um7/package.py | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/um7/package.py b/packages/um7/package.py index 230f009..810b3dd 100644 --- a/packages/um7/package.py +++ b/packages/um7/package.py @@ -12,7 +12,6 @@ import os import os.path -import llnl.util.tty as tty class Um7(Package): """ From facb2af239f2ac6985f0ec61c1ae7b126838804d Mon Sep 17 00:00:00 2001 From: Paul Leopardi Date: Wed, 27 Mar 2024 16:37:53 +1100 Subject: [PATCH 4/9] Tidy up --- packages/um7/package.py | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/packages/um7/package.py b/packages/um7/package.py index 810b3dd..fc0f39a 100644 --- a/packages/um7/package.py +++ b/packages/um7/package.py @@ -27,20 +27,20 @@ class Um7(Package): maintainers("penguian") - depends_on("dummygrib", type=("build","link")) + depends_on("dummygrib", type=("build", "link")) depends_on("fcm", type="build") - depends_on("gcom4+mpi", type=("build","link")) - depends_on("mpi", type=("build","run")) - depends_on("netcdf-fortran", type=("build","link")) - depends_on("oasis3-mct", type=("build","link")) + depends_on("gcom4+mpi", type=("build", "link")) + depends_on("mpi", type=("build", "run")) + depends_on("netcdf-fortran", type=("build", "link")) + depends_on("oasis3-mct", type=("build", "link")) variant("platform", default="intel", description="Compiler", - values=("oneapi","intel"), multi=False) - variant("omp",default=True,description="Use OpenMP") - variant("netcdf",default=True,description="NetCDF") - variant("opt",default="high",description="Optimization level", - values=("high","debug"), multi=False) + values=("oneapi", "intel"), multi=False) + variant("omp", default=True, description="Use OpenMP") + variant("netcdf", default=True, description="NetCDF") + variant("opt", default="high", description="Optimization level", + values=("high", "debug"), multi=False) def setup_build_environment(self, env): @@ -89,7 +89,7 @@ def install(self, spec, prefix): env["netcdf"] = "false" hg = 3 # build HadGEM3 ONLY here - + # Whether to build debug --jhan: adjust path to configs bld_config = f"bld-hadgem{hg}-mct.cfg" um_exe = f"um_hg{hg}.exe" From 4d13f49fdee237c1c39b34842e9da9c134d3d12c Mon Sep 17 00:00:00 2001 From: Paul Leopardi Date: Wed, 27 Mar 2024 16:58:40 +1100 Subject: [PATCH 5/9] Tidy up. Remove unused variable --- packages/um7/package.py | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/packages/um7/package.py b/packages/um7/package.py index fc0f39a..5203d6b 100644 --- a/packages/um7/package.py +++ b/packages/um7/package.py @@ -52,7 +52,7 @@ def setup_build_environment(self, env): oasis3_mct_includes = [] for header in self.spec["oasis3-mct"].headers: include = os.path.dirname(header) - if not include in oasis3_mct_includes: + if include not in oasis3_mct_includes: oasis3_mct_includes.append(include) env.prepend_path("CPATH", include) env.prepend_path("LIBRARY_PATH", self.spec["dummygrib"].prefix.lib) @@ -71,14 +71,12 @@ def install(self, spec, prefix): fcm = which("fcm") - env["platform_config_dir"]="nci-x86-ifort" - platform = "nci-x86-ifort" + env["platform_config_dir"] = "nci-x86-ifort" if "platform=oneapi" in spec: - env["platform_config_dir"]="nci-x86-ifx" - platform = "nci-x86-ifx" + env["platform_config_dir"] = "nci-x86-ifx" - env["optimisation_level"]=spec.variants["opt"].value opt_value = spec.variants["opt"].value + env["optimisation_level"] = opt_value env["openmp"] = "true" if "~omp" in spec: @@ -88,7 +86,7 @@ def install(self, spec, prefix): if "~netcdf" in spec: env["netcdf"] = "false" - hg = 3 # build HadGEM3 ONLY here + hg = 3 # build HadGEM3 ONLY here # Whether to build debug --jhan: adjust path to configs bld_config = f"bld-hadgem{hg}-mct.cfg" From 3774ffb881f50f34cedc44aff0668ae54ad0b7f3 Mon Sep 17 00:00:00 2001 From: Paul Leopardi Date: Mon, 15 Apr 2024 17:12:36 +1000 Subject: [PATCH 6/9] Add oasis3-mct branch to spec. Simplify if statements. --- packages/um7/package.py | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/packages/um7/package.py b/packages/um7/package.py index 5203d6b..5965824 100644 --- a/packages/um7/package.py +++ b/packages/um7/package.py @@ -32,7 +32,7 @@ class Um7(Package): depends_on("gcom4+mpi", type=("build", "link")) depends_on("mpi", type=("build", "run")) depends_on("netcdf-fortran", type=("build", "link")) - depends_on("oasis3-mct", type=("build", "link")) + depends_on("oasis3-mct@git.access-esm1.5-new-modules", type=("build", "link")) variant("platform", default="intel", description="Compiler", @@ -69,31 +69,30 @@ def setup_run_environment(self, env): def install(self, spec, prefix): + boolstr = lambda b: "true" if b else "false" + fcm = which("fcm") - env["platform_config_dir"] = "nci-x86-ifort" if "platform=oneapi" in spec: env["platform_config_dir"] = "nci-x86-ifx" + else: + env["platform_config_dir"] = "nci-x86-ifort" opt_value = spec.variants["opt"].value env["optimisation_level"] = opt_value - env["openmp"] = "true" - if "~omp" in spec: - env["openmp"] = "false" - - env["netcdf"] = "true" - if "~netcdf" in spec: - env["netcdf"] = "false" + env["openmp"] = boolstr("~omp" in spec) + env["netcdf"] = boolstr("~netcdf" in spec) hg = 3 # build HadGEM3 ONLY here # Whether to build debug --jhan: adjust path to configs - bld_config = f"bld-hadgem{hg}-mct.cfg" - um_exe = f"um_hg{hg}.exe" if opt_value == "debug": bld_config = f"bld-dbg-hadgem{hg}-C2.cfg" um_exe = f"um_hg{hg}_dbg.exe-{opt_value}" + else: + bld_config = f"bld-hadgem{hg}-mct.cfg" + um_exe = f"um_hg{hg}.exe" bld_dir = f"ummodel_hg{hg}" # Build with fcm From 1abe3ec8b309da854de53bf310f1ca01c09e52f0 Mon Sep 17 00:00:00 2001 From: Paul Leopardi Date: Tue, 16 Apr 2024 11:32:14 +1000 Subject: [PATCH 7/9] Use self.compiler.name --- packages/um7/package.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/packages/um7/package.py b/packages/um7/package.py index 5965824..4957305 100644 --- a/packages/um7/package.py +++ b/packages/um7/package.py @@ -34,9 +34,6 @@ class Um7(Package): depends_on("netcdf-fortran", type=("build", "link")) depends_on("oasis3-mct@git.access-esm1.5-new-modules", type=("build", "link")) - - variant("platform", default="intel", description="Compiler", - values=("oneapi", "intel"), multi=False) variant("omp", default=True, description="Use OpenMP") variant("netcdf", default=True, description="NetCDF") variant("opt", default="high", description="Optimization level", @@ -73,7 +70,7 @@ def install(self, spec, prefix): fcm = which("fcm") - if "platform=oneapi" in spec: + if self.compiler.name == "oneapi": env["platform_config_dir"] = "nci-x86-ifx" else: env["platform_config_dir"] = "nci-x86-ifort" From 6abdaa31ff115c42008a20176dc8d9080b415954 Mon Sep 17 00:00:00 2001 From: Paul Leopardi Date: Fri, 19 Apr 2024 10:57:50 +1000 Subject: [PATCH 8/9] Simplify the debug um_exe name --- packages/um7/package.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/um7/package.py b/packages/um7/package.py index 4957305..af922cd 100644 --- a/packages/um7/package.py +++ b/packages/um7/package.py @@ -86,7 +86,7 @@ def install(self, spec, prefix): # Whether to build debug --jhan: adjust path to configs if opt_value == "debug": bld_config = f"bld-dbg-hadgem{hg}-C2.cfg" - um_exe = f"um_hg{hg}_dbg.exe-{opt_value}" + um_exe = f"um_hg{hg}_dbg.exe" else: bld_config = f"bld-hadgem{hg}-mct.cfg" um_exe = f"um_hg{hg}.exe" From 7556c6ffde4e0147b72ed7de8bf5ea12c2fbf3e8 Mon Sep 17 00:00:00 2001 From: Paul Leopardi Date: Fri, 19 Apr 2024 14:56:18 +1000 Subject: [PATCH 9/9] Support only the intel compiler, for now --- packages/um7/package.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/um7/package.py b/packages/um7/package.py index af922cd..610dc2b 100644 --- a/packages/um7/package.py +++ b/packages/um7/package.py @@ -70,10 +70,10 @@ def install(self, spec, prefix): fcm = which("fcm") - if self.compiler.name == "oneapi": - env["platform_config_dir"] = "nci-x86-ifx" - else: + if self.compiler.name == "intel": env["platform_config_dir"] = "nci-x86-ifort" + else: + raise NotImplentedError("Unknown compiler") opt_value = spec.variants["opt"].value env["optimisation_level"] = opt_value