[petsc-dev] MatNest in petsc4py with empty submatrices

Chris Eldred chris.eldred at gmail.com
Thu Feb 18 12:27:53 CST 2016


Hey Lawrence,

I will give that a try, thanks!

-Chris

On Wed, Feb 17, 2016 at 3:53 PM, Lawrence Mitchell
<lawrence.mitchell at imperial.ac.uk> wrote:
> On 17/02/16 14:47, Chris Eldred wrote:
>> Hey All,
>>
>> I was wondering if anyone had used MatNest with petsc4py. I am having
>> issues trying to create a MatNest where some of the submatrices are
>> empty. In PETSc, I can just pass NULL in the array that I give to
>> MatCreateNest and it works fine. However, the following code
>
> We use it, but haven't used it with empty slots.
>
>> nest_list = [[None,None],[None,None]]
>> nest_list[0][0] = some matrix
>> nest_list[0][1] = some matrix
>> nest_list[1][0] = some matrix
>> A = PETSc.Mat().createNest(nest_list,comm=PETSc.COMM_WORLD)
>>
>> fails with:
>>   File "Mat.pyx", line 445, in petsc4py.PETSc.Mat.createNest
>> (src/petsc4py.PETSc.c:103202)
>> TypeError: Cannot convert NoneType to petsc4py.PETSc.Mat
>>
>> Is there an equivalent to NULL in petsc4py (there doesn't appear to be one)?
>>
>> If all of the entries in nest_list are filled, everything works fine.
>>
>> Any help would be appreciated!
>
> Maybe a patch like this to petsc4py?
>
> diff --git a/src/PETSc/Mat.pyx b/src/PETSc/Mat.pyx
> index f281ba0..490c58e 100644
> --- a/src/PETSc/Mat.pyx
> +++ b/src/PETSc/Mat.pyx
> @@ -460,7 +460,10 @@ cdef class Mat(Object):
>          tmp1 = oarray_p(empty_p(nr*nc), NULL, <void**>&cmats)
>          for i from 0 <= i < mr:
>              for j from 0 <= j < mc:
> -                cmats[i*mc+j] = (<Mat?>mats[i][j]).mat
> +                if mats[i][j] is None:
> +                    cmats[i*mc+j] = NULL
> +                else:
> +                    cmats[i*mc+j] = (<Mat?>mats[i][j]).mat
>          if isrows is not None:
>              tmp2 = oarray_p(empty_p(nr), NULL, <void**>&cisrows)
>              for i from 0 <= i < mr: cisrows[i] = (<IS?>isrows[i]).iset
>
>
> Untested.
>
> If you want to pass null isrows and iscols as well you'll need to do a
> similar thing there.
>
> Cheers,
>
> Lawrence
>



-- 
Chris Eldred
Postdoctoral Fellow, LAGA, University of Paris 13
PhD, Atmospheric Science, Colorado State University, 2015
DOE Computational Science Graduate Fellow (Alumni)
B.S. Applied Computational Physics, Carnegie Mellon University, 2009
chris.eldred at gmail.com



More information about the petsc-dev mailing list