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

int MatGetRow(Mat mat,int row,int *ncols,int **cols,Scalar **vals)
Not Collective

Input Parameters

mat - the matrix
row - the row to get

Output Parameters

ncols - the number of nonzeros in the row
cols - if nonzero, the column numbers
vals - if nonzero, the values

Notes

This routine is provided for people who need to have direct accessto the structure of a matrix. We hope that we provide enoughhigh-level matrix routines that few users will need it.

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

For better efficiency, set cols and/or vals to PETSC_NULL if you donot wish to extract these quantities.

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

You can only have one call to MatGetRow() outstanding for a particularmatrix at a time.

Fortran Notes

The calling sequence from Fortran is
   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
where maxcols >= maximum nonzeros in any row of the matrix.

Caution

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

Keywords

matrix, row, get, extract

See Also

MatRestoreRow(), MatSetValues()

Location: src/mat/interface/matrix.c
Matrix Index
Table of Contents