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? > -----原始邮件----- > 发件人: "Jed Brown" <[email protected]> > 发送时间: 2014年3月12日 星期三 > 收件人: "Barry Smith" <[email protected]>, "Matthew Knepley" <[email protected]> > 抄送: "吕超" <[email protected]>, petsc-users <[email protected]> > 主题: Re: [petsc-users] petsc malloc multidimensional array > > Barry Smith <[email protected]> writes: > > > On Mar 11, 2014, at 9:22 AM, Matthew Knepley <[email protected]> wrote: > > > >> On Tue, Mar 11, 2014 at 9:05 AM, 吕超 <[email protected]> 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);
