<html>
<head>
<meta content="text/html; charset=UTF-8" http-equiv="Content-Type">
</head>
<body bgcolor="#FFFFFF" text="#000000">
On 4/12/2012 11:52 AM, Jed Brown wrote:
<blockquote
cite="mid:CAM9tzSmsWUpp5-Ltng=c=RMQVOJvPzAMy280pggbp+h547DqGw@mail.gmail.com"
type="cite">
<div class="gmail_quote">On Thu, Apr 12, 2012 at 11:37, 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:
<blockquote class="gmail_quote" style="margin:0 0 0
.8ex;border-left:1px #ccc solid;padding-left:1ex">
<div bgcolor="#FFFFFF" text="#000000">
<div style="font-family:-moz-fixed;font-size:14px"
lang="x-western"> Everything is fine in
AlanFloatStruct.c. <b>However, when I was trying to use
'calloc' to allocate memory to 'a[][]' rather than
directly define 'a[][]' as a structure matrix, the
problem comes.</b> (see AlanTEST1.c).</div>
</div>
</blockquote>
<div><br>
</div>
<div>
<div> a = (TESTVAR**) calloc(SIZE, sizeof(TESTVAR*));</div>
<div> b = (TESTVAR**) calloc(SIZE, sizeof(TESTVAR*));</div>
<div> c = (TESTVAR**) calloc(SIZE, sizeof(TESTVAR*));</div>
<div> for(i = 0; i < SIZE; i++) {</div>
<div> a[i] = (TESTVAR*) calloc(SIZE, sizeof(TESTVAR));</div>
<div> b[i] = (TESTVAR*) calloc(SIZE, sizeof(TESTVAR));</div>
<div> c[i] = (TESTVAR*) calloc(SIZE, sizeof(TESTVAR));</div>
<div> }</div>
</div>
<div><br>
</div>
<div>At this point, there is no relationship between a[i][j] and
a[k][j]. It is not strided memory. I suggest allocating the
entire array in one allocation (SIZE*SIZE*sizeof(TESTVAR)).
You can set up pointers into it if you like, but MPI will not
use them.</div>
<div><br>
</div>
<div> MPI_Type_vector(SIZE, 1, SIZE, structype,
&columntype);</div>
<div><br>
</div>
<div>This specifies that the array is strided.</div>
</div>
</blockquote>
Dear Dr. Brown,<br>
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>
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?<br>
<br>
thanks,<br>
Alan<br>
</body>
</html>