static char help[] = "MWE for vecdestroy crash\n\n"; #include #include int main(int argc,char **args) { PetscErrorCode ierr; PetscInt mx = 16384; /* total number of grid points in x */ PetscInt my = 16384; /* total number of grid points in y */ Vec u,u_,H; /* wave, work and transfer function vectors */ Vec slice_rid; /* vector to hold the refractive index */ Mat A; /* FFT-matrix to call FFTW via interface */ PetscViewer hdf_ref_id_viewer; /* Load refractive index */ PetscViewer hdf5_sol_viewer; /* viewer to write the solution to hdf5*/ ierr = PetscInitialize(&argc,&args,(char*)0,help);if (ierr) return ierr; /* Make FFT matrix (via interface) and create vecs aligned to it. */ PetscInt dim[2],DIM; /* FFT parameters */ dim[0] = mx; dim[1] = my; DIM = 2; ierr = MatCreateFFT(PETSC_COMM_WORLD,DIM,dim,MATFFTW,&A);CHKERRQ(ierr); /* Create vectors that are compatible with parallel layout of A - must call MatCreateVecs()! */ ierr = MatCreateVecsFFTW(A,&u,&u_,&H);CHKERRQ(ierr); ierr = VecDuplicate(u,&slice_rid); /* Write u, now containing the exit wave to hdf5. */ ierr = PetscViewerHDF5Open(PETSC_COMM_WORLD,"exit_wave.h5", FILE_MODE_WRITE,&hdf5_sol_viewer);CHKERRQ(ierr); ierr = PetscObjectSetName((PetscObject)u, "exit_wave");CHKERRQ(ierr); ierr = VecView(u,hdf5_sol_viewer);CHKERRQ(ierr); ierr = PetscViewerDestroy(&hdf5_sol_viewer);CHKERRQ(ierr); ierr = MatDestroy(&A);CHKERRQ(ierr); ierr = VecDestroy(&slice_rid);CHKERRQ(ierr); ierr = VecDestroy(&u);CHKERRQ(ierr); ierr = VecDestroy(&u_);CHKERRQ(ierr); ierr = VecDestroy(&H);CHKERRQ(ierr); ierr = PetscFinalize(); return 0; }