<html>
<head>
<meta content="text/html; charset=UTF-8" http-equiv="Content-Type">
</head>
<body bgcolor="#FFFFFF" text="#000000">
Dear Dr. Brown, <br>
Your brilliant idea works. :) Thank you so much. <br>
I have a final question on it. Is it taken a lot of memory for
doing this? As I understand, pointers won't occupy many memories and
it works like an alias. It will not, to my limit knowledge, take
much extra memory by doing this. <br>
Is that true?<br>
<br>
thanks,<br>
Alan<br>
On 4/12/2012 1:22 PM, Jed Brown wrote:
<blockquote
cite="mid:CAM9tzSmBk4TMrc-0QaM=cjW3-hUDqMLy=L_Yqeoo-yDkWq4XCg@mail.gmail.com"
type="cite">
<div class="gmail_quote">On Thu, Apr 12, 2012 at 13:16, Zhenglun
(Alan) Wei <span dir="ltr"><<a moz-do-not-send="true"
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>
</blockquote>
<br>
</body>
</html>