-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathpackage.py
165 lines (128 loc) · 5.33 KB
/
package.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
# 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
#
# SPDX-License-Identifier: (Apache-2.0 OR MIT)
# Based on packages/cice5/package.py and other sources noted below.
from spack.package import install, join_path, mkdirp
# https://spack.readthedocs.io/en/latest/build_systems/makefilepackage.html
class Cice4(MakefilePackage):
"""The Los Alamos sea ice model (CICE) is the result of an effort to develop a computationally efficient sea ice component for a fully coupled atmosphere-land global climate model."""
homepage = "https://www.access-nri.org.au"
git = "https://github.com/ACCESS-NRI/cice4.git"
maintainers("penguian")
version("access-esm1.5", branch="access-esm1.5")
depends_on("[email protected]:")
depends_on("openmpi")
depends_on("oasis3-mct")
phases = ["edit", "build", "install"]
_buildscript = "spack-build.sh"
_buildscript_path = join_path("bld", _buildscript)
# The integer represents environment variable NTASK
__targets = {12: {}, }
__targets[12]["driver"] = "access"
__targets[12]["grid"] = "360x300"
__targets[12]["blocks"] = "12x1"
# The reason for the explicit -rpath is:
# https://github.com/ACCESS-NRI/spack-packages/issues/14#issuecomment-1653651447
def get_linker_args(self, spec, name):
return " ".join(
[(spec[name].libs).ld_flags,
"-Wl,-rpath=" + join_path(spec[name].prefix, "lib")]
)
def edit(self, spec, prefix):
srcdir = self.stage.source_path
buildscript_dest = join_path(srcdir, self._buildscript_path)
makeinc_path = join_path(srcdir, "bld", "Macros.spack")
copy(join_path(self.package_dir, self._buildscript), buildscript_dest)
config = {}
istr = " ".join([
join_path((spec["oasis3-mct"].headers).cpp_flags, "psmile.MPI1"),
join_path((spec["oasis3-mct"].headers).cpp_flags, "mct")])
ideps = ["netcdf-fortran"]
incs = " ".join([istr] + [(spec[d].headers).cpp_flags for d in ideps])
lstr = ""
ldeps = ["oasis3-mct", "netcdf-fortran"]
libs = " ".join([lstr] + [self.get_linker_args(spec, d) for d in ldeps])
CFLAGS = "-c -O2"
# Based on https://github.com/coecms/access-esm-build-gadi/blob/master/patch/Macros.Linux.raijin.nci.org.au-mct
config["pre"] = f"""
INCLDIR := -I. {incs}
SLIBS := {libs}
ULIBS :=
CPP := cpp
FC := mpif90
CPPFLAGS := -P -traditional
CPPDEFS := -DLINUX -DPAROPT
CFLAGS := {CFLAGS}
FIXEDFLAGS := -132
FREEFLAGS :=
"""
# based on packages/cice5/package.py (FFLAGS)
# and https://github.com/coecms/access-esm-build-gadi/blob/master/patch/Macros.Linux.raijin.nci.org.au-mct (LDFLAGS)
config["gcc"] = """
FFLAGS = -Wall -fdefault-real-8 -fdefault-double-8 -ffpe-trap=invalid,zero,overflow -fallow-argument-mismatch
LDFLAGS := $(FFLAGS)
"""
# Based on https://github.com/coecms/access-esm-build-gadi/blob/master/patch/Macros.Linux.raijin.nci.org.au-mct
config["intel"] = """
ifeq ($(DEBUG), yes)
FFLAGS := -r8 -i4 -O0 -g -align all -w -ftz -convert big_endian -assume byterecl -no-vec -xCORE-AVX2 -fp-model precise
else
FFLAGS := -r8 -i4 -O2 -align all -w -ftz -convert big_endian -assume byterecl -no-vec -xCORE-AVX512 -fp-model precise
endif
LDFLAGS := $(FFLAGS) -v -static-intel
"""
# Add support for the ifx compiler
config["oneapi"] = config["intel"]
# Based on https://github.com/ACCESS-NRI/cice4/blob/access-esm1.5/bld/Macros.nci
config["post"] = """
MOD_SUFFIX := mod
LD := $(FC)
CPPDEFS := $(CPPDEFS) -DNXGLOB=$(NXGLOB) -DNYGLOB=$(NYGLOB) -DN_ILYR=$(N_ILYR) \
-DBLCKX=$(BLCKX) -DBLCKY=$(BLCKY) -DMXBLCKS=$(MXBLCKS)
ifeq ($(DITTO), yes)
CPPDEFS := $(CPPDEFS) -DREPRODUCIBLE
endif
ifeq ($(NETCDF), yes)
CPPDEFS := $(CPPDEFS) -Dncdf
endif
ifeq ($(USE_ESMF), yes)
CPPDEFS := $(CPPDEFS) -Duse_esmf
endif
ifeq ($(AusCOM), yes)
CPPDEFS := $(CPPDEFS) -DAusCOM -Dcoupled
endif
ifeq ($(UNIT_TESTING), yes)
CPPDEFS := $(CPPDEFS) -DUNIT_TESTING
endif
ifeq ($(ACCESS), yes)
CPPDEFS := $(CPPDEFS) -DACCESS
endif
ifeq ($(OASIS3_MCT), yes)
CPPDEFS := $(CPPDEFS) -DOASIS3_MCT
endif
"""
fullconfig = config["pre"] + config[self.compiler.name] + config["post"]
print(fullconfig)
with open(makeinc_path, "w") as makeinc:
makeinc.write(fullconfig)
def build(self, spec, prefix):
build = Executable(
join_path(self.stage.source_path, self._buildscript_path)
)
for k in self.__targets:
build(self.__targets[k]["driver"],
self.__targets[k]["grid"],
self.__targets[k]["blocks"],
str(k))
def install(self, spec, prefix):
mkdirp(prefix.bin)
for k in self.__targets:
name = "_".join([self.__targets[k]["driver"],
self.__targets[k]["grid"],
self.__targets[k]["blocks"],
str(k) + "p"])
install(join_path("build_" + name, "cice_" + name + ".exe"),
prefix.bin)