<div class="gmail_quote">On Thu, Apr 12, 2012 at 13:16, Zhenglun (Alan) Wei <span dir="ltr"><<a href="mailto:zhenglun.wei@gmail.com">zhenglun.wei@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div bgcolor="#FFFFFF" text="#000000"> 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. <br>
1) should define a new one-dimensional pointer array, i.e. TESTVAR
*array;<br>
2) I allocate this array with array = (TESTVAR*) calloc(SIZE*SIZE,
sizeof(TESTVAR));<br>
3) then, I setup pointer of 'a[i][j]' to array. <br></div></blockquote><div><br></div><div>the_struct **a = malloc(SIZE*sizeof(the_struct));</div><div>for (i=0; i<SIZE; i++) a = &array[i*SIZE];</div>
<div><br></div><div>Now you can use a[i][j] instead of array[i*SIZE+j].</div><div><br></div><div>With C99, you can just create a VLA pointer:</div><div><br></div><div>Scalar (*a)[SIZE] = (Scalar(*)[SIZE])array;</div><div>
<br></div><div>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.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div bgcolor="#FFFFFF" text="#000000">
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?</div></blockquote></div><br><div>You can use VecScatter, for example.</div>