<div dir="ltr"><div><div>Hi all,</div><div><br></div><div>I am experiencing some problems of memory corruption with PetscMemzero().</div><div><br></div><div>I set the values of the Jacobian by blocks using MatSetValuesBlocked(). To do so, I use some temporary two-dimensional arrays[dof][dof] that I must reset at each loop.</div>
<div><br></div><div>Inside FormIJacobian, for instance, I declare the following two-dimensional array:</div><div><br></div><div>   PetscScalar  diag[dof][dof];</div><div><br></div><div>and then, to zero the array diag[][] I do</div>
<div><br>   ierr = PetscMemzero(diag,dof*dof*sizeof(PetscScalar));</div><div><br></div><div>So far no problem. It works fine.</div><div><br></div><div>Now, what I want is to have diag[][] as a global array so all functions can have access to it. Therefore, I declare it outside main().</div>
<div>Since outside the main() I still do not know dof, which is determined later inside main(), I declare the two-dimensional array diag as follows:</div><div><br></div><div>PetscScalar  **diag;</div><div><br></div><div>Then, inside main(), once dof is determined, I allocate memory for diag as follows:</div>
<div><br></div><div><div> diag = (PetscScalar**)malloc(sizeof(PetscScalar*) * dof);</div><div><br></div><div> for (k = 0; k < dof; k++){</div><div>  diag[k] = (PetscScalar*)malloc(sizeof(PetscScalar) * dof);<br></div><div>
 }<br></div></div><div>That is, the classical way to allocate memory using the pointer notation.</div><div><br></div><div>Then, when it comes to zero the two-dimensional array diag[][] inside FormIJacobian, I do as before:</div>
<div><br></div><div><div>   ierr = PetscMemzero(diag,dof*dof*sizeof(PetscScalar));</div></div><div><br></div><div>Compilation goes well but when I launch the executable, after few timesteps I get the following memory corruption message:</div>
<div><br></div><div><div>      TSAdapt 'basic': step   0 accepted t=0          + 1.000e-16 wlte=8.5e-05 family='arkimex' scheme=0:'1bee' dt=1.100e-16 </div><div>      TSAdapt 'basic': step   1 accepted t=1e-16      + 1.100e-16 wlte=4.07e-13 family='arkimex' scheme=0:'3' dt=1.210e-16 </div>
<div>      TSAdapt 'basic': step   2 accepted t=2.1e-16    + 1.210e-16 wlte=1.15e-13 family='arkimex' scheme=0:'3' dt=1.331e-16 </div><div>      TSAdapt 'basic': step   3 accepted t=3.31e-16   + 1.331e-16 wlte=1.14e-13 family='arkimex' scheme=0:'3' dt=1.464e-16 </div>
<div>[0]PETSC ERROR: PetscMallocValidate: error detected at TSComputeIJacobian() line 719 in src/ts/interface/ts.c</div><div>[0]PETSC ERROR: Memory [id=0(0)] at address 0x243c260 is corrupted (probably write past end of array)</div>
<div>[0]PETSC ERROR: Memory originally allocated in (null)() line 0 in src/mat/impls/aij/seq/(null)</div><div>[0]PETSC ERROR: --------------------- Error Message ------------------------------------</div><div>[0]PETSC ERROR: Memory corruption!</div>
<div>[0]PETSC ERROR:  !</div><div>[0]PETSC ERROR: ------------------------------------------------------------------------</div><div>[0]PETSC ERROR: Petsc Release Version 3.4.1, Jun, 10, 2013 </div><div>[0]PETSC ERROR: See docs/changes/index.html for recent updates.</div>
<div>[0]PETSC ERROR: See docs/faq.html for hints about trouble shooting.</div><div>[0]PETSC ERROR: See docs/index.html for manual pages.</div><div>[0]PETSC ERROR: ------------------------------------------------------------------------</div>
<div>[0]PETSC ERROR: ./diffusion on a icc-nompi-double-blas-debug named <a href="http://mazinger.ciemat.es">mazinger.ciemat.es</a> by u5751 Wed May 14 13:23:26 2014</div><div>[0]PETSC ERROR: Libraries linked from /home/u5751/petsc-3.4.1/icc-nompi-double-blas-debug/lib</div>
<div>[0]PETSC ERROR: Configure run at Wed Apr  2 14:01:51 2014</div><div>[0]PETSC ERROR: Configure options --with-mpi=0 --with-cc=icc --with-cxx=icc --with-clanguage=cxx --with-debugging=1 --with-scalar-type=real --with-precision=double --download-f-blas-lapack</div>
<div>[0]PETSC ERROR: ------------------------------------------------------------------------</div><div>[0]PETSC ERROR: PetscMallocValidate() line 149 in src/sys/memory/mtr.c</div><div>[0]PETSC ERROR: TSComputeIJacobian() line 719 in src/ts/interface/ts.c</div>
<div>[0]PETSC ERROR: SNESTSFormJacobian_ARKIMEX() line 995 in src/ts/impls/arkimex/arkimex.c</div><div>[0]PETSC ERROR: SNESTSFormJacobian() line 3397 in src/ts/interface/ts.c</div><div>[0]PETSC ERROR: SNESComputeJacobian() line 2152 in src/snes/interface/snes.c</div>
<div>[0]PETSC ERROR: SNESSolve_NEWTONLS() line 218 in src/snes/impls/ls/ls.c</div><div>[0]PETSC ERROR: SNESSolve() line 3636 in src/snes/interface/snes.c</div><div>[0]PETSC ERROR: TSStep_ARKIMEX() line 765 in src/ts/impls/arkimex/arkimex.c</div>
<div>[0]PETSC ERROR: TSStep() line 2458 in src/ts/interface/ts.c</div><div>[0]PETSC ERROR: TSSolve() line 2583 in src/ts/interface/ts.c</div><div>[0]PETSC ERROR: main() line 2690 in src/ts/examples/tutorials/diffusion.cxx</div>
<div>./compile_diffusion: line 25: 17061 Aborted                 ./diffusion -ts_adapt_monitor -ts_adapt_basic_clip 0.01,1.10 -draw_pause -2 -ts_arkimex_type 3 -ts_max_snes_failures -1 -snes_type newtonls -snes_linesearch_type basic -ksp_type gmres -pc_type ilu</div>
</div><div><br></div><div>Did I do something wrong ? Or is it due to the pointer notation to declare the two-dimensional array that conflicts with PetscMemzero ?</div><div><br></div><div>Many thanks in advance for your help.</div>
<div><br></div><div>Christophe</div><div><br>--<br><span style="color:rgb(0,128,0);font-family:Webdings;font-size:x-large">Q</span> <div><span style="background-color:rgb(255,255,255);white-space:pre-wrap">Por favor, piense en el medio ambiente antes de imprimir este mensaje.</span><div>
<span style="white-space:pre-wrap">Please consider the environment before printing this email.</span></div></div></div></div>
</div>