<div class="gmail_quote">On Thu, Apr 12, 2012 at 11:37, Zhenglun (Alan) Wei <span dir="ltr">&lt;<a href="mailto:zhenglun.wei@gmail.com">zhenglun.wei@gmail.com</a>&gt;</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 &#39;calloc&#39; to allocate memory to &#39;a[][]&#39; rather
        than directly define &#39;a[][]&#39; 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 &lt; 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, &amp;columntype);</div><div><br></div><div>This specifies that the array is strided.</div></div>