[petsc-users] [petsc4py] dm/examples/tutorials/ex2 in python

Francesco Caimmi francesco.caimmi at polimi.it
Tue Jun 2 09:30:35 CDT 2015


On Tuesday 02 June 2015 07:43:21 Matthew Knepley wrote:
> On Tue, Jun 2, 2015 at 4:52 AM, Francesco Caimmi <francesco.caimmi at gmail.com
> > wrote:
> > with global_vec as v:
> >         for i in xrange(start,end):
> >             v[i] = 5.0*rank
> 
> The 'with' construction just uses
> 
>   VecGetArray()
> 
> which return the raw C pointer. This is indexed from 0 always, so you want
> 
>   v[i-start] = 5.0*rank
> 
> If you want to index using [start, end), you need something like
> 
>   DMDAVecGetArray()
> 
>   Thanks,
> 
>      Matt
Matt,
thank you very much for your answer. Unfortunately I wasn't able to find 
documentation for the 'with' construction.
 
As far as I understand using DMDAVecGetArray would give me an object with 
shape (M,N) in this case, not a vector with shape M*N as global_vec, so I 
would have to resort to something different than VecGetOwnershipRange to get 
the indexes. 
I would prefer to avoid it because I don't feel it would be very clear. 
Ithink I will go with the "v[i-start]" thing .

Anyway, would it be ok to do as follows?

for i in xrange(start,end):
        global_vec[i] = 5.0*rank
global_vec.assemblyBegin()
global_vec.assemblyEnd()

I ask because, while the program works, I cannot see assembly operation in the 
C code for ex2, so I am trying to figure out why.
Is there some (python related ) reason that would make such an approach 
unwise?

Thanks,
-- 
Francesco Caimmi


More information about the petsc-users mailing list