From afdc23338fc86838926ff93c8ccbcbba8db6475b Mon Sep 17 00:00:00 2001 From: Erik van Sebille Date: Thu, 17 Jul 2025 13:34:32 +0200 Subject: [PATCH 1/3] Create a benchmark for a very simple kernel loop --- benchmark_kernelloop.py | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 benchmark_kernelloop.py diff --git a/benchmark_kernelloop.py b/benchmark_kernelloop.py new file mode 100644 index 0000000..5162dd0 --- /dev/null +++ b/benchmark_kernelloop.py @@ -0,0 +1,37 @@ +import numpy as np +import parcels + +runtime = np.timedelta64(10, "D") +dt = np.timedelta64(30, "m") + +parcelsv4 = True +try: + from parcels._datasets.structured.generic import datasets as datasets_structured +except ImportError: + from tests.utils import create_fieldset_zeros_unit_mesh + parcelsv4 = False + +# create fieldset +if parcelsv4: + ds = datasets_structured["ds_2d_left"] + grid = parcels.xgrid.XGrid(parcels.xgcm.Grid(ds)) + U = parcels.Field("U", ds["U (A grid)"], grid, mesh_type="flat") + V = parcels.Field("V", ds["V (A grid)"], grid, mesh_type="flat") + fieldset = parcels.FieldSet([U, V]) +else: + fieldset = create_fieldset_zeros_unit_mesh() + +pclass = parcels.Particle if parcelsv4 else parcels.JITParticle + +# use a kernel that doesn't involve field access/interpolation +def DoNothing(particle, fieldset, time): + pass + +for npart in [1, 10, 100, 1000]: + lon = np.linspace(-10, 10, npart) + lat = np.linspace(-30, -20, npart) + + pset = parcels.ParticleSet(fieldset=fieldset, pclass=pclass, lon=lon, lat=lat) + + print(f"Running {len(lon)} particles with parcels v{4 if parcelsv4 else 3}") + pset.execute(DoNothing, runtime=runtime, dt=dt) From c1908cef3bcea8843e2244e6591e29adb57c01c0 Mon Sep 17 00:00:00 2001 From: Erik van Sebille Date: Fri, 18 Jul 2025 07:51:22 +0200 Subject: [PATCH 2/3] Updating npart range for more efficient testing --- benchmark_kernelloop.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/benchmark_kernelloop.py b/benchmark_kernelloop.py index 5162dd0..f1b7ad1 100644 --- a/benchmark_kernelloop.py +++ b/benchmark_kernelloop.py @@ -27,7 +27,7 @@ def DoNothing(particle, fieldset, time): pass -for npart in [1, 10, 100, 1000]: +for npart in [1, 10, 50, 100, 250, 500]: lon = np.linspace(-10, 10, npart) lat = np.linspace(-30, -20, npart) From 8f71341305752601de096dc0fa97f20ad7dc1d14 Mon Sep 17 00:00:00 2001 From: Erik van Sebille Date: Tue, 22 Jul 2025 17:11:01 +0200 Subject: [PATCH 3/3] Increasing kernelloop benchmarking to 10k particles --- benchmark_kernelloop.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/benchmark_kernelloop.py b/benchmark_kernelloop.py index f1b7ad1..b2f5f1c 100644 --- a/benchmark_kernelloop.py +++ b/benchmark_kernelloop.py @@ -27,7 +27,7 @@ def DoNothing(particle, fieldset, time): pass -for npart in [1, 10, 50, 100, 250, 500]: +for npart in [1, 10, 100, 1000, 10000]: lon = np.linspace(-10, 10, npart) lat = np.linspace(-30, -20, npart)