Skip to content

Commit ae1c543

Browse files
Adding preloading to CLI
1 parent 4067f4c commit ae1c543

1 file changed

Lines changed: 17 additions & 9 deletions

File tree

MOi-Curvilinear/benchmark_moi_curvilinear.py

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,15 @@
2323

2424
DATA_ROOT = "/storage/shared/oceanparcels/input_data/MOi"
2525

26-
def run_benchmark(interpolator: str, trace_memory: bool = False, surface_simulation: bool =False, cycle_chunks: bool = False):
26+
def run_benchmark(interpolator: str, trace_memory: bool = False, surface_simulation: bool =False, preload: bool = False, cycle_chunks: bool = False):
2727

2828
lon0_expected, lat0_expected = -10.128929, -29.721205 # values from v3 using from_netcf (so assuming A-grid!)
2929

3030
if cycle_chunks:
3131
xy_chunks = [64, 128, 256, 512, 1024, 2084, 32, 16, 8, 4]
3232
nparts = [10_000]
3333
else:
34-
xy_chunks = ["auto"]
34+
xy_chunks = [256]
3535
nparts = [1, 10, 100, 1_000, 5_000, 10_000, 50_000, 100_000, 500_000, 1_000_000]
3636
fileU = f"{DATA_ROOT}/GLO12/psy4v3r1-daily_U_2010-01-0[1-3].nc"
3737
filenames = {"U": glob(fileU), "V": glob(fileU.replace("_U_", "_V_")), "W": glob(fileU.replace("_U_", "_W_"))}
@@ -49,8 +49,9 @@ def run_benchmark(interpolator: str, trace_memory: bool = False, surface_simulat
4949
"data_vars": 'minimal',
5050
"coords": 'minimal',
5151
"compat": 'override',
52-
"chunks": {"time_counter": 1, "depth":2, "y": chunk, "x": chunk}
5352
}
53+
if chunk:
54+
fileargs["chunks"] = {"time_counter": 1, "depth":2, "y": chunk, "x": chunk}
5455

5556
ds_u = xr.open_mfdataset(filenames["U"], **fileargs)[["vozocrtx"]].drop_vars(["nav_lon", "nav_lat"])
5657
ds_v = xr.open_mfdataset(filenames["V"], **fileargs)[["vomecrty"]].drop_vars(["nav_lon", "nav_lat"])
@@ -104,6 +105,10 @@ def run_benchmark(interpolator: str, trace_memory: bool = False, surface_simulat
104105

105106
pclass = parcels.Particle if parcelsv4 else parcels.JITParticle
106107

108+
if parcelsv4 and preload:
109+
fieldset.U.data.load()
110+
fieldset.V.data.load()
111+
107112
for npart in nparts:
108113
if cycle_chunks:
109114
X, Y = np.meshgrid(np.linspace(-10, 10, int(np.sqrt(npart))), np.linspace(-30, -20, int(np.sqrt(npart))))
@@ -115,17 +120,13 @@ def run_benchmark(interpolator: str, trace_memory: bool = False, surface_simulat
115120

116121
pset = parcels.ParticleSet(fieldset=fieldset, pclass=pclass, lon=lon, lat=lat)
117122

118-
print(f"Running {len(lon):_} particles on {"surface" if surface_simulation else "3D"} with parcels v{4 if parcelsv4 else 3}, chunksize {chunk} and {interpolator} interpolator")
123+
print(f"Running {len(lon):_} particles on {"surface" if surface_simulation else "3D"} with parcels v{4 if parcelsv4 else 3}, chunksize {chunk} ({'preloaded' if preload else 'not preloaded'}) and {interpolator} interpolator")
119124

120125
if trace_memory:
121126
tracemalloc.start()
122127
else:
123128
start = time.time()
124129

125-
# if surface_simulation and parcelsv4:
126-
# fieldset.U.data.load()
127-
# fieldset.V.data.load()
128-
129130
pset.execute(parcels.AdvectionEE, runtime=runtime, dt=dt, verbose_progress=False)
130131

131132
if trace_memory:
@@ -167,6 +168,13 @@ def main(args=None):
167168
help="Run surface simulation with only 1 or 2 depth levels (default: False)",
168169
)
169170

171+
p.add_argument(
172+
"-l",
173+
"--preload",
174+
action="store_true",
175+
help="Preload data into memory (default: False)",
176+
)
177+
170178
p.add_argument(
171179
"-c",
172180
"--chunks",
@@ -175,7 +183,7 @@ def main(args=None):
175183
)
176184

177185
args = p.parse_args(args)
178-
run_benchmark(args.Interpolator, args.memory, args.surface, args.chunks)
186+
run_benchmark(args.Interpolator, args.memory, args.surface, args.preload, args.chunks)
179187

180188

181189
if __name__ == "__main__":

0 commit comments

Comments
 (0)