Initial Riem_Solver_C Mini-App Port Notes
GT4Py miniapp at:
GFDL source code at:

1. Sim1_Solver inlining

There is no way to inline a stencil within a stencil. The relevant Fortran section of code is:

   do k=1,km
      do j=js1,je1
         do i=is1, ie1
            ... 
         enddo
      enddo
   enddo
!$ACC end kernels
      if ( a_imp > 0.5 ) then
           call SIM1_solver(dt, is1, ie1, js1, je1, isd, ied, jsd, jed, km, rdgas, gama, gm2, cp2, akap, pe2,  &
                            dm, pm2, pem, w2, dz2, pt, ws, p_fac)
      endif
!$ACC kernels present(ms,dt,km,hs,gz,pef,pe2,pem,dz2) 
    do k=2,km+1
      do j=js1,je1
         do i=is1, ie1
            ...
         enddo
      enddo
    enddo

The call is based on a run-time conditional, which in the GT4Py miniapp is converted to a compile-time conditional on a_imp.

We can inline the sim1_solver if we wrap each interval with
if __INLINED(A_IMP < 0.5)
This is the approach I’m taking at first.

Later, it would be nice to have the following features:
  1. Allow stencils calling other stencils (or we could call this a gtscript.macro (function-like, but allows computations)
  1. Allow compile-time conditionals OUTSIDE the computations

2. Filling bet

Bet does not need to be filled at all levels as we do in the current sim1_solver in fv3core here https://github.com/VulcanClimateModeling/fv3core/blob/master/fv3core/stencils/sim1_solver.py#L51

It’s only used one level at a time, so this is an equivalent and higher performing version:
    with computation(FORWARD):
        with interval(2, 1):
            if __INLINED(A_IMP < 0.5):
                bet = bb[0, 0, -1]
    # Line 265
    with computation(PARALLEL), interval(2, -1):
        if __INLINED(A_IMP < 0.5):
            gam = g_rat[0, 0, -1] / bet[0, 0, 0]
            bet = bb - gam

3. Lower-dimensional temporaries (bet)

bet can truly be defined as a 2D storage. How should this be represented in GT4Py? Will:

  1. the toolchain be able to determine that from the code above?
  1. will there be type hints on the first declaration of a temporary bet that hints at the storage mask?

4. Temporaries across computations

pe is a temporary in the miniapp stencil, but it is filled in one computation and used in another

5. Numpy backend has assertion error with multiple intervals + PARALLEL execution


  File "/Users/johannd/Code/gt4py/src/gt4py/backend/numpy_backend.py", line 124, in make_stage_source
    assert sorted(regions, reverse=iteration_order == gt_ir.IterationOrder.BACKWARD) == regions
AssertionError

6. Need to allow empty computations due to compile-time ifs