[petsc-users] A problem with MPI Derived Data Type and 'calloc'
Matthew Knepley
knepley at gmail.com
Thu Apr 19 04:52:46 CDT 2012
On Wed, Apr 18, 2012 at 3:52 PM, Alan Wei <zhenglun.wei at gmail.com> wrote:
> Dear all,
> I hope you're having a nice day. I have a further question on this
> issue in 3D.
> 1, Following the idea of Dr. Brown and Dr. Knepley, I finished a 2D test,
> which works very fine. Here, I did it in 3D by
> "
> TESTVAR ***a, ***b, ***c;
> TESTVAR **aa, **bb, **cc;
> TESTVAR *arraya, *arrayb, *arrayc;
>
> arraya = (TESTVAR*) calloc(SIZE*SIZE*SIZE, sizeof(TESTVAR));
> arrayb = (TESTVAR*) calloc(SIZE*SIZE*SIZE, sizeof(TESTVAR));
> arrayc = (TESTVAR*) calloc(SIZE*SIZE*SIZE, sizeof(TESTVAR));
>
> aa =(TESTVAR**) calloc(SIZE*SIZE, sizeof(TESTVAR*));
> bb =(TESTVAR**) calloc(SIZE*SIZE, sizeof(TESTVAR*));
> cc =(TESTVAR**) calloc(SIZE*SIZE, sizeof(TESTVAR*));
>
> for(i = 0; i < SIZE*SIZE; i++) {
> aa[i] = &arraya[i*SIZE];
> bb[i] = &arrayb[i*SIZE];
> cc[i] = &arrayc[i*SIZE];
> }
>
> a =(TESTVAR***) calloc(SIZE*SIZE, sizeof(TESTVAR**));
> b =(TESTVAR***) calloc(SIZE*SIZE, sizeof(TESTVAR**));
> c =(TESTVAR***) calloc(SIZE*SIZE, sizeof(TESTVAR**));
>
> for(i = 0; i < SIZE; i++) {
> a[i] = &aa[i*SIZE];
> b[i] = &bb[i*SIZE];
> c[i] = &cc[i*SIZE];
> }
> "
> It works. However, I wonder if there is any other good ideas for 3D
> problem other than this kinda of 'two-layer' approach.
>
What is the reason for not using DMDA?
> 2, I have a little question on PETSc about 3D processor ordering. Does
> PETSc have any function giving me the nodes/rank number of neighboring
> nodes/ranks? Are those 'Application Ordering' functions applicable for my
> case?
>
What do you mean by neighboring? If it is jsut stencil neighbors, then use
a local vector.
Matt
> thanks,
> Alan
>
> On Fri, Apr 13, 2012 at 5:41 PM, Jed Brown <jedbrown at mcs.anl.gov> wrote:
>
>> On Fri, Apr 13, 2012 at 17:38, Zhenglun (Alan) Wei <
>> zhenglun.wei at gmail.com> wrote:
>>
>>> 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.
>>
>>
>> A pointer takes about as much space as a floating point value, so that
>> array of pointers costs about 1*N compared to the N*N matrix.
>>
>
>
--
What most experimenters take for granted before they begin their
experiments is infinitely more interesting than any results to which their
experiments lead.
-- Norbert Wiener
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20120419/328d61f9/attachment.htm>
More information about the petsc-users
mailing list