[petsc-dev] PDIPDM questions

Abhyankar, Shrirang G shrirang.abhyankar at pnnl.gov
Tue Sep 15 16:00:37 CDT 2020


From: Barry Smith <bsmith at petsc.dev>
Date: Tuesday, September 15, 2020 at 1:20 PM
To: Pierre Jolivet <pierre.jolivet at enseeiht.fr>
Cc: "Abhyankar, Shrirang G" <shrirang.abhyankar at pnnl.gov>, PETSc Development <petsc-dev at mcs.anl.gov>
Subject: Re: [petsc-dev] PDIPDM questions




On Sep 15, 2020, at 12:32 AM, Pierre Jolivet <pierre.jolivet at enseeiht.fr<mailto:pierre.jolivet at enseeiht.fr>> wrote:




On 15 Sep 2020, at 2:21 AM, Abhyankar, Shrirang G <shrirang.abhyankar at pnnl.gov<mailto:shrirang.abhyankar at pnnl.gov>> wrote:

Hello Pierre,
   PDIPM works in parallel so you can have distributed Hessian, Jacobians, constraints, variables, gradients in any layout you want.  If you are using a DM then you can have it generate the Hessian.

Could you please show an example where this is the case?
pdipm->x, which I’m assuming is a working vector, is both used as input for Hessian and Jacobian functions, e.g., https://gitlab.com/petsc/petsc/-/blob/master/src/tao/constrained/impls/ipm/pdipm.c#L369 (Hessian) + https://gitlab.com/petsc/petsc/-/blob/master/src/tao/constrained/impls/ipm/pdipm.c#L473 (Jacobian)
I thus doubt that it is possible to have different layouts?
In practice, I end up with the following error when I try this (2 processes, distributed Hessian with centralized Jacobian):
[1]PETSC ERROR: --------------------- Error Message --------------------------------------------------------------
[1]PETSC ERROR: Nonconforming object sizes
[1]PETSC ERROR: Vector wrong size 14172 for scatter 0 (scatter reverse and vector to != ctx from size)
[1]PETSC ERROR: #1 VecScatterBegin() line 96 in /Users/jolivet/Documents/repositories/petsc/src/vec/vscat/interface/vscatfce.c
[1]PETSC ERROR: #2 MatMultTransposeAdd_MPIAIJ() line 1223 in /Users/jolivet/Documents/repositories/petsc/src/mat/impls/aij/mpi/mpiaij.c
[1]PETSC ERROR: #3 MatMultTransposeAdd() line 2648 in /Users/jolivet/Documents/repositories/petsc/src/mat/interface/matrix.c
[0]PETSC ERROR: Nonconforming object sizes
[0]PETSC ERROR: Vector wrong size 13790 for scatter 27962 (scatter reverse and vector to != ctx from size)
[1]PETSC ERROR: #4 TaoSNESFunction_PDIPM() line 510 in /Users/jolivet/Documents/repositories/petsc/src/tao/constrained/impls/ipm/pdipm.c
[0]PETSC ERROR: #5 TaoSolve_PDIPM() line 712 in /Users/jolivet/Documents/repositories/petsc/src/tao/constrained/impls/ipm/pdipm.c
[1]PETSC ERROR: #6 TaoSolve() line 222 in /Users/jolivet/Documents/repositories/petsc/src/tao/interface/taosolver.c
[0]PETSC ERROR: #1 VecScatterBegin() line 96 in /Users/jolivet/Documents/repositories/petsc/src/vec/vscat/interface/vscatfce.c
[0]PETSC ERROR: #2 MatMultTransposeAdd_MPIAIJ() line 1223 in /Users/jolivet/Documents/repositories/petsc/src/mat/impls/aij/mpi/mpiaij.c
[0]PETSC ERROR: #3 MatMultTransposeAdd() line 2648 in /Users/jolivet/Documents/repositories/petsc/src/mat/interface/matrix.c
[0]PETSC ERROR: #4 TaoSNESFunction_PDIPM() line 510 in /Users/jolivet/Documents/repositories/petsc/src/tao/constrained/impls/ipm/pdipm.c
[0]PETSC ERROR: #5 TaoSolve_PDIPM() line 712 in /Users/jolivet/Documents/repositories/petsc/src/tao/constrained/impls/ipm/pdipm.c
[0]PETSC ERROR: #6 TaoSolve() line 222 in /Users/jolivet/Documents/repositories/petsc/src/tao/interface/taosolver.c

I think this can be reproduced by ex1.c by just distributing the Hessian instead of having it centralized on rank 0.


Ideally, you want to have the layout below to minimize movement of matrix/vector elements across ranks.

·         The layout of vectors x, bounds on x, and gradient is same.

·         The row layout of the equality/inequality Jacobian is same as the equality/inequality constraint vector layout.

·         The column layout of the equality/inequality Jacobian is same as that for x.

Very naive question, but given that I have a single constraint, how do I split a 1 x N matrix column-wise? I thought it was not possible.

   For the standard PETSc matrix implementations dense, AIJ, BAIJ, SBAIJ, that partition matrices by row it is not possible to have different column entires stored on different ranks.

   The two PetscLayouts associated with a matrix need to match the layouts of the vector input and output for a matrix vector product. So for a matrix with a single row the output vector needs to have a layout of 1 entry on the first rank and 0 entries on the rest.  The input vector can have many layouts, one layout would be for all the entries to be on the first rank, but one could also distribute the vector entries across the ranks. But for the standard PETSc matrix implementations all the matrix entries would be on the first rank and all input vector entries would be communicated to the first process before doing the local matrix-vector product.

Right, this is how I thought the Jacobian would be stored in Pierre’s application. Having all the entries of the Jacobian on rank 0 (single row) and all the other ranks will have no entries.

   So to store the single row matrix entries across the ranks one would need a custom storage format and communication pattern. For each let's assume the input vector to the matrix-vector product has a conventional layout of [0:rend0-1,rend0-1:rend1-1,...] and let's store the matrix entries for this layout by rank so that the local multiplies can be done without any communication, hence rank 0 will have matrix columns 0,rend0-1, rank 1 will have rend0-1:rend1-1 etc.

   Let Mat_MPIColumn (for lack of a better name) be our custom data structure.

   typedef struct {
     Mat              seq;
     Vec              work;
   } Mat_MPIColumn;

     It would have a sequential matrix (AIJ or dense, or others) with 1 row and rend0-1:rend1-1 columns, call it seq. The local matrix-vector product could be calculated by MatMult(col->seq,inputvec,col->work); then a MPI_Reduce() could be used to accumulate the results from the col->work into the output vector on rank 0.

     Note this design would seem to work for not just a row matrix on process 0 but for having multiply rows on process 0 if needed.

      The custom matrix would also need a custom MatSetValues() which seems straightforward, by checking the column of the input entry it would determine what rank the  entry belonged to and on the correct rank the entry in the local seq matrix would be determined by subtracting rend(rank -1)-1 from the global column.

   So in conclusion what is required is a relatively straight-forward new matrix class that is intended for "short-fat" matrices that are stored across the ranks but whose resulting matrix-vector product is on rank 0.  I haven't thought about things like MatMultTranspose() hopefully they are not too convoluted.

Mat_MPIColumn sounds interesting. I wonder if PETSc could (should) have this as a matrix class. But, I am not sure though how many applications have a global constraint across all the variables that needs having a new Mat_MPIColumn matrix type. I’ve seen someone asking (or maybe discussing) similar stuff for TSEvent where they had an event function involving all variables.

Shri

   Questions, comments?

  Barry




Thanks,
Pierre



·         The row and column layout for the Hessian is same as x.

The tutorial example ex1 is extremely small (only 2 variables) so its implementation is very simplistic. I think, in parallel, it ships off constraints etc. to rank 0. It’s not an ideal example w.r.t demonstrating a parallel implementation. We aim to add more examples as we develop PDIPM. If you have an example to contribute then we would most welcome it and provide help on adding it.

Thanks,
Shri
From: petsc-dev <petsc-dev-bounces at mcs.anl.gov<mailto:petsc-dev-bounces at mcs.anl.gov>> on behalf of Pierre Jolivet <pierre.jolivet at enseeiht.fr<mailto:pierre.jolivet at enseeiht.fr>>
Date: Monday, September 14, 2020 at 1:52 PM
To: PETSc Development <petsc-dev at mcs.anl.gov<mailto:petsc-dev at mcs.anl.gov>>
Subject: [petsc-dev] PDIPDM questions

Hello,
In my quest to help users migrate from Ipopt to Tao, I’ve a new question.
When looking at src/tao/constrained/tutorials/ex1.c, it seems that almost everything is centralized on rank 0 (local sizes are 0 but on rank 0).
I’d like to have my Hessian distributed more naturally, as in (almost?) all other SNES/TS examples, but still keep the Jacobian of my equality constraint, which is of dimension 1 x N (N >> 1), centralized on rank 0.
Is this possible?
If not, is it possible to supply the transpose of the Jacobian, of dimension N x 1, which could then be distributed row-wise like the Hessian?
Or maybe use some trick to distribute a MatAIJ/MatDense of dimension 1 x N column-wise? Use a MatNest with as many blocks as processes?

So, just to sum up, how can I have a distributed Hessian with a Jacobian with a single row?

Thanks in advance for your help,
Pierre



-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-dev/attachments/20200915/0147c921/attachment-0001.html>


More information about the petsc-dev mailing list