[petsc-users] SNESGetJacobian issue when added to snes/ex3.c

Barry Smith bsmith at mcs.anl.gov
Tue Apr 8 15:45:58 CDT 2014


   The first monitor is called BEFORE the Jacobian is ever created. So skip mucking with the jacobian in the 0th iteration of SNES, use the iteration argument in your SNES monitor routine.

   BTW: there is a lot of built in viewing of PETSc matrices you can do without writing your own monitor. For example in the master development of PETSc you can use

-mat_view viewer type:filename:format 

for example -mat_view prints the values to the screen in ASCII (use only for tiny matrices). -mat_view draw draws the nonzero pattern -mat_view binary:filename saves the matrix in binary format to the file filename.

   Barry

On Apr 8, 2014, at 3:18 PM, Xiangdong <epscodes at gmail.com> wrote:

> Hello everyone,
> 
> I have a question about the usage of SNESGetJacobian().
> 
> When I added the following three lines to the snes Monitor function in ex3 for viewing the Jacobian matrix:
> 
> Mat Jmat;
> ierr = SNESGetJacobian(snes,&Jmat,NULL,NULL,NULL); CHKERRQ(ierr);
> ierr = MatView(Jamt, PETSC_VIEWER_STDOUT_WORLD); CHKERRQ(ierr); 
> 
>  I got error message complaining:
> Operation done in wrong order!
> Must call MatAssemblyBegin/End() before viewing matrix!
>  MatView() line 812 in matrix.c
> 
> 
> Is the Jmat returned by SNESGetJacobian supposed to be assembled? 
> 
> Even if I add MatAssemblyBegin/End(), it still crashes by reporting argument out of range in MatSetValues_SeqAIJ() or MatSetValues_MPIAIJ().
> 
> Any suggestions?
> 
> Thank you.
> 
> Xiangdong
> 
> 



More information about the petsc-users mailing list