<html>#2319: do not use static variables in CCTK_DECLARE_ARGUMENTS
<table style='border-spacing: 1ex 0pt; '>
<tr><td style='text-align:right'> Reporter:</td><td>Roland Haas</td></tr>
<tr><td style='text-align:right'>   Status:</td><td>new</td></tr>
<tr><td style='text-align:right'>Milestone:</td><td></td></tr>
<tr><td style='text-align:right'>  Version:</td><td></td></tr>
<tr><td style='text-align:right'>     Type:</td><td>enhancement</td></tr>
<tr><td style='text-align:right'> Priority:</td><td>minor</td></tr>
<tr><td style='text-align:right'>Component:</td><td>Cactus</td></tr>
</table>

<p>Currently CCTK_DECLARE_VARIABLES (schematically) looks like this:</p>
<div class="codehilite language-c"><pre><span></span><span class="k">static</span> <span class="kt">int</span> <span class="n">cctk_varFooIdx</span> <span class="o">=</span> <span class="o">-</span><span class="mi">1</span>
<span class="n">CCTK_REAL</span> <span class="o">*</span> <span class="n">Foo</span><span class="p">;</span>
<span class="k">if</span><span class="p">(</span><span class="n">cctk_varFooIdx</span> <span class="o">==</span> <span class="o">-</span><span class="mi">1</span><span class="p">)</span> <span class="n">cctk_varFooIdx</span> <span class="o">=</span> <span class="n">CCTK_VarIndex</span><span class="p">(</span><span class="s">&quot;BAR::FOO&quot;</span><span class="p">);</span>
<span class="n">Foo</span> <span class="o">=</span> <span class="n">CCTK_VarDataPtrI</span><span class="p">(</span><span class="n">cctkGH</span><span class="p">,</span> <span class="n">cctk_varFooIdx</span><span class="p">,</span> <span class="mi">0</span><span class="p">)</span>
</pre></div>


<p>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 <code>CCTK_VarIndex</code> 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 <code>DECLARE_CCTK_ARGUMENTS</code> from within an <code>#pragma omp parallel</code> 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).</p>
<p>The pull request <a data-is-external-link="true" href="https://bitbucket.org/cactuscode/cactus/pull-requests/81/cactus-remove-static-variables-in/diff" rel="nofollow">https://bitbucket.org/cactuscode/cactus/pull-requests/81/cactus-remove-static-variables-in/diff</a> removes the static variables in sched
<p>--<br/>
Ticket URL: <a href='https://bitbucket.org/einsteintoolkit/tickets/issues/2319/do-not-use-static-variables-in'>https://bitbucket.org/einsteintoolkit/tickets/issues/2319/do-not-use-static-variables-in</a></p>
</html>