13.4. Matrices

Usage of matrices and vectors is similar. The user can create a new parallel or sequential matrix H with M global rows and N global columns, with the routine
   info = MatCreate(MPI_Comm comm,int m,int n,int M,int N,Mat *H); 
where the matrix format can be specified at runtime. The user could alternatively specify each processes' number of local rows and columns using m and n. H can then be used to store the Hessian matrix, as indicated by the above routine TaoSetHessianMat(). Matrix entries can then be set with the command
   info = MatSetValues(Mat H,int m,int *im,int n,int *in, 
                       Scalar *values,INSERT_VALUES); 
Afterall elements have been inserted into the matrix, it must be processed with the pair of commands
   info = MatAssemblyBegin(Mat H,MAT_FINAL_ASSEMBLY); 
   info = MatAssemblyEnd(Mat H,MAT_FINAL_ASSEMBLY); 
The PETSc users manual discusses various matrix formats as well as the details of some basic matrix manipulation routines.