Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
maddenp-noaa committed Jul 22, 2024
1 parent b309d80 commit aadabfa
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
9 changes: 5 additions & 4 deletions docs/sections/user_guide/yaml/execution.rst
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ Example block:
stderr: /path/to/runscript.err
stdout: /path/to/runscript.out
tasks_per_node: 40
threads: 8
walltime: 00:02:00
envcmds:
- module use /path/to/modulefiles
Expand All @@ -44,9 +43,11 @@ These entries map to job-scheduler directives sent to e.g. Slurm when a batch jo

Shorthand names are provided for certain directives for each scheduler, and can be specified as-so along with appropriate values. Recognized names for each scheduler are:

* LSF: ``jobname``, ``memory``, ``nodes``, ``queue``, ``shell``, ``stdout``, ``tasks_per_node``, ``threads``, ``walltime``
* PBS: ``debug``, ``jobname``, ``memory``, ``nodes``, ``queue``, ``shell``, ``stdout``, ``tasks_per_node``, ``threads``, ``walltime``
* Slurm: ``cores``, ``exclusive``, ``export``, ``jobname``, ``memory``, ``nodes``, ``partition``, ``queue``, ``rundir``, ``stderr``, ``stdout``, ``tasks_per_node``, ``threads``, ``walltime``
* LSF: ``jobname``, ``memory``, ``nodes``, ``queue``, ``shell``, ``stdout``, ``tasks_per_node``, ``walltime``
* PBS: ``debug``, ``jobname``, ``memory``, ``nodes``, ``queue``, ``shell``, ``stdout``, ``tasks_per_node``, ``walltime``
* Slurm: ``cores``, ``exclusive``, ``export``, ``jobname``, ``memory``, ``nodes``, ``partition``, ``queue``, ``rundir``, ``stderr``, ``stdout``, ``tasks_per_node``, ``walltime``

**NB** To arrange for the ``OMP_NUM_THREADS`` environment variable to be set in the execution environment of components compiled with OpenMP support, set the ``execution:`` block's ``threads:`` child item. Drivers with appropriate support will set ``OMP_NUM_THREADS`` as well as the corresponding scheduler flag when making a batch-resource request.

Other, arbitrary directive key-value pairs can be provided exactly as they should appear in the batch runscript. For example

Expand Down
6 changes: 5 additions & 1 deletion src/uwtools/drivers/driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -456,9 +456,13 @@ def _write_runscript(self, path: Path, envvars: Optional[dict[str, str]] = None)
Write the runscript.
"""
path.parent.mkdir(parents=True, exist_ok=True)
envvars = envvars or {}
threads = self._driver_config.get("execution", {}).get("threads")
if threads and "OMP_NUM_THREADS" not in envvars:
raise UWConfigError("Config specified threads but driver does not set OMP_NUM_THREADS")
rs = self._runscript(
envcmds=self._driver_config.get("execution", {}).get("envcmds", []),
envvars=envvars or {},
envvars=envvars,
execution=[
"time %s" % self._runcmd,
"test $? -eq 0 && touch %s" % self._runscript_done_file,
Expand Down
8 changes: 8 additions & 0 deletions src/uwtools/tests/drivers/test_driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -545,6 +545,14 @@ def test_Driver__write_runscript(driverobj):
assert actual.strip() == dedent(expected).strip()


def test_Driver__write_runscript_threads_fail(driverobj):
path = Path(driverobj._driver_config["rundir"]) / "runscript"
driverobj._driver_config["execution"]["threads"] = 4
with raises(UWConfigError) as e:
driverobj._write_runscript(path=path)
assert str(e.value) == "Config specified threads but driver does not set OMP_NUM_THREADS"


def test__add_docstring():
class C:
pass
Expand Down

0 comments on commit aadabfa

Please sign in to comment.