[petsc-users] getting a sub matrix from a matrix
Barry Smith
bsmith at mcs.anl.gov
Fri Dec 21 15:34:25 CST 2012
On Dec 21, 2012, at 3:16 PM, Nachiket Gokhale <gokhalen at gmail.com> wrote:
> I have a dense matrix A (100x100) and I want to extract a matrix B from it consisting of the first N columns of A. Is there a better way to do it than getting the column using MatGetColumnVector, followed by VecGetArray, and MatSetValues? It could also be done using MatGetSubMatrix but is seems to be more involved.
MatGetSubMatrix() is exactly for this purpose and should not be particularly involved. Use ISCreateStride() to create an IS to indicate all the rows and and another ISCreateStride to indicate the 0 to N-1 columns.
Barry
>
> Thanks,
>
> -Nachiket
More information about the petsc-users
mailing list