[petsc-users] MatCreateSubMatrix

Matthew Knepley knepley at gmail.com
Mon Aug 12 14:03:47 CDT 2019


On Mon, Aug 12, 2019 at 2:55 PM Emmanuel Ayala via petsc-users <
petsc-users at mcs.anl.gov> wrote:

> Hello, I have some doubts.
>
> I'm trying to create a submatrix (MatCreateSubMatrix). I have an identity
> matrix A. Then, in each process, I select some indices (owned in this
> process but in global numbering) that i need to remove (only columns) from
> the matrix A. These indices are storage in an PetscInt array (arr_cols),
> created with PetscMalloc1 (size: n_cols). My goal is to use the index set
> tool (IS). For this purpose, i did the next:
>
> 1. I defined the sub-matrix (submat, specifying the size)
> 2. I created the IS for the rows, in this case taking into account the
> MatGetOwnershipRange(A,&row_low,&row_high);
> ISCreateGeneral(COMMUNICATOR,n_rows,arr_rows,PETSC_COPY_VALUES,&is_rows);.
> This consider all the rows owned by the process.
> 2. I created the IS for columns:
> ISCreateGeneral(COMMUNICATOR,n_cols,arr_col,PETSC_COPY_VALUES,&is_col);
> The range for the is_col, was defined taking into account the the columns
> that will be in IT's "diagonal part", using
> MatGetOwnershipRangeColumn(A,&col_low,&col_high);
> 3. I create the submatrix:
> MatCreateSubMatrix(A,is_row,is_col,MAT_INITIAL_MATRIX,&submat);
>
> Questions:
>
> a. Which communicator i need to use, MPI_COMM_SELF or PETSC_COMM_WORLD?
> and why?
>

You will generally use the same communicator as A. MatGetSubmatrices()
makes sequential matrices with SELF.


> b. Moreover, my approach to create the submatrix is ok?
>

It sounds right.


> c. In the example:
>
> https://www.mcs.anl.gov/petsc/petsc-current/src/ksp/ksp/examples/tutorials/ex49.c.html
> there is a line
> 1239:   ISSetBlockSize(is,2);
> what is the meaning of this line?
>

If your matrix has a blocksize, you can simplify indexing. I would get
everything working right first.

  Thanks,

     Matt


> Best regards.
>


-- 
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

https://www.cse.buffalo.edu/~knepley/ <http://www.cse.buffalo.edu/~knepley/>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20190812/d3224b53/attachment.html>


More information about the petsc-users mailing list