<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div><div>On May 14, 2013, at 2:15 PM, Matthew Knepley wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div dir="ltr"><div class="gmail_extra">On Tue, May 14, 2013 at 4:06 PM, Anthony Vergottis <span dir="ltr"><<a href="mailto:a.vergottis@gmail.com" target="_blank">a.vergottis@gmail.com</a>></span> wrote:<br><div class="gmail_quote">
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">To whom it may concern,<div><br></div><div>I am very new to Petsc and I would very much appreciate some assistance.</div>
<div><br></div><div>What would be the best way to create an array of matrix objects? The number of matrix objects required would be determined during run time.</div>
<div><br></div><div>For example, I am looking into the FEM and I would like to create a matrix for each element (I know how to set up the matrix objects). Therefore, if I am using a mesh with 100 element I would like to determine during runtime that I will need to create 100 "Mat    A[100]" etc, something along those lines. Hope I explained it well.</div>

<div><br></div><div>Sorry if this is a trivial question but your help would go a long way.</div></div></blockquote><div><br></div><div>I don't think you want to do this. Generally, element matrices can be raw arrays. If you really want</div>
<div>an array of Mat objects, declare it</div><div><br></div><div>  Mat *mats;</div><div><br></div><div>Allocate it</div><div><br></div><div>  ierr = PetscMalloc(numMats * sizeof(Mat), &mats);CHKERRQ(ierr);</div><div>
<br></div><div>and call MatCreate(), etc. for each entry.</div></div></div></div>
</blockquote>Another alternative is to use a lightweight vector/matrix library for small local matrices. Since you're using C++, an easy-to-use option might be Eigen. </div><br></body></html>