14.2. Viewers: Looking at PETSc Objects

Up: Contents Next: Debugging Previous: Keeping Track of Options

PETSc employs a consistent scheme for examining, printing, and saving objects through commands of the form

   ierr = XXXView(XXX obj,Viewer viewer); 
Here obj is any PETSc object of type XXX, where XXX is Mat, Vec, SNES, etc. There are several predefined viewers:
The user can control the format of ASCII printed objects with viewers created by ViewerASCIIOpen() by calling
   ierr = ViewerSetFormat(Viewer viewer,int format,char *name); 
Possible formats include VIEWER_FORMAT_ASCII_DEFAULT, VIEWER_FORMAT_ASCII_MATLAB, and VIEWER_FORMAT_ASCII_IMPL. The implementation-specific format, VIEWER_FORMAT_ASCII_IMPL, displays the object in the most natural way for a particular implementation. For example, when viewing a block diagonal matrix that has been created with MatCreateSeqBDiag(), VIEWER_FORMAT_ASCII_IMPL prints by diagonals, while VIEWER_FORMAT_ASCII_DEFAULT uses the conventional row-oriented format.

The routines

   ierr = ViewerPushFormat(Viewer viewer,int format,char *name); 
   ierr = ViewerPopFormat(Viewer viewer); 
allow one to temporarily change the format of a viewer.

As discussed above, one can output PETSc objects in binary format by first opening a binary viewer with ViewerBinaryOpen() and then using MatView(), VecView(), etc. The corresponding routines for input of a binary object have the form XXXLoad(). In particular, matrix and vector binary input is handled by the following routines:

   ierr = MatLoad(Viewer viewer,MatType outtype,Mat *newmat); 
   ierr = VecLoad(Viewer viewer,Vec *newvec); 
These routines generate parallel matrices and vectors if the viewer's communicator has more than one processor. The particular matrix and vector formats are determined from the options database; see the manual pages for details.

One can provide additional information about matrix data for matrices stored on disk by providing an optional file matrixfilename.info, where matrixfilename is the name of the file containing the matrix. The format of the optional file is the same as the .petscrc file and can (currently) contain the following:

   -matload_block_size <bs> 
   -matload_bdiag_diags <s1,s2,s3,...> 
The block size indicates the size of blocks to use if the matrix is read into a block oriented data structure (for example, MATSEQBDIAG or MATMPIBAIJ). The diagonal information s1,s2,s3,... indicates which (block) diagonals in the matrix have nonzero values.


Up: Contents Next: Debugging Previous: Keeping Track of Options