Consider adding if statement functionality to read/write declarations

Issue #2734 new
Samuel Cupp created an issue

Currently, the read/write declarations are a compile-time setting. This is usually fine. For a function that is scheduled in multiple places with different rd/wr, Cactus takes a union of all declarations for generating the function-specific macros. However, one case can lead to additional complications in scheduling. If a function has many different if statements inside it controlling behavior at runtime (see e.g. GRHydro for the worst case scenario of this type of runtime-dependent scheduling), then properly setting the rd/wr declarations will require either ignoring the actual behavior of the code and hoping for the best or having all of those if statements reproduced inside the schedule.ccl. The former can bypass some safety checks and enforcement of good code behavior, while the latter causes excessive bloat in the schedule.ccl.

A preferable alternative would be to allow rd/wr declarations to have runtime tags/conditionals/something that can turn them on/off depending on parameters. An easy example is IllinoisGRMHD's conserv_to_prims function, which writes the primitives, conservatives, and (if update_Tmunu) the stress-energy tensor. Right now, the only way to explicitly give this data dependency would be (focusing on the WRITES declarations)

if (update_Tmunu)
{
  schedule IllinoisGRMHD_conserv_to_prims
  {
    LANG: C
    READS: stuff
    WRITES: prims, cons, Tmunu
  } ""
} else {
  schedule IllinoisGRMHD_conserv_to_prims
  {
    LANG: C
    READS: stuff
    WRITES: prims, cons
  } ""
}

Instead, it would be convenient to say

schedule IllinoisGRMHD_conserv_to_prims
{
  LANG: C
  READS: stuff
  WRITES: prims, cons
  WRITES: Tmunu if update_Tmunu
} ""

or something equivalent. This not only gives the ability to more accurately state the data dependencies, it also allows for more compact scheduling of complicated functions while still allowing for them to be controlled using runtime parameters.

Comments (1)

  1. Log in to comment