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

Jed Brown jed at jedbrown.org
Tue May 20 09:25:00 CDT 2014


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().
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 835 bytes
Desc: not available
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20140520/6892f60d/attachment.pgp>


More information about the petsc-users mailing list