<div dir="ltr"><div dir="ltr">On Wed, Nov 18, 2020 at 11:11 PM Praharsh Suryadevara via petsc-users <<a href="mailto:petsc-users@mcs.anl.gov">petsc-users@mcs.anl.gov</a>> wrote:<br></div><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Hi All,<br>
I asked this on StackOverflow but I realized it's better off asked here,<br>
<br>
I'm trying to use the CVODE_PETSc interface, and I've been getting<br>
memory corruption errors I couldn't understand, so I tried to make a<br>
minimal reproducible example for one below. Running this,<br></blockquote><div><br></div><div>There is a bug in CVODE's PETSc interface:</div><div><br></div><div>==16192== Invalid write of size 8<br>==16192== at 0x4E4553C: N_VNewEmpty_Petsc (in /home/praharsh/.local/lib/libsundials_nvecpetsc.so.5.5.0)<br>==16192== by 0x4E45630: N_VMake_Petsc (in /home/praharsh/.local/lib/libsundials_nvecpetsc.so.5.5.0)<br>==16192== by 0x108AF8: main (in /home/praharsh/.local/examples/cvode/petsc/cv_petsc_ex7)<br>==16192== Address 0xfaf8708 is 0 bytes after a block of size 392 alloc'd<br>==16192== at 0x4C2FB0F: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)<br>==16192== by 0x4044922: ??? (in /var/empty/local/lib/libsundials_cvode.so.5.3.0)<br>==16192== by 0x84000001: ???<br>==16192== by 0x4E4532E: N_VNewEmpty_Petsc (in /home/praharsh/.local/lib/libsundials_nvecpetsc.so.5.5.0)<br>==16192== by 0x4E45630: N_VMake_Petsc (in /home/praharsh/.local/lib/libsundials_nvecpetsc.so.5.5.0)<br>==16192== by 0x108AF8: main (in /home/praharsh/.local/examples/cvode/petsc/cv_petsc_ex7)<br></div><div><br></div><div>An alternative is to use CVODE through PETSc, meaning you would configure using --download-sundials, and</div><div>then use the CVODE solvers from Sundials.</div><div><br></div><div> Thanks,</div><div><br></div><div> Matt</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
int main(int argc,char **argv)<br>
<br>
{<br>
N_Vector nvecx;<br>
PetscErrorCode ierr;<br>
Vec x;<br>
int nr_dof = 3;<br>
PetscInitializeNoArguments();<br>
VecCreateSeq(PETSC_COMM_SELF, nr_dof, &x);<br>
VecZeroEntries(x);<br>
VecAssemblyBegin(x);<br>
VecAssemblyEnd(x);<br>
nvecx = N_VMake_Petsc(x);<br>
if (check_retval((void *)nvecx, "N_VMake_Petsc", 0)) return 1;<br>
N_VDestroy(nvecx);<br>
ierr = VecDestroy(&x);CHKERRQ(ierr);<br>
printf("Corruption is happening below\n");<br>
ierr = PetscFinalize();<br>
printf("PETSC FINALIZE\n");<br>
return ierr;<br>
}<br>
<br>
gives me<br>
<br>
Corruption is happening below<br>
double free or corruption (out)<br>
[1] 14133 abort (core dumped) ./cv_petsc_ex7<br>
<br>
I've also attached the output of valgrind --leak-check=full<br>
./my_program_executable &> valgrind_output.log<br>
I'm not particularly sure why PetscFinalize is causing memory<br>
corruption here. I'm using Sundials 5.5.0 and Petsc 3.14.0. I don't<br>
really understand CVODE or PETSc internals or manual memory management<br>
well since I'm new to all of them. Any help pinpointing the issue<br>
would be appreciated.<br>
<br>
Thank you!<br>
Praharsh<br>
</blockquote></div><br clear="all"><div><br></div>-- <br><div dir="ltr" class="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div>What most experimenters take for granted before they begin their experiments is infinitely more interesting than any results to which their experiments lead.<br>-- Norbert Wiener</div><div><br></div><div><a href="http://www.cse.buffalo.edu/~knepley/" target="_blank">https://www.cse.buffalo.edu/~knepley/</a><br></div></div></div></div></div></div></div></div>