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);

Attachment: pgpdi9zjZVxsU.pgp
Description: PGP signature

Reply via email to