-
Notifications
You must be signed in to change notification settings - Fork 7
Add default CICE5 builds when using CMake #383
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 3 commits
3c4c286
8c74a88
1cc3b88
1195201
68ebf7e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,13 +7,27 @@ | |
| from spack_repo.builtin.build_systems.makefile import MakefilePackage | ||
| from spack.package import * | ||
|
|
||
| # These are the default layouts, inc 3 executables for OM2 | ||
| # alternatively, supply the 5 layouts variant to produce 1 executable | ||
| OM2_LAYOUTS = [ | ||
| {"nxglob": "360", "nyglob": "300", "blckx": "15", "blcky": "300", "mxblcks": "1"}, | ||
| {"nxglob": "1440", "nyglob": "1080", "blckx": "30", "blcky": "27", "mxblcks": "4"}, | ||
| {"nxglob": "3600", "nyglob": "2700", "blckx": "40", "blcky": "30", "mxblcks": "12"}, | ||
| ] | ||
| ESM1P6_LAYOUTS = [ | ||
| {"nxglob": "360", "nyglob": "300", "blckx": "30", "blcky": "300", "mxblcks": "1"}, | ||
| ] | ||
|
|
||
|
|
||
| def _int_validator(s): | ||
| """Test a string variant is a valid integer """ | ||
| if (s.isdigit() and int(s) > 0): | ||
| return True | ||
| else: | ||
| print(f"ERROR: {s} not a valid integer") | ||
| return False | ||
| if (s != "none"): | ||
| if (s.isdigit() and int(s) > 0): | ||
| return True | ||
| else: | ||
| print(f"ERROR: {s} not a valid integer") | ||
| return False | ||
|
|
||
|
|
||
| class Cice5(CMakePackage, MakefilePackage): | ||
| """The Los Alamos sea ice model (CICE) is the result of an effort to develop | ||
|
|
@@ -32,7 +46,7 @@ class Cice5(CMakePackage, MakefilePackage): | |
| version("access-om2", branch="master") | ||
| version("access-esm1.6", branch="access-esm1.6") | ||
|
|
||
| # by default, keep existing processor layout defined in makefile | ||
| # by default, keep existing processor layout | ||
| # if nxglob, nyglob, blckx, blcky, mxblcks are supplied, then spack will switch to cmake | ||
| build_system("makefile", "cmake", default="makefile") | ||
|
|
||
|
|
@@ -113,26 +127,84 @@ class Cice5(CMakePackage, MakefilePackage): | |
| depends_on("libaccessom2+deterministic", when="+deterministic") | ||
| depends_on("libaccessom2~deterministic", when="~deterministic") | ||
|
|
||
|
|
||
| class CMakeBuilder(cmake.CMakeBuilder): | ||
|
|
||
| phases = ["set_layouts", "cmake", "build", "install"] | ||
|
|
||
| def cmake_args(self): | ||
| """List of the arguments that must be passed to cmake""" | ||
| # set cmake args based on the values in _layout, cmake_args is called during super().cmake() | ||
| if self.spec.variants["model"].value == "access-esm1.6": | ||
| args = [self.define("CICE_DRIVER", "access")] | ||
| else: # access-om2 | ||
| args = [self.define("CICE_DRIVER", "auscom")] | ||
|
|
||
| args.extend([ | ||
| self.define("CICE_NXGLOB", self._layout['nxglob']), | ||
| self.define("CICE_NYGLOB", self._layout['nyglob']), | ||
| self.define("CICE_BLCKX", self._layout['blckx']), | ||
| self.define("CICE_BLCKY", self._layout['blcky']), | ||
| self.define("CICE_MXBLCKS", self._layout['mxblcks']), | ||
| self.define_from_variant("CICE_IO", "io_type"), | ||
| self.define_from_variant("CICE_NXGLOB", "nxglob"), | ||
| self.define_from_variant("CICE_NYGLOB", "nyglob"), | ||
| self.define_from_variant("CICE_BLCKX", "blckx"), | ||
| self.define_from_variant("CICE_BLCKY", "blcky"), | ||
| self.define_from_variant("CICE_MXBLCKS", "mxblcks"), | ||
| self.define_from_variant("CICE_DETERMINISTIC", "deterministic"), | ||
| ]) | ||
|
|
||
| return args | ||
|
|
||
| def set_layouts(self, pkg, spec, prefix): | ||
| """Layout of cice processors to use. If variants are set, use those. | ||
| Otherwise, use defaults.""" | ||
| layout_variants = OM2_LAYOUTS[0].keys() | ||
|
|
||
| # if all 5 layouts variants are available, set the layouts dict | ||
| if all([ | ||
| self.spec.variants[variant].value != 'none' | ||
| for variant in layout_variants | ||
| ]): | ||
|
Comment on lines
+179
to
+182
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It would be clearer that this is a list comprehension if the square brackets are immediately at the start and end of the list comprehension. |
||
| layouts = [{variant: self.spec.variants[variant].value | ||
| for variant in layout_variants}] | ||
| # else if no layout variants are available, use the defaults | ||
| elif all([ | ||
| self.spec.variants[variant].value == 'none' | ||
| for variant in layout_variants | ||
| ]): | ||
|
Comment on lines
+186
to
+189
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It would be clearer that this is a list comprehension if the square brackets are immediately at the start and end of the list comprehension. |
||
| if self.spec.variants["model"].value == "access-esm1.6": | ||
| layouts = ESM1P6_LAYOUTS | ||
| else: | ||
| layouts = OM2_LAYOUTS | ||
| else: | ||
| raise Error(f"All of {layout_variants} " | ||
| "variants must be set if any are set") | ||
|
|
||
| self._all_layouts = layouts | ||
|
|
||
| @property | ||
| def build_dirname(self) -> str: | ||
| """Directory name to use when building the package. """ | ||
| # We modify this to ensure uniqueness with multiple builds | ||
| build = ( | ||
| f"{self._layout['nxglob']}x{self._layout['nyglob']}_" | ||
| f"{self._layout['blckx']}x{self._layout['blcky']}_" | ||
| f"{self._layout['mxblcks']}" | ||
| ) | ||
| return f"{super().build_dirname}/{build}" | ||
|
|
||
| def cmake(self, pkg, spec, prefix): | ||
| for layout in self._all_layouts: | ||
| self._layout = layout | ||
| super().cmake(pkg, spec, prefix) | ||
|
|
||
| def build(self, pkg, spec, prefix): | ||
| for layout in self._all_layouts: | ||
| self._layout = layout | ||
| super().build(pkg, spec, prefix) | ||
|
|
||
| def install(self, pkg, spec, prefix): | ||
| for layout in self._all_layouts: | ||
| self._layout = layout | ||
| super().install(pkg, spec, prefix) | ||
|
|
||
|
|
||
| class MakefileBuilder(makefile.MakefileBuilder): | ||
|
|
||
|
|
@@ -217,7 +289,6 @@ def set_deps_targets(self, pkg, spec, prefix): | |
|
|
||
| self.__deps["ldflags"] = " ".join([lstr] + [self.get_linker_args(spec, d) for d in ldeps]) | ||
|
|
||
|
|
||
| def edit(self, pkg, spec, prefix): | ||
|
|
||
| srcdir = self.stage.source_path | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.