Table 2 summarizes basic PETSc matrix operations. We briefly discuss a few of these routines in more detail below.
The parallel matrix can multiply a vector with n
local entries, returning a vector with m local entries. That is,
to form the product
ierr = MatMult(Mat A,Vec x,Vec y);the vectors x and y should be generated with
ierr = VecCreateMPI(MPI_Comm comm,n,N,&x); ierr = VecCreateMPI(MPI_Comm comm,m,M,&y);By default, if the user lets PETSc decide the number of components to be stored locally (by passing in PETSC_DECIDE as the second argument to VecCreateMPI() or using VecCreate()), vectors and matrices of the same dimension are automatically compatible for parallel matrix-vector operations.
Along with the matrix-vector multiplication routine, there is
a version for the transpose of the matrix,
ierr = MatMultTrans(Mat A,Vec x,Vec y);There are also versions that add the result to another vector:
ierr = MatMultAdd(Mat A,Vec x,Vec y,Vec w); ierr = MatMultTransAdd(Mat A,Vec x,Vec y,Vec w);These routines, respectively, produce w = A*x + y and w = AT*x + y . In C it is legal for the vectors y and w to be identical. In Fortran, this situation is forbidden by the language standard, but we allow it anyway.
One can print a matrix (sequential or parallel) to the screen with the
command
ierr = MatView(Mat mat,VIEWER_STDOUT_WORLD);Other viewers can be used as well. For instance, one can draw the nonzero stucture of the matrix into the default X-window with the command
ierr = MatView(Mat mat,VIEWER_DRAW_WORLD);Use
ierr = MatView(Mat mat,Viewer viewer);where viewer was obtained with ViewerDrawOpenX(). Additional viewers and options are given in the MatView() man page and Section Viewers: Looking at PETSc Objects .
The NormType argument to MatNorm() is one of NORM_1 or NORM_INFINITY.