[petsc-users] Question about MatGetSubMatrix

Barry Smith bsmith at petsc.dev
Sat Jul 24 00:32:48 CDT 2021


  Qi,

    MatSetLocalGlobalToGlobalMapping() is the routine that provides the information to the matrix so that one can use a "local" ordering and it will get automatically translated to the parallel PETSc ordering on the parallel matrix. Generically yes it includes the ghost point region on each MPI rank. Some DM's provide this information automatically; for DMDA it is pretty simple, for DMStag a bit more complicated. 

  You are correct, the previous manual page for MatZeroRowsLocal() incorrectly states "global" rows from 16+ years ago, likely a cut and paste error. It looks like it has been fixed in the main PETSc repository,

  Barry


> On Jul 23, 2021, at 10:50 AM, Tang, Qi <tangqi at msu.edu> wrote:
> 
> How can we use MatZeroRowsLocal? Is there any doc for the local index vs global index for a matrix?
> 
> I am asking because we are not sure about how to prepare a proper local index. Does the index include the ghost point region or not?
> 
> Qi
> 
> 
> 
> 
>> On Jul 20, 2021, at 9:30 PM, Tang, Qi <tangqi at msu.edu <mailto:tangqi at msu.edu>> wrote:
>> 
>> Hi,
>> 
>> Now I think the DMStagStencilToIndexLocal provides the local index for given (stencil) positions. How can we use that local index information to eliminate the rows? 
>> 
>> Is the following code possible:
>> 
>> MatSetLocalToGlobalMapping(…);
>> If (is_boundary){
>> PetscInt ix;
>> DMStagStencilToIndexLocal(…, &ix);
>> MatZeroRowsLocal(… &ix, …);
>> }
>> 
>> The comment of MatZeroRowsLocal said "rows - the global row indices”. But this seems inconsistent with its name, so I am confused.
>> 
>> Thanks,
>> Qi
>> 
>> 
>>> On Jul 20, 2021, at 2:18 AM, Patrick Sanan <patrick.sanan at gmail.com <mailto:patrick.sanan at gmail.com>> wrote:
>>> 
>>> Hi Qi -
>>> 
>>> I just opened a PR to make DMStagStencilToIndexLocal() public
>>> https://gitlab.com/petsc/petsc/-/merge_requests/4180 <https://urldefense.com/v3/__https://gitlab.com/petsc/petsc/-/merge_requests/4180__;!!HXCxUKc!mAeQntyQFk-B3KHmJJWuOGKXTfKh8A-uC-v9JFZHW-VbJT7ejxWH7LlaFNM-Zg$>
>>> 
>>> (Sorry for my inattention - I think I may have missed some communications in processing the flood of PETSc emails too quickly - I still plan to get some more automatic DMStag fieldsplit capabilities into main, if it's not too late).
>>> 
>>>> Am 20.07.2021 um 02:47 schrieb Tang, Qi <tangqi at msu.edu <mailto:tangqi at msu.edu>>:
>>>> 
>>>> Hi,
>>>> As a part of implementing this process by ourself, we would like to eliminate boundary dofs. By reading DMStag code, we guess we can use
>>>> DMStagStencilToIndexLocal
>>>> MatZeroRowsLocal
>>>> 
>>>> We note that DMStagStencilToIndexLocal is not explicitly defined in the header file. Is this function ready to use? And will we be able to eliminate the dofs using the above functions?
>>>> 
>>>> Thanks,
>>>> Qi
>>>> 
>>>> 
>>>> 
>>>>> On Jul 16, 2021, at 8:17 PM, Barry Smith <bsmith at petsc.dev <mailto:bsmith at petsc.dev>> wrote:
>>>>> 
>>>>> 
>>>>>   Zakariae,
>>>>> 
>>>>>     MatGetSubMatrix() was removed a long time ago, the routine is now MatCreateSubMatrix() but it does not work in way you had hoped. There is currently no mechanism to move values you put into the sub matrix back into the original larger matrix (though perhaps there should be?). 
>>>>> 
>>>>>     Please look at MatCreateSubMatrixVirtual() and also MatCreateNest() to see if either of those approaches satisfy your needs. 
>>>>> 
>>>>>     Please let us know if there are extensions that would be useful for you to accomplish what you need. 
>>>>> 
>>>>>   Barry
>>>>> 
>>>>> 
>>>>>> On Jul 16, 2021, at 7:45 PM, Jorti, Zakariae via petsc-users <petsc-users at mcs.anl.gov <mailto:petsc-users at mcs.anl.gov>> wrote:
>>>>>> 
>>>>>> Hello,
>>>>>> 
>>>>>> I have a matrix A = [A00 , A01 ; A10, A11]. 
>>>>>> I extract the submatrix A11 with MatGetSubMatrix.
>>>>>> I only know the global IS is1 and is2, so to get A11 I call: 
>>>>>> MatGetSubMatrix(A,is2,is2,MAT_INITIAL_MATRIX,&A11);
>>>>>> I want to modify A11 and update the changes on the global matrix A but I could not find any MatRestoreSubMatrix routine.
>>>>>> Is there something similar to VecGetSubVector and VecRestoreSubVector for matrices that uses only global indices?
>>>>>> Many thanks.
>>>>>> Best regards,
>>>>>> 
>>>>>> Zakariae 
>>>>> 
>>>> 
>>> 
>> 
> 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20210724/6625716f/attachment.html>


More information about the petsc-users mailing list