1

I'm trying to figure out how CVODE interfaces with PETSc since I've been getting a memory corruption error when running the examples. I've isolated a minimal reproducible example 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;
}

with PETSc 3.14.0 and Sundials 5.5.0 gives me

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

I'm not particularly sure how to debug this considering that not calling Petscfinalize would leave a memory leak(?) and I haven't had much experience managing memory.

0 Answers0