<div dir="ltr">[I am posting this example in response to a request I received in private.]<div><br></div><div>This is how you can use complex numbers from C. This code assumes that you have declared CCTK_COMPLEX grid functions u, v, w.</div>
<div><br></div><div style>(I didn&#39;t actually try to compile this example, but the overall structure should be fine.)</div><div><br></div><div>#include &lt;cctk.h&gt;</div><div>#include &lt;cctk_Arguments.h&gt;</div><div>
<br></div><div>#include &lt;complex.h&gt;</div><div>#include &lt;math.h&gt;</div><div><br></div><div>void do_some_complex_calculations(CCTK_ARGUMENTS)</div><div>{</div><div>  DECLARE_CCTK_ARGUMENTS;</div><div><br></div><div style>
#pragma omp parallel for</div><div>  for (int k=0; k&lt;cctk_lsh[2]; ++k) {</div><div>  for (int j=0; j&lt;cctk_lsh[1]; ++j) {</div><div style>  for (int i=0; i&lt;cctk_lsh[0]; ++i) {</div><div style>    const int idx = CCTK_GFINDEX3D(cctkGH, i,j,k);</div>
<div style><br></div><div style>    CCTK_COMPLEX tmp = 2.0 + 3.0 * I;</div><div style>    u[idx] = conj(tmp) * v[idx] + 2.0 * cabs(w[idx]);</div><div style>    u[idx] = cexp(u[idx]) - creal(tmp) + cimag(tmp);</div><div style>
<br></div><div style>  }</div><div style>  }</div><div style>  }</div><div style>}</div><div><br><div>-erik<br clear="all"><div><br></div>-- <br>Erik Schnetter &lt;<a href="mailto:schnetter@cct.lsu.edu" target="_blank">schnetter@cct.lsu.edu</a>&gt;<br>
<a href="http://www.perimeterinstitute.ca/personal/eschnetter/" target="_blank">http://www.perimeterinstitute.ca/personal/eschnetter/</a>
</div></div></div>