[petsc-dev] Correct syntax for DMDA ownership ranges in petsc4py

Chris Eldred chris.eldred at gmail.com
Fri Apr 8 02:29:56 CDT 2016


Hey Matt,

Yes I have tried all possible variants:
[(8,8,4),]
([8,8,4],)
[[8,8,4],]
((8,8,4),)
and they all fail with the same
TypeError: Expected tuple, got list

However, I think I see what is happening now. In line 156
    cdef object ranges = list(ownership_ranges)
it looks like ranges is being defined as a list, rather than a tuple.
So maybe there should be a cast from list to tuple in the return
statement?

-Chris

On Thu, Apr 7, 2016 at 9:19 PM, Matthew Knepley <knepley at gmail.com> wrote:
> On Thu, Apr 7, 2016 at 2:14 PM, Chris Eldred <chris.eldred at gmail.com> wrote:
>>
>> I think what happens on the 1st version is that the input list has
>> len(3), and since the DMDA only has 1 dimension petsc4py throws the
>> first ValueError.
>
>
> Yes, you are right.
>
>>
>> As far as I can tell, the code is expecting a list of lists: ie for
>> each dimension it gets ranges[i] (where i is the index for the
>> dimension) and casts it into an array. So I tried the 2nd version,
>> which fails regardless of whether I use lists or tuples, and I don't
>> understand why.
>
>
> That function returns 'range' and the type is declared as tuple. Did you try
>
>   ownership_ranges=((8,8,4),)
>
>     Matt
>
>>
>>
>> -Chris
>>
>> On Thu, Apr 7, 2016 at 9:00 PM, Matthew Knepley <knepley at gmail.com> wrote:
>> > On Thu, Apr 7, 2016 at 1:52 PM, Chris Eldred <chris.eldred at gmail.com>
>> > wrote:
>> >>
>> >> Hey All,
>> >>
>> >> (I sent this to petsc-users a few days ago and didn't get any replies,
>> >> figured I would try here as well...)
>> >>
>> >> Does anyone know the correct syntax for setting ownership ranges for
>> >> DMDAs in petsc4py? For example, if I have a 1D DMDA with 20 vertices
>> >> and 3 processes, and I want to distribute the vertices as [8,8,4],
>> >> should the correct create call be:
>> >>
>> >> da =
>> >>
>> >> PETSc.DMDA().create(dim=1,dof=1,sizes=[20,],proc_sizes=[3,],boundary_type=[PETSc.DM.BoundaryType.PERIODIC,],
>> >> stencil_type= PETSc.DMDA.StencilType.BOX,
>> >> stencil_width=1,ownership_ranges=[8,8,4])
>> >>
>> >> or
>> >>
>> >> da =
>> >>
>> >> PETSc.DMDA().create(dim=1,dof=1,sizes=[20,],proc_sizes=[3,],boundary_type=[PETSc.DM.BoundaryType.PERIODIC,],
>> >> stencil_type= PETSc.DMDA.StencilType.BOX,
>> >> stencil_width=1,ownership_ranges=[[8,8,4],])
>> >>
>> >> For me, the 1st version fails with
>> >> ValueError: number of dimensions 1 and number ownership ranges 3
>> >> (which I expected)
>> >> but the 2nd version also fails with
>> >> TypeError: Expected tuple, got list
>> >>
>> >> I have tried using tuples instead of lists and nothing changes.
>> >> Creating without the ownership_ranges argument works fine as well. Is
>> >> there something else I am missing?
>> >
>> >
>> > Here is the code:
>> >
>> >
>> >
>> > https://bitbucket.org/petsc/petsc4py/src/b234a50085607b793fce93d5dc46307c0d9b57c4/src/PETSc/petscdmda.pxi?at=master&fileviewer=file-view-default#petscdmda.pxi-150
>> >
>> > I do not understand why the 1st version fails.
>> >
>> >    Matt
>> >
>> >>
>> >> Thanks in advance for any assistance!
>> >>
>> >> Regards,
>> >> -Chris
>> >>
>> >>
>> >> --
>> >> 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
>> >
>> >
>> >
>> >
>> > --
>> > What most experimenters take for granted before they begin their
>> > experiments
>> > is infinitely more interesting than any results to which their
>> > experiments
>> > lead.
>> > -- Norbert Wiener
>>
>>
>>
>> --
>> 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
>
>
>
>
> --
> What most experimenters take for granted before they begin their experiments
> is infinitely more interesting than any results to which their experiments
> lead.
> -- Norbert Wiener



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