[petsc-users] CVODE N_Vector PETSc interface gives a memory corruption error

Praharsh Suryadevara surya031 at umn.edu
Wed Nov 18 22:11:07 CST 2020


Hi All,
I asked this on StackOverflow but I realized it's better off asked here,

I'm trying to use the CVODE_PETSc interface, and I've been getting
memory corruption errors I couldn't understand, so I tried to make a
minimal reproducible example for one below. Running this,

int main(int argc,char **argv)

{
    N_Vector           nvecx;
    PetscErrorCode       ierr;
    Vec                  x;
    int nr_dof = 3;
    PetscInitializeNoArguments();
    VecCreateSeq(PETSC_COMM_SELF, nr_dof, &x);
    VecZeroEntries(x);
    VecAssemblyBegin(x);
    VecAssemblyEnd(x);
    nvecx = N_VMake_Petsc(x);
    if (check_retval((void *)nvecx, "N_VMake_Petsc", 0)) return 1;
    N_VDestroy(nvecx);
    ierr = VecDestroy(&x);CHKERRQ(ierr);
    printf("Corruption is happening below\n");
    ierr = PetscFinalize();
    printf("PETSC FINALIZE\n");
    return ierr;
}

gives me

Corruption is happening below
double free or corruption (out)
[1]    14133 abort (core dumped)  ./cv_petsc_ex7

I've also attached the output of valgrind --leak-check=full
./my_program_executable &> valgrind_output.log
I'm not particularly sure why PetscFinalize is causing memory
corruption here. I'm using Sundials 5.5.0 and Petsc 3.14.0. I don't
really understand CVODE or PETSc internals or manual memory management
well since I'm new to all of them. Any help pinpointing the issue
would be appreciated.

Thank you!
Praharsh
-------------- next part --------------
A non-text attachment was scrubbed...
Name: valgrind_output.log
Type: text/x-log
Size: 19281 bytes
Desc: not available
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20201118/3a323d42/attachment-0001.bin>


More information about the petsc-users mailing list