[petsc-users] MatNest error with null matrix blocks

Barry Smith bsmith at petsc.dev
Sun Jul 6 11:59:00 CDT 2025


 
   Yes, they are automatically initialized to something ((void*)-2 actually). They are NOT automatically initialized to PETSC_NULL_XXX

   #define PetscObjectIsNull(obj) (obj%v == 0 .or. obj%v == -2 .or. obj%v == -3)

   PETSc Fortran has multiple representations of NULL objects. When you want to pass in the meaning "I am a null" you pass  PETSC_NULL_XXX. Not the other representations.


   Barry

Why? Well, if variables were initialized to 0 and then got passed into a routine, the routine would see the 0 and think: Oh, the person does not want to set this variable (because passing x would be the same as passing PETSC_NULL_XXX).






> On Jul 4, 2025, at 9:59 PM, Randall Mackie <rlmackie862 at gmail.com> wrote:
> 
> Thanks Barry
> 
> We were confused because the online manual says:
> 
> PETSc objects are always automatically initialized when declared so you do not need to (and should not) do
> 
> type(tXXX) x = PETSC_NULL_XXX
> XXX x = PETSC_NULL_XXX
> 
> Randy
> 
> 
>> On Jul 4, 2025, at 6:56 PM, Barry Smith <bsmith at petsc.dev> wrote:
>> 
>> 
>>    You need to pass PETSC_NULL_MAT in those locations, you cannot just pass a Mat that has never been created (that is a different kind of NULL matrix :-). I have added clearer error checking in https://urldefense.us/v3/__https://gitlab.com/petsc/petsc/-/merge_requests/8526__;!!G_uCfscf7eWS!fCKFD2GQuhS7Ph3ZA3-seSvOMjhBw12nu4QDGsY2xv5BW8-DUzkyLgU0UhWOJsx21qVDDjkua97Nfr43MUTuUsk$ 
>> 
>>   Barry
>> 
>> 
>>> On Jul 4, 2025, at 10:32 AM, Randall Mackie <rlmackie862 at gmail.com> wrote:
>>> 
>>> In the process of upgrading our code to version 3.23, we have run into another issue, this time with nest matrices.
>>> 
>>> In previous versions (well to at least 3.21) it was perfectly fine to pass in null matrix blocks to create a nest matrix. There are situations where we have, for example, only diagonal blocks. That should be allowed and was and worked fine.
>>> 
>>> In petsc 3.23, that no longer is true, or perhaps we do not know what is the proper way to pass in a null matrix.
>>> 
>>> The attached example reproduces this with the following error:
>>> 
>>> [0]PETSC ERROR: Configure options: --force --with-clean=1 --with-scalar-type=complex --with-debugging=1 --with-fortran=1 --download-mpich=1 --with-cxx=0
>>> [0]PETSC ERROR: #1 PetscObjectReference() at /home/rmackie/PETSc/petsc/src/sys/objects/inherit.c:620
>>> [0]PETSC ERROR: #2 MatNestSetSubMats_Nest() at /home/rmackie/PETSc/petsc/src/mat/impls/nest/matnest.c:1407
>>> [0]PETSC ERROR: #3 MatNestSetSubMats() at /home/rmackie/PETSc/petsc/src/mat/impls/nest/matnest.c:1518
>>> [0]PETSC ERROR: #4 MatCreateNest() at /home/rmackie/PETSc/petsc/src/mat/impls/nest/matnest.c:1800
>>> [0]PETSC ERROR: #5 matnest_bug_reproducer.F90:48
>>> 
>>> 
>>> Thanks for helping with this, and thanks for all the work on the Fortran interfaces - I’ve been playing around with your new branch and am excited by all the work!
>>> 
>>> Randy
>>> <matnest_bug_reproducer.F90>
>> 
> 

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


More information about the petsc-users mailing list