Skip to content

Time loop splitting #2780

Open
Open

Description

@ccuetom

When running an operator with an injection at the beginning, the time loop is split in two.

This can be reproduced with an example of the form:

from devito import *

grid = Grid(shape=(10, 10))
time = grid.time_dim

nt = 200
factor = 5
time_under = ConditionalDimension(name='timeu', parent=time, factor=factor)

rec = SparseTimeFunction(name='rec', grid=grid, npoint=1, nt=nt)

u = TimeFunction(name='u', grid=grid, space_order=2)
v = TimeFunction(name='v', grid=grid, space_order=2)
g = Function(name='g', grid=grid, space_order=2)
usaved = TimeFunction(name='usaved', grid=grid, space_order=2, time_dim=time_under, save=nt//factor+1)

eq = [Eq(u.forward, u + 1), Eq(usaved, u.forward)] + rec.interpolate(u)
op = Operator(eq)
op(time_m=1, time_M=nt-1)

t = rec.time_dim
eq = rec.inject(field=v, expr=rec) + [Eq(v.backward, v + 1), Inc(g, v.backward * usaved)]
op = Operator(eq)
op(time_m=1, time_M=nt-1)

where the second operator ends up with two time loops instead of one.

Activity

  1. ggorman commented on Oct 22, 2026

    @ggorman
    Contributor

    #3008 (merged 2026-08-20, empty body) stopped Schedule from splitting a time loop that carries sub-iterators: on current main the second Operator above has a single time loop, where main at 2025-10-29 had two ([--, ++]). That loop now runs forward (time += 1) although the equations write v.backward: sum(g) comes out as 89118272, against 66730956 for the same script with v saved in full (save=nt), which still gives two loops. Remaining: the merged loop should run backward. The direction finding is from a single run against the full-save variant, not a hand-derived reference.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions