[petsc-users] Advice Being Sought

Jed Brown jedbrown at mcs.anl.gov
Wed Apr 24 07:11:23 CDT 2013


David Scott <d.scott at ed.ac.uk> writes:
> I am uncertain what I should do precisely. With reference to the code 
> that I attached to a previous message should I insert something like
>    PetscViewer viewer
>    call MatView(B, viewer, ierr)
>    call PetscViewerBinaryOpen(PETSC_COMM_WORLD, 'BinaryMatrix',  &
>      FILE_MODE_WRITE, viewer, ierr)

You can't use the viewer before you open the viewer, so you'll have to
swap the two lines above.

>    call PetscViewerDestroy(viewer, ierr)
> in compute_matrix after B has been assembled (and similar code in 
> compute_rhs).

You can just check for error/non-convergence when you call KSPSolve and
write the matrix and vector at that time.  You can put them in the same
file:

    call PetscViewerBinaryOpen(PETSC_COMM_WORLD, 'DifficultSystem',  &
      FILE_MODE_WRITE, viewer, ierr)
    call MatView(B, viewer, ierr)  ! use KSPGetOperators() if needed
    call VecView(X, viewer, ierr)  ! use KSPGetRhs() if needed
    call PetscViewerDestroy(viewer, ierr)


More information about the petsc-users mailing list