Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/access-esm1p5/package.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class AccessEsm1p5(BundlePackage):
version("latest")

depends_on("cice4@access-esm1.5", type="run")
depends_on("mom5@access-esm1.5 type=ACCESS-CM", type="run")
depends_on("mom5@access-esm1.5", type="run")
# um7 is in a private repository
depends_on("um7@access-esm1.5", type="run")

Expand Down
18 changes: 1 addition & 17 deletions packages/access-esm1p6/package.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,6 @@ class AccessEsm1p6(BundlePackage):
values=("4", "5"),
multi=False,
)
variant(
"generic-tracers",
default=True,
description="Enable generic tracers.",
)
variant(
"um",
default="access-esm1.6",
Expand All @@ -52,18 +47,7 @@ class AccessEsm1p6(BundlePackage):

depends_on("cice4@access-esm1.5", type="run", when="cice=4")
depends_on("cice5@access-esm1.6", type="run", when="cice=5")
# TODO: Use the access-esm1.6 branch when it has been confirmed that
# MOM5 master supports building with generic tracers disabled.
depends_on(
"mom5@access-esm1.5 type=ACCESS-CM",
type="run",
when="~generic-tracers",
)
depends_on(
"mom5@access-esm1.6 type=ACCESS-ESM",
type="run",
when="+generic-tracers",
)
depends_on("mom5@access-esm1.6", type="run")
# um7 is in a private repository
depends_on("um7@access-esm1.5", type="run", when="um=access-esm1.5")
depends_on("um7@access-esm1.6", type="run", when="um=access-esm1.6")
Expand Down
4 changes: 2 additions & 2 deletions packages/access-om2-bgc/package.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ class AccessOm2Bgc(BundlePackage):
depends_on("cice5+deterministic", when="+deterministic", type="run")
depends_on("cice5~deterministic", when="~deterministic", type="run")
depends_on(
"mom5+deterministic type=ACCESS-OM-BGC",
"mom5@legacy-access-om2-bgc+deterministic",
when="+deterministic",
type="run"
)
depends_on(
"mom5~deterministic type=ACCESS-OM-BGC",
"mom5@legacy-access-om2-bgc~deterministic",
when="~deterministic",
type="run"
)
Expand Down
120 changes: 86 additions & 34 deletions packages/mom5/package.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# Copyright 2013-2023 Lawrence Livermore National Security, LLC and other
# Spack Project Developers. See the top-level COPYRIGHT file for details.
# Copyright Spack Project Developers. See COPYRIGHT file for details.
#
# Copyright 2023 ACCESS-NRI
# Copyright ACCESS-NRI
#
# SPDX-License-Identifier: (Apache-2.0 OR MIT)

from spack.package import install, join_path, mkdirp
from spack.version.version_types import GitVersion, StandardVersion

# https://spack.readthedocs.io/en/latest/build_systems/makefilepackage.html
class Mom5(MakefilePackage):
Expand All @@ -18,23 +18,21 @@ class Mom5(MakefilePackage):
maintainers("harshula", "penguian")

version("access-om2", branch="master", preferred=True)
version("legacy-access-om2-bgc", branch="master")
version("access-esm1.5", branch="access-esm1.5")
version("access-esm1.6", branch="master")

variant("restart_repro", default=True, description="Reproducible restart build.")
variant("access-gtracers", default=False, description="Use ACCESS-NRI's fork of GFDL-generic-tracers.")
# The following two variants are not applicable when version is "access-esm1.5":
variant("deterministic", default=False, description="Deterministic build.")
variant("optimisation_report", default=False, description="Generate optimisation reports.")
variant("type", default="ACCESS-OM",
values=("ACCESS-CM", "ACCESS-ESM", "ACCESS-OM", "ACCESS-OM-BGC", "MOM_solo"),
multi=False,
description="Build MOM5 to support a particular use case.")

depends_on("access-fms", when="+access-gtracers")
depends_on("access-generic-tracers", when="+access-gtracers")

with when("@:access-esm0,access-esm2:"):

with when("@access-esm1.6,access-om2,legacy-access-om2-bgc"):
variant("deterministic",
default=False,
description="Deterministic build.")
variant("optimisation_report",
default=False,
description="Generate optimisation reports.")

with when("@access-om2,legacy-access-om2-bgc"):
depends_on("netcdf-c@4.7.4:")
depends_on("netcdf-fortran@4.5.2:")
# Depend on virtual package "mpi".
Expand All @@ -44,28 +42,77 @@ class Mom5(MakefilePackage):
depends_on("oasis3-mct~deterministic", when="~deterministic")
depends_on("libaccessom2+deterministic", when="+deterministic")
depends_on("libaccessom2~deterministic", when="~deterministic")

# NOTE: Spack will also match "access-om2-legacy-bgc" here, that's why
# it has been renamed to "legacy-access-om2-bgc".
with when("@access-om2"):
depends_on("access-fms")
depends_on("access-generic-tracers")

# access-esm1.5 and access-esm1.6
with when("@access-esm1.5:access-esm1.6"):
depends_on("netcdf-c@4.7.1:")
depends_on("netcdf-fortran@4.5.1:")
# Depend on "openmpi".
depends_on("openmpi")
depends_on("oasis3-mct")

phases = ["edit", "build", "install"]
with when("@access-esm1.5"):
depends_on("oasis3-mct@access-esm1.5")

_platform = "spack"
with when("@access-esm1.6"):
depends_on("oasis3-mct@access-esm1.5+deterministic", when="+deterministic")
depends_on("oasis3-mct@access-esm1.5~deterministic", when="~deterministic")
depends_on("access-fms")
depends_on("access-generic-tracers")

phases = ["setup", "edit", "build", "install"]

# NOTE: The keys in the __builds variable are required to check whether
# a valid version was passed in by the user.
__builds = {
"access-om2": {"type": "ACCESS-OM", "gtracers": True},
"legacy-access-om2-bgc": {"type": "ACCESS-OM-BGC", "gtracers": False},
"access-esm1.5": {"type": "ACCESS-CM", "gtracers": False},
"access-esm1.6": {"type": "ACCESS-ESM", "gtracers": True}
}
__version = "INVALID"
__platform = "spack"

def url_for_version(self, version):
return "https://github.com/ACCESS-NRI/mom5/tarball/{0}".format(version)

# NOTE: This functionality will hopefully be implemented in the Spack core
# in the future. Till then, this approach can be used in other SPRs
# where this functionality is required.
def setup(self, spec, prefix):

if isinstance(self.version, GitVersion):
self.__version = self.version.ref_version.string
elif isinstance(self.version, StandardVersion):
self.__version = self.version.string
else:
print("ERROR: version=" + self.version.string)
raise ValueError

# The rest of the checks are only required if a __builds member
# variable exists
if self.__version not in self.__builds.keys():
print("ERROR: The version must be selected from: " +
", ".join(self.__builds.keys()))
raise ValueError

print("INFO: version=" + self.__version +
" type=" + self.__builds[self.__version]["type"] +
" gtracers=" + str(self.__builds[self.__version]["gtracers"]))

def edit(self, spec, prefix):

srcdir = self.stage.source_path
makeinc_path = join_path(srcdir, "bin", "mkmf.template.spack")
config = {}

# NOTE: The order of the libraries matters during the linking step!
if self.spec.satisfies("@access-esm1.5:access-esm1.6"):
if self.__version in ["access-esm1.5", "access-esm1.6"]:
istr = " ".join([
join_path((spec["oasis3-mct"].headers).cpp_flags, "psmile.MPI1"),
join_path((spec["oasis3-mct"].headers).cpp_flags, "mct")])
Expand All @@ -82,11 +129,12 @@ def edit(self, spec, prefix):
# TODO: https://github.com/ACCESS-NRI/ACCESS-OM/issues/12
FFLAGS_OPT = "-g3 -O2 -xCORE-AVX2 -debug all -check none -traceback"
CFLAGS_OPT = "-O2 -debug minimal -xCORE-AVX2"
if "+deterministic" in self.spec:
if self.spec.satisfies("+deterministic"):
FFLAGS_OPT = "-g0 -O0 -xCORE-AVX2 -debug none -check none"
CFLAGS_OPT = "-O0 -debug none -xCORE-AVX2"
print("INFO: +deterministic applied")

if self.spec.satisfies("+access-gtracers"):
if self.__builds[self.__version]["gtracers"]:
ideps.extend(["access-fms", "access-generic-tracers"])
ldeps.extend(["access-fms", "access-generic-tracers"])

Expand Down Expand Up @@ -175,7 +223,7 @@ def edit(self, spec, prefix):
"""

# Copied from bin/mkmf.template.nci
if self.spec.satisfies("@access-esm1.5:access-esm1.6"):
if self.__version in ["access-esm1.5", "access-esm1.6"]:
config["intel"] = f"""
ifeq ($(VTRACE), yes)
FC = mpifort-vt
Expand Down Expand Up @@ -311,7 +359,7 @@ def edit(self, spec, prefix):
# The `.replace()` apparently doesn't modify the object.
config["oneapi"] = config["intel"].replace("CFLAGS_REPRO := -fp-model precise -fp-model source", "CFLAGS_REPRO := -fp-model precise")

if self.spec.satisfies("@access-esm1.5:access-esm1.6"):
if self.__version in ["access-esm1.5", "access-esm1.6"]:
config["post"] = """
# you should never need to change any lines below.

Expand Down Expand Up @@ -497,24 +545,28 @@ def build(self, spec, prefix):
# ./MOM_compile.csh --type $mom_type --platform spack
with working_dir(join_path(self.stage.source_path, "exp")):
build = Executable("./MOM_compile.csh")
if "+restart_repro" in self.spec:

if self.spec.satisfies("+restart_repro"):
build.add_default_env("REPRO", "true")
print("INFO: +restart_repro applied")

if self.spec.satisfies("+access-gtracers"):
if self.__builds[self.__version]["gtracers"]:
build.add_default_env("SPACK_GTRACERS_EXTERNAL", "true")

if not self.spec.satisfies("@access-esm1.5"):
if self.__version != "access-esm1.5":
# The MOM5 commit d7ba13a3f364ce130b6ad0ba813f01832cada7a2
# requires the --no_version switch to avoid git hashes being
# embedded in the binary.
build.add_default_arg("--no_version")
if "+optimisation_report" in self.spec:
if self.spec.satisfies("+optimisation_report"):
build.add_default_env("REPORT", "true")
print("INFO: +optimisation_report applied")

build(
"--type",
self.spec.variants["type"].value,
self.__builds[self.__version]["type"],
"--platform",
self._platform,
self.__platform,
"--no_environ"
)

Expand All @@ -524,10 +576,10 @@ def install(self, spec, prefix):
install(
join_path(
"exec",
self._platform,
self.spec.variants["type"].value,
"fms_" + self.spec.variants["type"].value + ".x"
self.__platform,
self.__builds[self.__version]["type"],
"fms_" + self.__builds[self.__version]["type"] + ".x"
),
prefix.bin
)
install(join_path("bin", "mppnccombine." + self._platform), prefix.bin)
install(join_path("bin", "mppnccombine." + self.__platform), prefix.bin)