[petsc-dev] MATOP_MAT_MULT

Pierre Jolivet pierre.jolivet at enseeiht.fr
Wed Apr 22 00:06:18 CDT 2020



> On 22 Apr 2020, at 12:05 AM, Zhang, Hong <hzhang at mcs.anl.gov> wrote:
> 
> Pierre,
> The old API, MatMatMult(), MatPtAP() ... are still available as wrappers to the new API:
>> MatProductCreate()
>> MatProductSetType(,MATPRODUCT_AB/PtAP)
>> MatProductSetFromOptions()
>> MatProductSymbolic()
>> MatProductNumeric()
> You do not need to change your code.

Yes, of course. My concern is not the MatMatMult operation itself, it’s how to know if a MatMatMult implementation is available for a given stencil (A, B).

> When you call MatMatMult() with seqsbaij and dense matrices, a detailed error message will be out from MatProductSetFromOptions() (or MatMatMult() if you use the wrapper).

Well, that’s just not an option. I don’t want the code to error, I want a fallback mechanism so that I can do the MatMatMult myself, column by column (or implement this as part of issue #608 in the case of dense B and C so neither José nor me have to bother about this again).
That makes MatMatMult very hard to use now, because you can’t tell a priori if your code will run or not if the types of your A and B are variable (because of an unimplemented MatMatMult).

> I'll discuss Jose's usage in next email.

What you propose there looks good to me.
(Though I’d like to be able to skip MatProductSymbolic() in the case of a dense Wmat allocated in user code, but this is very minor)

Thanks,
Pierre

> Hong
> From: Pierre Jolivet <pierre.jolivet at enseeiht.fr>
> Sent: Tuesday, April 21, 2020 10:53 AM
> To: Zhang, Hong <hzhang at mcs.anl.gov>
> Cc: petsc-dev <petsc-dev at mcs.anl.gov>
> Subject: Re: [petsc-dev] MATOP_MAT_MULT
>  
> 
> 
>> On 21 Apr 2020, at 5:22 PM, Zhang, Hong <hzhang at mcs.anl.gov <mailto:hzhang at mcs.anl.gov>> wrote:
>> 
>> Pierre,
>> MatMatMult_xxx() is removed from MatOps table.
> 
> Shouldn’t there be a deprecation notice somewhere?
> There is nothing about MATOP_MAT_MULT in the 3.13 changelog https://www.mcs.anl.gov/petsc/documentation/changes/313.html <https://www.mcs.anl.gov/petsc/documentation/changes/313.html>
> For example, I see that in SLEPc, José is currently making these checks, which are in practice useless as they always return PETSC_FALSE? https://gitlab.com/slepc/slepc/-/blob/master/src/sys/classes/bv/impls/contiguous/contig.c#L191 <https://gitlab.com/slepc/slepc/-/blob/master/src/sys/classes/bv/impls/contiguous/contig.c#L191>
> (Maybe José is aware of this and this is just for testing)
> 
>> MatMatMult() is replaced by
>> MatProductCreate()
>> MatProductSetType(,MATPRODUCT_AB)
>> MatProductSetFromOptions()
>> MatProductSymbolic()
>> MatProductNumeric()
>> 
>> Where/when do you need query a single matrix for its product operation?
> 
> I didn’t want to bother at first with the new API, because I’m only interested in C = A*B with C and B being dense.
> Of course, I can update my code, but if I understand Stefano’s issue correctly, and let’s say my A is of type SBAIJ, for which there is no MatMatMult, the code will now error out in the MatProduct?
> There is no fallback mechanism? Meaning I could in fact _not_ use the new API and will just have to loop on all columns of B, even for AIJ matrices.
> 
> Thanks,
> Pierre
> 
>> Hong
>> 
>>   
>> 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>>
>> Sent: Tuesday, April 21, 2020 7:50 AM
>> To: petsc-dev <petsc-dev at mcs.anl.gov <mailto:petsc-dev at mcs.anl.gov>>
>> Subject: [petsc-dev] MATOP_MAT_MULT
>>  
>> Hello,
>> Am I seeing this correctly?
>> #include <petsc.h>
>> 
>> int main(int argc,char **args)
>> {
>>   Mat               A;
>>   PetscBool         hasMatMult;
>>   PetscErrorCode    ierr;
>> 
>>   ierr = PetscInitialize(&argc,&args,NULL,NULL);if (ierr) return ierr;
>>   ierr = MatCreate(PETSC_COMM_WORLD,&A);CHKERRQ(ierr);
>>   ierr = MatSetType(A,MATMPIAIJ);CHKERRQ(ierr);
>>   ierr = MatHasOperation(A,MATOP_MAT_MULT,&hasMatMult);CHKERRQ(ierr);
>>   printf("%s\n", PetscBools[hasMatMult]);
>>   ierr = PetscFinalize();
>>   return ierr;
>> }
>> 
>> => FALSE
>> 
>> I believe this is a regression (or at least an undocumented change) introduced here: https://gitlab.com/petsc/petsc/-/merge_requests/2524/ <https://gitlab.com/petsc/petsc/-/merge_requests/2524/>
>> I also believe Stefano raised a similar point there: https://gitlab.com/petsc/petsc/-/issues/608 <https://gitlab.com/petsc/petsc/-/issues/608>
>> This is a performance killer in my case because I was previously using this check to know whether I could use MatMatMult or had to loop on all columns and call MatMult on all of them.
>> There is also a bunch of (previously functioning but now) broken code, e.g., https://www.mcs.anl.gov/petsc/petsc-current/src/mat/impls/transpose/transm.c.html#line105 <https://www.mcs.anl.gov/petsc/petsc-current/src/mat/impls/transpose/transm.c.html#line105> or https://www.mcs.anl.gov/petsc/petsc-current/src/mat/impls/nest/matnest.c.html#line2105 <https://www.mcs.anl.gov/petsc/petsc-current/src/mat/impls/nest/matnest.c.html#line2105>
>> Is this being addressed/documented?
>> 
>> Thanks,
>> Pierre

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


More information about the petsc-dev mailing list