Hi. I'm having a compilation issue involving a Cactus array.
I'm trying to simplify my declarations & storage by declaring/assigning storage for an array called "dataslice" in my thorn's interface.ccl (numtheta & numphi are thorn parameters):
CCTK_REAL data_slices TYPE=ARRAY DISTRIB=CONSTANT DIM=3 SIZE=59,numtheta,numphi { dataslice }
In my C source file, I get the pointers from the 0th rank of this array, for passing into an interpolator:
CCTK_POINTER outputs[59]; for(m=0;m<59;m++){ outputs[m] = &dataslice[m][0][0]; }
----------------------------------------------------
But during compilation, I get the error
error: expression must have pointer-to-object type outputs[m] = &dataslice[m][0][0];
Note that I *don't* get this error if I instead declare dataslice in the C file, as
CCTK_REAL dataslice[59][numtheta][numphi];
So it appears that the Cactus ARRAY is not quite the same type as the C array I was using before. Can anyone enlighten me as to how I should be handling the array?
Thanks,
Bernard
Hello Bernard,
In my C source file, I get the pointers from the 0th rank of this array, for passing into an interpolator:
CCTK_POINTER outputs[59]; for(m=0;m<59;m++){ outputs[m] = &dataslice[m][0][0]; }
I C all arrays appear flat (not multi-dimensional as they are in Fortran), so you need to use:
output[m] = &dataslice[m*numtheta*numphi]
You can (if you want to) query dataslice's size by calling the Cactus function CCTK_GroupDynamicData (http://einsteintoolkit.org/documentation/ReferenceManual/ReferenceManualch2....) though using the parameters is fine as well.
Yours, Roland
Thanks, Roland. That is what I have to do.
C does permit multi-dimensional arrays that can be indexed like [i][j][k] (presumably without guaranteed contiguous memory allocation), but I didn't appreciate that the Cactus ones are the simpler flat sort (OK, I suppose I knew that for the grid functions, but not the other kind).
Anyway, I've changed to the "flat" 1D indexing as you've indicated, and it's compiling now. Thanks again,
Bernard
On 24 May 2016 at 02:01, Roland Haas rhaas@aei.mpg.de wrote:
Hello Bernard,
In my C source file, I get the pointers from the 0th rank of this array, for passing into an interpolator:
CCTK_POINTER outputs[59]; for(m=0;m<59;m++){ outputs[m] = &dataslice[m][0][0]; }
I C all arrays appear flat (not multi-dimensional as they are in Fortran), so you need to use:
output[m] = &dataslice[m*numtheta*numphi]
You can (if you want to) query dataslice's size by calling the Cactus function CCTK_GroupDynamicData (http://einsteintoolkit.org/documentation/ReferenceManual/ReferenceManualch2....) though using the parameters is fine as well.
Yours, Roland
-- My email is as private as my paper mail. I therefore support encrypting and signing email messages. Get my PGP key from http://keys.gnupg.net.
Users mailing list Users@einsteintoolkit.org http://lists.einsteintoolkit.org/mailman/listinfo/users
Hello Bernard,
Very good.
C does permit multi-dimensional arrays that can be indexed like [i][j][k] (presumably without guaranteed contiguous memory allocation), but I didn't appreciate that the Cactus ones are the simpler flat sort (OK, I suppose I knew that for the grid functions, but not the other kind).
As far as I know, the showstopper issue is that in C all but one of the array dimensions (unless c99 changes this) must be known at compile time which is not true in Cactus. Memory is continuous as long as this is really an array declared as something like double a[42][16][34] and not an array of pointers like eg the numerical recipies multi-d arrays. If c99 changed this, then this would be very good to know.
Anyway, I've changed to the "flat" 1D indexing as you've indicated, and it's compiling now. Thanks again,
Very good.
Bernard
On 24 May 2016 at 02:01, Roland Haas rhaas@aei.mpg.de wrote:
Hello Bernard,
In my C source file, I get the pointers from the 0th rank of this array, for passing into an interpolator:
CCTK_POINTER outputs[59]; for(m=0;m<59;m++){ outputs[m] = &dataslice[m][0][0]; }
I C all arrays appear flat (not multi-dimensional as they are in Fortran), so you need to use:
output[m] = &dataslice[m*numtheta*numphi]
You can (if you want to) query dataslice's size by calling the Cactus function CCTK_GroupDynamicData (http://einsteintoolkit.org/documentation/ReferenceManual/ReferenceManualch2....) though using the parameters is fine as well.
Yours, Roland
-- My email is as private as my paper mail. I therefore support encrypting and signing email messages. Get my PGP key from http://keys.gnupg.net.
Users mailing list Users@einsteintoolkit.org http://lists.einsteintoolkit.org/mailman/listinfo/users
users@lists.einsteintoolkit.org