Matrix blocks
Barry Smith
bsmith at mcs.anl.gov
Tue Sep 9 07:26:26 CDT 2008
From the manual page:
This routine creates the matrices in submat; you should NOT create
them before
calling it. It also allocates the array of matrix pointers submat.
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
You should declare Mat *submat; // no 4 here
then pass &submat into the function call
Also note note from the manual page:
MatGetSubMatrices() can extract ONLY sequential submatrices
(from both sequential and parallel matrices). Use MatGetSubMatrix()
to extract a parallel submatrix.
Perhaps you really want to use MatGetSubMatrix()? Or perhaps you
want to
use the PCFIELDSPLIT preconditioner that is in petsc-dev http://www-unix.mcs.anl.gov/petsc/petsc-as/developers/index.html
Barry
On Sep 9, 2008, at 7:05 AM, Michel Cancelliere wrote:
> Ok, I'm using MatGetSubMatrix() with the following piece of code
>
> PetscErrorCode SampleShellPCSetUp(SampleShellPC *shell,Mat pmat,Vec x)
> {
> Mat *submat[4];
> PetscErrorCode ierr;
> PetscInt N;
> IS set1[4],set2[4];
>
>
>
> ierr = VecGetSize(x,&N);CHKERRQ(ierr);
> ierr = ISCreateStride(PETSC_COMM_SELF,N/
> 2,0,1,&set1[0]);CHKERRQ(ierr);
> ierr = ISCreateStride(PETSC_COMM_SELF,N/
> 2,0,1,&set2[0]);CHKERRQ(ierr);
> ierr = ISCreateStride(PETSC_COMM_SELF,N/
> 2,0,1,&set1[1]);CHKERRQ(ierr);
> ierr = ISCreateStride(PETSC_COMM_SELF,N/2,N/
> 2,1,&set2[1]);CHKERRQ(ierr);
> ierr = ISCreateStride(PETSC_COMM_SELF,N/2,N/
> 2,1,&set1[2]);CHKERRQ(ierr);
> ierr = ISCreateStride(PETSC_COMM_SELF,N/
> 2,0,1,&set2[2]);CHKERRQ(ierr);
> ierr = ISCreateStride(PETSC_COMM_SELF,N/2,N/
> 2,1,&set1[3]);CHKERRQ(ierr);
> ierr = ISCreateStride(PETSC_COMM_SELF,N/2,N/
> 2,1,&set2[3]);CHKERRQ(ierr);
> ierr = MatGetSubMatrices(pmat,
> 4,set1,set2,MAT_INITIAL_MATRIX,submat);CHKERRQ(ierr);
>
> but it seems to get only the first of the subblocks,
>
> am I using the correct syntax for the MatGetSubMatrices function?
>
> Thank you
>
> On Fri, Sep 5, 2008 at 2:42 PM, Matthew Knepley <knepley at gmail.com>
> wrote:
> You can extract matrix blocks using MatGetSubMatrix().
>
> Matt
>
> On Fri, Sep 5, 2008 at 6:50 AM, Michel Cancelliere
> <fernandez858 at gmail.com> wrote:
> > Hi All,
> >
> > I am building a shell preconditioner, for implement that I should
> divide a
> > sparse matrix into four blocks of dimension N/2xN/2 (N size of the
> Matrix),
> > I took a look to src/mat/examples/tutorials/ex2 but it is for
> dense matrix.
> > There is a function for do that in Petsc? or another method for
> efficiently
> > implementation?
> >
> > Thank you,
> >
> > Michel Cancelliere
> >
>
>
>
> --
> What most experimenters take for granted before they begin their
> experiments is infinitely more interesting than any results to which
> their experiments lead.
> -- Norbert Wiener
>
>
More information about the petsc-users
mailing list