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

Zhenglun (Alan) Wei zhenglun.wei at gmail.com
Fri Apr 13 17:38:34 CDT 2012


Dear Dr. Brown,
     Your brilliant idea works. :) Thank you so much.
     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.
     Is that true?

thanks,
Alan
On 4/12/2012 1:22 PM, Jed Brown wrote:
> On Thu, Apr 12, 2012 at 13:16, Zhenglun (Alan) Wei 
> <zhenglun.wei at gmail.com <mailto:zhenglun.wei at gmail.com>> wrote:
>
>          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.
>     1)  should define a new one-dimensional pointer array, i.e.
>     TESTVAR *array;
>     2)  I allocate this array with array = (TESTVAR*)
>     calloc(SIZE*SIZE, sizeof(TESTVAR));
>     3)  then, I setup pointer of 'a[i][j]'  to array.
>
>
> the_struct **a = malloc(SIZE*sizeof(the_struct));
> for (i=0; i<SIZE; i++) a = &array[i*SIZE];
>
> Now you can use a[i][j] instead of array[i*SIZE+j].
>
> With C99, you can just create a VLA pointer:
>
> Scalar (*a)[SIZE] = (Scalar(*)[SIZE])array;
>
> 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.
>
>           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?
>
>
> You can use VecScatter, for example.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20120413/0c60869a/attachment.htm>


More information about the petsc-users mailing list