-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add helper functions to run specifc profiling analysis, starting with…
… parallel scaling.
- Loading branch information
1 parent
191c370
commit 7bba5f8
Showing
4 changed files
with
84 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
from pathlib import Path | ||
import xarray as xr | ||
|
||
from om3utils.payu_config_yaml import read_payu_config_yaml | ||
|
||
|
||
def scaling_ncpus(run_dir): | ||
config_file = Path(run_dir) / "config.yaml" | ||
config = read_payu_config_yaml(config_file.as_posix()) | ||
return config["ncpus"] | ||
|
||
|
||
def scaling_speedup(stats: xr.Dataset) -> xr.Dataset: | ||
speedup = stats.tavg.sel(ncpus=stats["ncpus"].min()) / stats.tavg | ||
speedup.name = "speedup" | ||
return speedup | ||
|
||
|
||
def scaling_efficiency(stats: xr.Dataset) -> xr.Dataset: | ||
speedup = scaling_speedup(stats) | ||
eff = speedup / speedup.ncpus * 100 * stats["ncpus"].min() | ||
eff.name = "parallel efficiency [%]" | ||
return eff |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import pytest | ||
import xarray as xr | ||
|
||
|
||
@pytest.fixture() | ||
def profiling_data(): | ||
regions = ["Total runtime", "Ocean Initialization"] | ||
ncpus = [1, 2, 4] | ||
hits = [] | ||
tmin = [] | ||
tmax = [] | ||
tavg = [] | ||
for n in ncpus: | ||
hits.append([1, 2]) | ||
tmin.append([value / min(n, 2) for value in [138.600364, 2.344926]]) | ||
tmax.append([value / min(n, 2) for value in [138.600366, 2.345701]]) | ||
tavg.append([value / min(n, 2) for value in [600365, 2.345388]]) | ||
|
||
return regions, ncpus, hits, tmin, tmax, tavg | ||
|
||
|
||
@pytest.fixture() | ||
def simple_scaling_data(profiling_data): | ||
regions, ncpus, hits, tmin, tmax, tavg = profiling_data | ||
|
||
return xr.Dataset( | ||
data_vars=dict( | ||
hits=(["ncpus", "region"], hits), | ||
tmin=(["ncpus", "region"], tmin), | ||
tmax=(["ncpus", "region"], tmax), | ||
tavg=(["ncpus", "region"], tavg), | ||
), | ||
coords=dict(region=regions, ncpus=ncpus), | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import pytest | ||
|
||
from om3utils.profiling_analyses import scaling_ncpus, scaling_speedup, scaling_efficiency | ||
|
||
|
||
@pytest.fixture() | ||
def scaling_run_dir(tmp_path): | ||
file = tmp_path / "config.yaml" | ||
file.write_text("ncpus: 4") | ||
|
||
|
||
def test_scaling_ncpus(tmp_path, scaling_run_dir): | ||
ncpus = scaling_ncpus(tmp_path) | ||
|
||
assert ncpus == 4 | ||
|
||
|
||
def test_scaling_speedup(simple_scaling_data): | ||
speedup = scaling_speedup(simple_scaling_data) | ||
|
||
assert (speedup.sel(region="Total runtime").values[:] == [1.0, 2.0, 2.0]).all() | ||
|
||
|
||
def test_efficiency(simple_scaling_data): | ||
efficiency = scaling_efficiency(simple_scaling_data) | ||
|
||
assert (efficiency.sel(region="Total runtime").values[:] == [100.0, 100.0, 50.0]).all() |