[petsc-users] A problem with MPI Derived Data Type and 'calloc'

Jed Brown jedbrown at mcs.anl.gov
Thu Apr 12 11:52:33 CDT 2012


On Thu, Apr 12, 2012 at 11:37, Zhenglun (Alan) Wei
<zhenglun.wei at gmail.com>wrote:
>
>     Everything is fine in AlanFloatStruct.c. *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.* (see AlanTEST1.c).
>

    a = (TESTVAR**) calloc(SIZE, sizeof(TESTVAR*));
    b = (TESTVAR**) calloc(SIZE, sizeof(TESTVAR*));
    c = (TESTVAR**) calloc(SIZE, sizeof(TESTVAR*));
    for(i = 0; i < SIZE; i++) {
      a[i] = (TESTVAR*) calloc(SIZE, sizeof(TESTVAR));
      b[i] = (TESTVAR*) calloc(SIZE, sizeof(TESTVAR));
      c[i] = (TESTVAR*) calloc(SIZE, sizeof(TESTVAR));
    }

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.

    MPI_Type_vector(SIZE, 1, SIZE, structype, &columntype);

This specifies that the array is strided.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20120412/25aaa14b/attachment.htm>


More information about the petsc-users mailing list