[petsc-users] petsc malloc multidimensional array

Matthew Knepley knepley at gmail.com
Wed Mar 12 07:03:53 CDT 2014


On Wed, Mar 12, 2014 at 6:38 AM, 吕超 <luchao at mail.iggcas.ac.cn> wrote:

>   Many thanks for all your explanation, its really help me!
>
>   Now my program run smoothly, and the result is satisfactory!
>
>   For 3d results, I now make drawings by many slices in matlab.
>
>   And I find it not visualized, so could do you please tell me how can I
> draw these 3d space fileds finely?
>

Consider using http://www.paraview.org/

   Matt


>
> > -----原始邮件-----
> > 发件人: "Jed Brown" <jed at jedbrown.org>
> > 发送时间: 2014年3月12日 星期三
> > 收件人: "Barry Smith" <bsmith at mcs.anl.gov>, "Matthew Knepley" <
> knepley at gmail.com>
> > 抄送: "吕超" <luchao at mail.iggcas.ac.cn>, petsc-users <
> petsc-users at mcs.anl.gov>
> > 主题: Re: [petsc-users] petsc malloc multidimensional array
> >
> > Barry Smith <bsmith at mcs.anl.gov> writes:
> >
> > > On Mar 11, 2014, at 9:22 AM, Matthew Knepley <knepley at gmail.com
> > wrote:
> > >
> > >> On Tue, Mar 11, 2014 at 9:05 AM, 吕超 <luchao at mail.iggcas.ac.cn> wrote:
> > >> Hi, Matthew:
> > >>
> > >>      Thank you for your reply so fast! but I also have some questions:
> > >>
>
> > >>     2d arrays I used is just intermediate variable, not for fields, and the fields is used Vector. In Finite element method, when I use element stiffness matrix to assemble global stiffness matrix, I always first compute the 2d element stiffness matrixs whose size is 512*512(inner points in element),so big for static arrays.
> > >
>
> > >    If the 512 is a fixed number, not different for different elements you can in C 89 standard use
> > >
> > >     mysubroutine(….)
> > >     double element[512][512];
> >
> > This is fairly "big" -- 2 MiB of what is typically an 8 MiB stack size,
> > so if you allocate several of these, you may get a stack overflow.  You
> > can increase the stack size on most systems, but that makes it more
> > complicated to run your program.  I would allocate dynamically if you
> > are worried about this.
> >
> > If you want to avoid PETSc array functions, you can allocate dynamically
> > and access via a pointer:
> >
> >   double *mem = malloc(M*N*sizeof(double));
> >   double (*p)[N] = (double (*)[N])mem;
> >   // access p[i][j]
> >   free(mem);
>
>
>
>


-- 
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/20140312/e02990d4/attachment.html>


More information about the petsc-users mailing list