do not use static variables in CCTK_DECLARE_ARGUMENTS

Create issue
Issue #2319 resolved
Roland Haas created an issue

Currently CCTK_DECLARE_VARIABLES (schematically) looks like this:

static int cctk_varFooIdx = -1
if(cctk_varFooIdx == -1) cctk_varFooIdx = CCTK_VarIndex("BAR::FOO");
Foo = CCTK_VarDataPtrI(cctkGH, cctk_varFooIdx, 0)

ie for each Cactus variable there is a static integer variable that is initialized with the grid variable index the first time the function is called. This way Cactus avoids having many (expensive) calls to CCTK_VarIndex for each scheduled routine. However the static variables are undesirable for at least two reasons: (a) they make it impossible to call scheduled functions in a multi-threaded way (or DECLARE_CCTK_ARGUMENTS from within an #pragma omp parallel section) and (b) there is one such variable and one if statement per grid variable potentially being slow for thorns with many variables (eg GRHydro).

The pull request removes the static variables in scheduled functions in favor for a set of global variables (of similar name) that are initialized once when Cactus starts. Fortran scheduled functions do similar (worse actually since they do contain calls taking strings as arguments) in their C-to-Fortran wrappers, though the current pull request does not address them yet.

The pull request adds a new (auto-generated) function to each thorn that is called when a thorn is enabled to set up the thorn's variables. This needs to be a separate function and cannot be done in the existing function CactusBindingsVariables_${thorn}_Initialise() due to issues with how Cactus handles public variables of implementations if I remember correctly.

Comments (1)

  1. Log in to comment