Thank you Hong. I will look into it.

Best,
Karthik.

From: Zhang, Hong <[email protected]>
Date: Thursday, 20 April 2023 at 16:47
To: Matthew Knepley <[email protected]>, Chockalingam, Karthikeyan (STFC,DL,HC) 
<[email protected]>
Cc: [email protected] <[email protected]>
Subject: Re: [petsc-users] question about MatSetLocalToGlobalMapping
Karthik,
We built a KKT matrix in  TaoSNESJacobian_PDIPM() (see 
petsc/src/tao/constrained/impls/ipm/pdipm.c) which assembles several small 
matrices into a large KKT matrix in mpiaij format. You could take the same 
approach to insert P and P^T into your K.
FYI, I attached our paper.
Hong
________________________________
From: petsc-users <[email protected]> on behalf of Matthew 
Knepley <[email protected]>
Sent: Thursday, April 20, 2023 5:37 AM
To: Karthikeyan Chockalingam - STFC UKRI <[email protected]>
Cc: [email protected] <[email protected]>
Subject: Re: [petsc-users] question about MatSetLocalToGlobalMapping

On Thu, Apr 20, 2023 at 6:13 AM Karthikeyan Chockalingam - STFC UKRI via 
petsc-users <[email protected]<mailto:[email protected]>> wrote:

Hello,



I created a new thread, thought would it be more appropriate (and is a 
continuation of my previous post). I want to construct the below K matrix 
(which is composed of submatrices)



K = [A P^T

       P   0]



Where K is of type MatMPIAIJ. I first constructed the top left [A] using 
MatSetValues().



Now, I would like to construct the bottom left [p] and top right [p^T] using 
MatSetValuesLocal().



To use  MatSetValuesLocal(),  I first have to create a local-to-global mapping 
using ISLocalToGlobalMappingCreate. I have created two mapping row_mapping and 
column_mapping.

I do not understand why they are not the same map. Maybe I was unclear before. 
It looks like you have two fields, say phi and lambda, where lambda is a 
Lagrange multiplier imposing some constraint. Then you get a saddle point like 
this. You can imagine matrices

  (phi, phi)        --> A
  (phi, lambda) --> P^T
  (lambda, phi) --> P

So you make a L2G map for the phi field and the lambda field. Oh, you are 
calling them row and col map, but they are my phi and lambda
maps. I do not like the row and col names since in P they reverse.


Q1) At what point should I declare MatSetLocalToGlobalMapping – is it just 
before I use MatSetValuesLocal()?

Okay, it is good you are asking this because my thinking was somewhat confused. 
I think the precise steps are:

  1) Create the large saddle point matrix K

    1a) We must call 
https://petsc.org/main/manualpages/Mat/MatSetLocalToGlobalMapping/ on it. In 
the simplest case, this just maps
           the local rows numbers [0, Nrows) to the global rows numbers 
[rowStart, rowStart + Nrows).

  2) To form each piece:

    2a) Extract that block using 
https://petsc.org/main/manualpages/Mat/MatGetLocalSubMatrix/

           This gives back a Mat object that you subsequently restore using 
https://petsc.org/main/manualpages/Mat/MatRestoreLocalSubMatrix/

     2b) Insert values using 
https://petsc.org/main/manualpages/Mat/MatSetValuesLocal/

            The local indices used for insertion here are indices relative to 
the block itself, and the L2G map for this matrix
            has been rewritten to insert into that block in the larger matrix. 
Thus this looks like just calling MatSetValuesLocal()
            on the smaller matrix block, but inserts correctly into the larger 
matrix.

Therefore, the code you write code in 2) could work equally well making the 
large matrix from 1), or independent smaller matrix blocks.

Does this make sense?

  Thanks,

     Matt


I will use MatSetLocalToGlobalMapping(K, row_mapping, column_mapping) to build 
the bottom left [P].





Q2) Can now I reset the mapping as MatSetLocalToGlobalMapping(K, 
column_mapping, row_mapping) to build the top right [P^T]?





Many thanks!



Kind regards,

Karthik.




















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

Reply via email to