petsc-3.7.1 2016-05-15
Report Typos and Errors

# MatGetRow

Gets a row of a matrix. You MUST call MatRestoreRow() for each row that you get to ensure that your application does not bleed memory.

### Synopsis

    #include "petscmat.h"
    PetscErrorCode MatGetRow(Mat mat,PetscInt row,PetscInt *ncols,const PetscInt *cols[],const PetscScalar *vals[])

Not Collective Many br

### Input Parameters

| mat | - the matrix Many br
| row | - the row to get Many br

### Output Parameters

| ncols | - if not NULL, the number of nonzeros in the row Many br
| cols | - if not NULL, the column numbers Many br
| vals | - if not NULL, the values Many br

### Notes

This routine is provided for people who need to have direct access Many brto the structure of a matrix. We hope that we provide enough Many brhigh-level matrix routines that few users will need it. Many br

MatGetRow() always returns 0-based column indices, regardless of Many brwhether the internal representation is 0-based (default) or 1-based. Many br

For better efficiency, set cols and/or vals to NULL if you do Many brnot wish to extract these quantities. Many br

The user can only examine the values extracted with MatGetRow(); Many brthe values cannot be altered. To change the matrix entries, one Many brmust use MatSetValues(). Many br

You can only have one call to MatGetRow() outstanding for a particular Many brmatrix at a time, per processor. MatGetRow() can only obtain rows Many brassociated with the given processor, it cannot get rows from the Many brother processors; for that we suggest using MatGetSubMatrices(), then Many brMatGetRow() on the submatrix. The row indix passed to MatGetRows() Many bris in the global number of rows. Many br

### Fortran Notes

The calling sequence from Fortran is Many br

       MatGetRow(matrix,row,ncols,cols,values,ierr)
             Mat     matrix (input)
             integer row    (input)
             integer ncols  (output)
             integer cols(maxcols) (output)
             double precision (or double complex) values(maxcols) output

Many brwhere maxcols >= maximum nonzeros in any row of the matrix. Many br

### Caution

Do not try to change the contents of the output arrays (cols and vals). Many brIn some cases, this may corrupt the matrix. Many br

Many br

### See Also

MatRestoreRow(), MatSetValues(), MatGetValues(), MatGetSubMatrices(), MatGetDiagonal()

Level:advanced
Location:src/mat/interface/matrix.c
Index of all Mat routines
Table of Contents for all manual pages
Index of all manual pages

### Examples

src/mat/examples/tutorials/ex16.c.html