<div dir="ltr"><div class="gmail_extra"><br><div class="gmail_quote">On Thu, May 15, 2014 at 2:08 AM, Jed Brown <span dir="ltr"><<a href="mailto:jed@jedbrown.org" target="_blank">jed@jedbrown.org</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="">Christophe Ortiz <<a href="mailto:christophe.ortiz@ciemat.es">christophe.ortiz@ciemat.es</a>> writes:<br>
<br>
> Hi all,<br>
><br>
> I am experiencing some problems of memory corruption with PetscMemzero().<br>
><br>
> I set the values of the Jacobian by blocks using MatSetValuesBlocked(). To<br>
> do so, I use some temporary two-dimensional arrays[dof][dof] that I must<br>
> reset at each loop.<br>
><br>
> Inside FormIJacobian, for instance, I declare the following two-dimensional<br>
> array:<br>
><br>
> PetscScalar diag[dof][dof];<br>
><br>
> and then, to zero the array diag[][] I do<br>
><br>
> ierr = PetscMemzero(diag,dof*dof*sizeof(PetscScalar));<br>
<br>
</div>Note that this can also be spelled<br>
<br>
PetscMemzero(diag,sizeof diag);<br></blockquote><div><br></div><div>Ok.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div class=""><br>
> Then, inside main(), once dof is determined, I allocate memory for diag as<br>
> follows:<br>
><br>
> diag = (PetscScalar**)malloc(sizeof(PetscScalar*) * dof);<br>
><br>
> for (k = 0; k < dof; k++){<br>
> diag[k] = (PetscScalar*)malloc(sizeof(PetscScalar) * dof);<br>
> }<br>
> That is, the classical way to allocate memory using the pointer notation.<br>
<br>
</div>Note that you can do a contiguous allocation by creating a Vec, then use<br>
VecGetArray2D to get 2D indexing of it.<br>
</blockquote></div><br></div><div class="gmail_extra"><br></div><div class="gmail_extra">Good to know. I'll try. Thanks.</div><div class="gmail_extra"><br></div></div>