[petsc-dev] MatNest in petsc4py with empty submatrices

Chris Eldred chris.eldred at gmail.com
Mon Feb 22 10:18:27 CST 2016


Hey Lisandro,

null = PETSc.Mat()

works as well.

-Chris

On Sun, Feb 21, 2016 at 8:55 PM, Lisandro Dalcin <dalcinl at gmail.com> wrote:
> Could you try the following?
>
> null = PETSc.Mat()
> nest_list = [[null,null],[null,null]]
>
> Anyway, I like Lawrence's patch. I'll push a fix to maint
>
>
> On 18 February 2016 at 21:27, Chris Eldred <chris.eldred at gmail.com> wrote:
>> 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
>
>
>
> --
> Lisandro Dalcin
> ============
> Research Scientist
> Computer, Electrical and Mathematical Sciences & Engineering (CEMSE)
> Extreme Computing Research Center (ECRC)
> King Abdullah University of Science and Technology (KAUST)
> http://ecrc.kaust.edu.sa/
>
> 4700 King Abdullah University of Science and Technology
> al-Khawarizmi Bldg (Bldg 1), Office # 4332
> Thuwal 23955-6900, Kingdom of Saudi Arabia
> http://www.kaust.edu.sa
>
> Office Phone: +966 12 808-0459



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