Skip to content

Read a NetCDF DEM in bands instead of as a whole - #200

Open
BenjaminRodenberg wants to merge 7 commits into
mainfrom
dem-banded-read
Open

BenjaminRodenberg wants to merge 7 commits into
mainfrom
dem-banded-read

Conversation

@BenjaminRodenberg

@BenjaminRodenberg BenjaminRodenberg commented Oct 20, 2026 •

Copy link
Copy Markdown
Collaborator

read_dem loaded the whole surface variable, about 750 MB for BedMachineGreenland-v5.nc, before sampling it at the cell centres. It now reads bands of at most 4M values, and of each band only the window around the points it samples. A single bounding box does not help: the cells of the Greenland mesh span nearly the whole DEM.

Peak RSS after grid initialization on the Greenland mesh with the full-resolution DEM drops from about 1.1 GB to about 0.3 GB. Results are unchanged.

Assisted-by: Claude Code:claude-opus-5-5

Author's Todos

  • I ran the pre-commit hooks and fixed all issues
  • I added an entry under develop in the CHANGELOG.md (may be skipped for minor changes not observable for the user)

@BenjaminRodenberg BenjaminRodenberg self-assigned this Oct 20, 2026
@BenjaminRodenberg BenjaminRodenberg added the enhancement New feature or request label Oct 20, 2026
@BenjaminRodenberg

Copy link
Copy Markdown
Collaborator Author

This is a performance optimization that is mostly useful in the context of #197. I will keep this separate and unmerged for now because it is independent and still needs evaluation. #197 is already large enough.

@BenjaminRodenberg BenjaminRodenberg added this to the v0.9.0 milestone Oct 20, 2026
setup-mpi makes Open MPI use TCP between ranks, and on GitHub's
runners Open MPI's TCP transport also picks the docker0 interface,
over which messages never arrive. Small messages still get through,
but large ones hang: in #197 a gather on 4 ranks hung until GitHub's
limit of 6 hours, while the same run passed locally, where the ranks
use shared memory. The next commits run the MATLAB example on up to
4 ranks, with gathers large enough to hang.

Open MPI now only uses the loopback interface in both workflows. It
is set in mca-params.conf, since tox does not pass OMPI_MCA_*
variables to the tests. In addition, the build-and-test job now stops
after 20 minutes and its MPI steps after 5, so a hang fails quickly
instead of blocking a runner for 6 hours.

Taken from 5e28f4d and 47b4c8f of #197.

Assisted-by: Claude Code:claude-opus-5-5
MATLAB and NetCDF grids now keep the flat indices of their columns in
the 2-D fields as `ind` and take every per-column field from the 2-D
fields with them, instead of applying the mask to each field again.
A subset of the columns then only needs a subset of `ind`, which the
next commits use to split a MATLAB grid over MPI ranks.

The columns, their order and the model output are unchanged.

Assisted-by: Claude Code:claude-opus-5-5
The output writer now gathers the columns of all ranks with
ColumnGather and rank 0 writes them to the file a single rank would
write, one variable at a time to limit its memory. Only structured
grids are gathered; a partitioned mesh still skips the output file.

Taken from 8b5a9eb of #197.

Assisted-by: Claude Code:claude-opus-5-5
The shading look-up table is computed by walking from every glacier
cell of the 2-D grid, not only from the columns of one rank, so a
rank holding part of the columns cannot build its rows of the table.
Shading on several ranks is now a usage error asking for --no-shading,
and _precompute_shading_matlab asserts that it is not called in such
a run.

No grid that supports shading runs on several ranks yet; the next
commits split MATLAB grids over the ranks.

Taken from 43a676e of #197.

Assisted-by: Claude Code:claude-opus-5-5
On several ranks, each rank now computes a contiguous block of the
columns of a MATLAB grid, the first block on rank 0. The 2-D fields
stay whole on every rank: the slope needs the neighbours of each cell,
and the output writer places the columns of all ranks into them.

The domain-wide latitude mean, lapse rate and random seed of #203 make
the results equal those of a single rank.

Taken from 46f47a2 of #197.

Assisted-by: Claude Code:claude-opus-5-5
The MATLAB example runs for one day on a single rank and on 2, 3 and
4 ranks under mpirun; each parallel run must give a byte-identical
output file and an equal --dump-reference snapshot. CI also runs the
MATLAB example on 4 ranks.

Taken from db2b582 and e26d3e8 of #197.

Assisted-by: Claude Code:claude-opus-5-5
read_dem loaded the whole surface variable, about 750 MB for
BedMachineGreenland-v5.nc, before sampling it at the cell centres. It
now reads bands of at most 4M values, and of each band only the window
around the points it samples. A single bounding box does not help:
the cells of the Greenland mesh span nearly the whole DEM.

Peak RSS after grid initialization on the Greenland mesh with the
full-resolution DEM drops from about 1.1 GB to about 0.3 GB. Results
are unchanged.

Assisted-by: Claude Code:claude-opus-5-5

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant