Array Notation : passing array to function

Array Notation : passing array to function

Dear all,recently I started to use the Array Notation in the new compiler 12.1.0, which is amazing, and I am glad to finally have (dynamic) multi-dimensional array support in C++ too :).Unfortunately documentationis still a bit rare, so I am confused about following code (here an example)*****************#include #include typedef std::complex cmplxd;typedef cmplxd(*A2c)[];int Nx, Ny, NxLlD, NyLlD;void goCilk(cmplxd A[NxLlD,Nx][NyLlD,Ny]){ for(int x = NxLlD; x <= NxLlD+Nx-1; x++) { for(int y = NyLlD; y <= NyLlD+Ny-1; y++) { std::cout << x << " " << y << " " << A[x][y] << std::endl; }}}int main(){ NxLlD = 1; Nx = 4; NyLlD = 1; Ny = 3; cmplxd *A = new cmplxd[Nx*Ny]; for(int x = 0; x < Nx*Ny; x++) A[x] = 1.; A[0]=2.; goCilk((A2c) A);}*****************The code compiles and runs without error. Now concerning the "cmplxd goCilk(cmplxd A[NxLlD,Nx][NyLlD,Ny])" functions, I tought that A[NxLlD, Nx] defines the starting value, and the length of this dimension. Similar like fortran has with A(NxLlD:NxLlD+Nx-1), but it seems that even tough the code compiles, the NxLlD value has no meaning as I checked with using some random numbers for NxLlD/NyLlD.Could you please point me to the documentation, where I can find out the correct syntax ?And is it actually possible todefine an offset to an array (only in notation like in Fortran), e.g. right now A[0][0] points to the first value, but I would like thatA[NxLlD][NyLlD] to point to the lowest value (it makes life far more simpler for MPI (domain decomposition) programs).Thanks a lot and best wishes,Paul

4 posts / novo 0
Último post
Para obter mais informações sobre otimizações de compiladores, consulte Aviso sobre otimizações.

Hello Paul,
I am not sure if you are aware but this website has the entire Cilk Plus language specification: http://software.intel.com/en-us/articles/intel-cilk-plus-specification/

The Array-triplets are representedusing the following sytax

Array [ ]

For example, Array[0:5:2] implies we are going to touch A[0], A[2], A[4], A[6], A[8]

I hope this helps!

Thanks,

Balaji V. Iyer.

Dear Balaji,thanks a lot for your quick reply. Yes, I know about the specifictation, I looked through it and couldn't findanything related. So what confused me,is thatWORKS : void goCilk(cmplxd A[NxLlD,Nx][NyLlD,Ny]) (<--- note the comma NxLLD, Nxbehaviour is not documented, and seems not be a valid feature, yet the compiler accepts it without warning.Is this a bug or am I missing somehting ?Thanks

also, it has a pretty different behavirout compared to Fortran,Assuming I pass an array in Fortran, I define the index position of this array. E.g.subroutine (A) double precison :: A(Start_X:End_X, Start_Y:End_Y)in the function deklaration. While cilk plus seems to always assume that my index starts from A[0].Is there a way to tell cilk where to start counting ?E.g.double (int Start_X, int Length_X, A[Start_X, Length_X])calling Start_X=5, and Length_X=10, then A[5] refers to the zeroth element (A'[0] in the previous view).In Fortran it is pretty easy, in Cilk I hope this feature exists, or may be included ?

Deixar um comentário

Faça login para adicionar um comentário. Não é membro? Inscreva-se hoje mesmo!