Skip to content

Commit

Permalink
Skip Kernel execution when no particles need to be executed
Browse files Browse the repository at this point in the history
  • Loading branch information
erikvansebille committed Jul 30, 2024
1 parent 56314f7 commit f4fa1e9
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions parcels/particleset.py
Original file line number Diff line number Diff line change
Expand Up @@ -944,6 +944,11 @@ def execute(self, pyfunc=AdvectionRK4, pyfunc_inter=None, endtime=None, runtime=

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

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

# If we don't perform interaction, only execute the normal kernel efficiently.
if self.interaction_kernel is None:
res = self.kernel.execute(self, endtime=next_time, dt=dt)
if res == StatusCode.StopAllExecution:
return StatusCode.StopAllExecution
if not skip_kernel:
res = self.kernel.execute(self, endtime=next_time, dt=dt)
if res == StatusCode.StopAllExecution:
return StatusCode.StopAllExecution
# Interaction: interleave the interaction and non-interaction kernel for each time step.
# E.g. Normal -> Inter -> Normal -> Inter if endtime-time == 2*dt
else:
Expand Down

0 comments on commit f4fa1e9

Please sign in to comment.