Multirate code saves too much global information in RK initialization
This line illustrates the issue.
The RK initialization code for the multirate methods currently assigns each RHS value it generates into an RK specific global variable, one per RHS value at each small step. Once the RK initialization state is over, the RHS values are migrated over to the appropriate AB history variables. The issue is that for an n step method with substep ratio k, that makes for 4 * (n - 1) * k distinct RK globals. Whereas there are 4 * (n - 1) AB history values. The remaining RHS values from the RK initialization stage are kept around for the duration of the primary code, which has the potential to be highly inefficient at scale.
The reason for this inefficiency is that it simplifies the logic to generate all the RK RS history and then to subsequently transfer over the history to the AB stage.
There are two ways to fix this:
- Allow dead code elimination to eliminate assignments to dead
<p>
variables. Potentially tricky, since this may require interprocedural information. - Fix the multirate code to assign to fewer global variables.