2.4.4. Matrices

Up: Contents Next: Linear Solvers Previous: Vectors

Usage of PETSc matrices and vectors is similar. The user can create a new parallel or sequential matrix, A, which has M global rows and N global columns, with the routine

   ierr = MatCreate(MPI_Comm comm,int M,int N,Mat *A); 
where the matrix format can be specified at runtime. Values can then be set with the command
   ierr = MatSetValues(Mat A,int m,int *im,int n,int *in,Scalar *values,INSERT_VALUES); 
After all elements have been inserted into the matrix, it must be processed with the pair of commands
   ierr = MatAssemblyBegin(Mat A,MAT_FINAL_ASSEMBLY); 
   ierr = MatAssemblyEnd(Mat A,MAT_FINAL_ASSEMBLY); 
Chapter Matrices discusses various matrix formats as well as the details of some basic matrix manipulation routines.


Up: Contents Next: Linear Solvers Previous: Vectors