<div class="gmail_quote">On Thu, Apr 12, 2012 at 11:37, Zhenglun (Alan) Wei <span dir="ltr"><<a 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>