On Thu, Apr 12, 2012 at 13:16, Zhenglun (Alan) Wei <zhenglun.wei at gmail.com>wrote:
> Thank you for your reply. It gives me another way to solve this > problem. However, I failed several times while I was trying it. Can I > repeat your idea to make sure that I understand it. > 1) should define a new one-dimensional pointer array, i.e. TESTVAR *array; > 2) I allocate this array with array = (TESTVAR*) calloc(SIZE*SIZE, > sizeof(TESTVAR)); > 3) then, I setup pointer of 'a[i][j]' to array. > the_struct **a = malloc(SIZE*sizeof(the_struct)); for (i=0; i<SIZE; i++) a = &array[i*SIZE]; Now you can use a[i][j] instead of array[i*SIZE+j]. With C99, you can just create a VLA pointer: Scalar (*a)[SIZE] = (Scalar(*)[SIZE])array; and then use a[i][j] syntax without needing to allocate those pointers. It's a shame Microsoft refuses to do any maintenance on their old C compiler. > Are they correct? BTW, does PETSc have any data structure can be an > alternative so that I do not need to use MPI derived data type? > You can use VecScatter, for example. -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20120412/76ae40fc/attachment-0001.htm>
