-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add parallel example script using ZarrMonitor (#126)
This example script serves both as usage documentation, and as a basic parallel test of the ZarrMonitor.
- Loading branch information
Jeremy McGibbon
authored
Aug 26, 2020
1 parent
3b25427
commit 3254904
Showing
6 changed files
with
61 additions
and
7 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
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 @@ | ||
output |
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,14 @@ | ||
|
||
MPI_ENV_VARS=PMIX_MCA_gds=hash | ||
|
||
all: global_timings zarr_monitor | ||
|
||
global_timings: | ||
$(MPI_ENV_VARS) mpirun -n 4 python -m mpi4py global_timings.py | ||
|
||
zarr_monitor: | ||
$(MPI_ENV_VARS) mpirun -n 6 python -m mpi4py zarr_monitor.py | ||
|
||
clean: | ||
$(RM) -r output/* | ||
touch output/.gitkeep |
File renamed without changes.
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,41 @@ | ||
import fv3gfs.util | ||
from mpi4py import MPI | ||
import numpy as np | ||
from datetime import timedelta | ||
import cftime | ||
import zarr | ||
|
||
OUTPUT_PATH = "output/zarr_monitor.zarr" | ||
|
||
|
||
def get_example_state(time): | ||
sizer = fv3gfs.util.SubtileGridSizer( | ||
nx=48, ny=48, nz=70, n_halo=3, extra_dim_lengths={} | ||
) | ||
allocator = fv3gfs.util.QuantityFactory(sizer, np) | ||
air_temperature = allocator.zeros( | ||
[fv3gfs.util.X_DIM, fv3gfs.util.Y_DIM, fv3gfs.util.Z_DIM], units="degK" | ||
) | ||
air_temperature.view[:] = np.random.randn(*air_temperature.extent) | ||
return {"time": time, "air_temperature": air_temperature} | ||
|
||
|
||
if __name__ == "__main__": | ||
size = MPI.COMM_WORLD.Get_size() | ||
# assume square tile faces | ||
ranks_per_edge = int((size // 6) ** 0.5) | ||
layout = (ranks_per_edge, ranks_per_edge) | ||
|
||
store = zarr.storage.DirectoryStore(OUTPUT_PATH) | ||
partitioner = fv3gfs.util.CubedSpherePartitioner( | ||
fv3gfs.util.TilePartitioner(layout) | ||
) | ||
monitor = fv3gfs.util.ZarrMonitor(store, partitioner, mpi_comm=MPI.COMM_WORLD) | ||
|
||
time = cftime.DatetimeJulian(2020, 1, 1) | ||
timestep = timedelta(hours=1) | ||
|
||
for i in range(10): | ||
state = get_example_state(time) | ||
monitor.store(state) | ||
time += timestep |
This file was deleted.
Oops, something went wrong.