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

Matthew Knepley knepley at gmail.com
Wed Jun 3 13:50:13 CDT 2015


On Wed, Jun 3, 2015 at 9:37 AM, Francesco Caimmi <francesco.caimmi at polimi.it
> wrote:

>  Thank you all for your suggestions!
>
>
>
> It looks like I will have to re-read the initial parts of the manual to
> better understand the assembly operations.
>
>
>
> However I am still a bit puzzled by the fact that doing
>
>
>
> ####
>
> start, end = global_vec.getOwnershipRange()
>
>
>
> with global_vec as v:
>
> for i in xrange(end-start):
>
> v[i] = 5.0*rank
>
>
>
> viewer = PETSc.Viewer.DRAW(global_vec.comm)
>
> global_vec.view(viewer)
>
> ####
>
>
>
> or doing
>
>
>
> ####
>
> start, end = global_vec.getOwnershipRange()
>
>
>
> for i in xrange(start,end):
>
> global_vec[i] = 5.0*rank
>

It looks like Lisandro has overloaded the [] operator to translate from
local to global indices. I don't
think I would recommend this since it would lock the vector for every
entry. The code above is
a direct numpy array access.

  Thanks,

     Matt


>
>
> viewer = PETSc.Viewer.DRAW(global_vec.comm)
>
> global_vec.view(viewer)
>
> ####
>
>
>
> actually I get the _same_ output, which, btw, is the intended output, as
> far as I can tell from the output of ex2.c (after compiling it). This is
> true regardless of the number of processors (up to three).
>
> Based on what you said I expected the second piece of code to fail. Have I
> misunderstood something?
>
>
>
>
>
> --
>
> Francesco Caimmi
>
>  Laboratorio di Ingegneria dei Polimeri
>
> http://www.chem.polimi.it/polyenglab/
>
>
>
> Politecnico di Milano - Dipartimento di Chimica,
>
> Materiali e Ingegneria Chimica “Giulio Natta”
>
>
>
> P.zza Leonardo da Vinci, 32
>
> I-20133 Milano
>
> Tel. +39.02.2399.4711
>
> Fax +39.02.7063.8173
>
>
>
> francesco.caimmi at polimi.it
>
> Skype: fmglcaimmi (please arrange meetings by e-mail)
>
> GPG Public Key : http://goo.gl/64dDo
>
> On Tuesday June 2 2015 at 18:49 Jed Brown wrote:
>
>
>
> > Matthew Knepley <knepley at gmail.com> writes:
>
> > >> for i in xrange(start,end):
>
> > >> global_vec[i] = 5.0*rank
>
> > >
>
> > > No, you would need xrange(end-start):
>
> > Specifically, Python made a decision about indexing semantics that,
>
> > while not irrational, really sucks for distributed array computing. I'm
>
> > not aware of a clean way to give you nice syntax.
>



-- 
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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20150603/a025a234/attachment.html>


More information about the petsc-users mailing list