From 25c8c31a685d677437e1f5bd959776d781c7910e Mon Sep 17 00:00:00 2001 From: anton-seaice Date: Wed, 18 Sep 2024 16:00:31 +1000 Subject: [PATCH] review comments & PEP --- payu/models/cesm_cmeps.py | 16 +++++++++++++--- test/models/access-om3/test_access_om3.py | 13 ++++++++----- 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/payu/models/cesm_cmeps.py b/payu/models/cesm_cmeps.py index 06d4d65b..cb0ee695 100644 --- a/payu/models/cesm_cmeps.py +++ b/payu/models/cesm_cmeps.py @@ -198,10 +198,10 @@ def _setup_checks(self): if nthreads < 1: raise ValueError(f"The number of {realm}_nthreads ({nthreads}) in " f"{NUOPC_CONFIG} must be at least 1.") - + if nthreads > 1: npes = nthreads*ntasks*pestride - # this is taken from + # this is taken from # https://github.com/ESCOMP/CMEPS/blob/5b7d76978e2fdc661ec2de4ba9834b985decadc6/cesm/driver/esm.F90#L1007 # the correct calculation might be (ntasks-1)*pestride*nthreads + nthreads else: @@ -242,7 +242,17 @@ def _setup_checks(self): case "netcdf4p" | "pnetcdf": niotasks = int(self.runconfig.get(io_section, "pio_numiotasks")) iostride = int(self.runconfig.get(io_section, "pio_stride")) - if (ioroot + (niotasks-1)*iostride) >= npes: + if (niotasks<=0) : + warn(f"The pio_numiotasks for {io_section} in {NUOPC_CONFIG} is " + "not set, using model default") + if (iostride<=0) : + warn(f"The pio_stride for {io_section} in {NUOPC_CONFIG} is " + "not set, using model default") + if (all( + niotasks>0, + iostride>0, + ioroot + (niotasks-1)*iostride) >= npes + ): raise ValueError( f"The iolayout for {io_section} in {NUOPC_CONFIG} is " "requesting out of range cpus" diff --git a/test/models/access-om3/test_access_om3.py b/test/models/access-om3/test_access_om3.py index ee480a4a..cf1e714b 100644 --- a/test/models/access-om3/test_access_om3.py +++ b/test/models/access-om3/test_access_om3.py @@ -249,10 +249,11 @@ def test__setup_checks_bad_io(ncpu, pio_numiotasks, pio_stride, pio_root, pio_ty teardown_cmeps_config() + @pytest.mark.parametrize("pio_typename, pio_async_interface", [ - ("netcdf4p", ".true."), - ("pnetcdf", ".true."), - ("netcdf", ".true."), + ("netcdf4p", ".true."), + ("pnetcdf", ".true."), + ("netcdf", ".true."), ]) def test__setup_checks_pio_async(pio_typename, pio_async_interface): @@ -273,7 +274,9 @@ def test__setup_checks_pio_async(pio_typename, pio_async_interface): model.runconfig = MockRunConfig(test_runconf) - with pytest.warns(Warning, match = "does not do consistency checks for asynchronous pio"): + with pytest.warns( + Warning, match="does not do consistency checks for asynchronous pio" + ): model._setup_checks() teardown_cmeps_config() @@ -305,4 +308,4 @@ def test__setup_checks_not_pio_async(pio_typename, pio_async_interface): model._setup_checks() - teardown_cmeps_config() \ No newline at end of file + teardown_cmeps_config()