#2319: do not use static variables in CCTK_DECLARE_ARGUMENTS
Reporter:Roland Haas
Status:new
Milestone:
Version:
Type:enhancement
Priority:minor
Component:Cactus

Currently CCTK_DECLARE_VARIABLES (schematically) looks like this:

static int cctk_varFooIdx = -1
CCTK_REAL * Foo;
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 https://bitbucket.org/cactuscode/cactus/pull-requests/81/cactus-remove-static-variables-in/diff removes the static variables in sched

--
Ticket URL: https://bitbucket.org/einsteintoolkit/tickets/issues/2319/do-not-use-static-variables-in