[petsc-users] Memory corruption with two-dimensional array and PetscMemzero

Christophe Ortiz christophe.ortiz at ciemat.es
Wed May 21 08:18:06 CDT 2014


On Tue, May 20, 2014 at 4:25 PM, Jed Brown <jed at jedbrown.org> wrote:

> Christophe Ortiz <christophe.ortiz at ciemat.es> writes:
> > Would the following be ok ?
> >
> > //Creation of vector X of size dof*dof:
> > VecCreateSeq(PETSC_COMM_SELF,dof*dof,&X);
> >
> > // Using two-dimensional array style:
> > PetscScalar *x;
>
> This needs to be
>
>   PetscScalar **x;
>
> as you would have noticed if you tried to compile.
>
> > VecGetArray2d(X,dof,dof,0,0,&x);
> >
> > x[i][j] = ...;
>
> Yes.
>
> > Is it ok ?
> > Then, what should be passed to MatSetValuesBlocked() ?
>
> Since the array starts are (0,0), you can just pass &x[0][0].
>
> Remember to call VecRestoreArray2d() and eventually VecDestroy().
>

I tried and it works. The advantage is that it avoids setting up and using
pointers.
However, I found out that it is significantly slower than using explicit
pointers of pointers **.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20140521/e2792ac0/attachment.html>


More information about the petsc-users mailing list