Skip to content

Commit f4fa1e9

Browse files
Skip Kernel execution when no particles need to be executed
1 parent 56314f7 commit f4fa1e9

1 file changed

Lines changed: 9 additions & 3 deletions

File tree

parcels/particleset.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -944,6 +944,11 @@ def execute(self, pyfunc=AdvectionRK4, pyfunc_inter=None, endtime=None, runtime=
944944

945945
tol = 1e-12
946946
while (time < endtime and dt > 0) or (time > endtime and dt < 0) or dt == 0:
947+
# Check if we can fast-forward to the next time needed for the particles
948+
if dt > 0:
949+
skip_kernel = True if min(self.time) > (time + dt) else False
950+
else:
951+
skip_kernel = True if max(self.time) < (time + dt) else False
947952
time_at_startofloop = time
948953

949954
if dt > 0:
@@ -953,9 +958,10 @@ def execute(self, pyfunc=AdvectionRK4, pyfunc_inter=None, endtime=None, runtime=
953958

954959
# If we don't perform interaction, only execute the normal kernel efficiently.
955960
if self.interaction_kernel is None:
956-
res = self.kernel.execute(self, endtime=next_time, dt=dt)
957-
if res == StatusCode.StopAllExecution:
958-
return StatusCode.StopAllExecution
961+
if not skip_kernel:
962+
res = self.kernel.execute(self, endtime=next_time, dt=dt)
963+
if res == StatusCode.StopAllExecution:
964+
return StatusCode.StopAllExecution
959965
# Interaction: interleave the interaction and non-interaction kernel for each time step.
960966
# E.g. Normal -> Inter -> Normal -> Inter if endtime-time == 2*dt
961967
else:

0 commit comments

Comments
 (0)