<p>Hi, Matthew:</p><p>     Thank you for your reply so fast! but I also have some questions:</p><p>    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. So i want to use PetscMalloc to bulid 2d arrays to store element stiffness matrixs' values. And I don't know how to do, could do tell me?</p><p>     then use another 1d array to abstract the nonzero values from 2d arrays above-mentioned. could do you please tell me  some other methods much more convenient and faster?<br><br><br></p><blockquote style="padding-left: 5px; margin-right: 0px; margin-left: 5px; border-left-color: rgb(182, 182, 182); border-left-width: 2px; border-left-style: solid;" name="replyContent">-----原始邮件-----<br>
<b>发件人:</b> "Matthew Knepley" <knepley@gmail.com><br>
<b>发送时间:</b> 2014年3月11日 星期二<br>
<b>收件人:</b> "吕超" <luchao@mail.iggcas.ac.cn><br>
<b>抄送:</b> petsc-users <petsc-users@mcs.anl.gov><br>
<b>主题:</b> Re: [petsc-users] petsc malloc multidimensional array<br><br><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Tue, Mar 11, 2014 at 8:37 AM, 吕超 <span dir="ltr"><<a href="mailto:luchao@mail.iggcas.ac.cn" target="_blank">luchao@mail.iggcas.ac.cn</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; padding-left: 1ex; border-left-color: rgb(204, 204, 204); border-left-width: 1px; border-left-style: solid;"><p>  Hi, recently,when I use PETSc to bulid 2d arrays such as PetscScalar A[512][512],B[512][512],C,D,E,F,..., program always has error of Segmentation Violation. So I want to use PetscMalloc to bulid 2d array, and I hope that I can also use these 2d array A[i][j] by subscripts as before. Could do please tell me how can I do? Thank you.</p>
</blockquote><div>1) This is a C question, not a PETSc question</div><div><br></div><div>2) If you are using 2D arrays for fields, you should be using the DMDA, which has a section in the manual</div><div><br></div><div>  Thanks,</div>
<div><br></div><div>     Matt</div><div> </div><blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; padding-left: 1ex; border-left-color: rgb(204, 204, 204); border-left-width: 1px; border-left-style: solid;"><p>LV CHAO</p><p>2014/3/11<br><br><br></p><span></span><br><br><br></blockquote>
</div><br><br clear="all"><div><br></div>-- <br>What most experimenters take for granted before they begin their experiments is infinitely more interesting than any results to which their experiments lead.<br>-- Norbert Wiener
</div></div>
</blockquote><br><span></span><br><br><br>