[petsc-users] petsc4py Vec: how to copy from one index to multiple indices of the same vector?

Amal Alghamdi amal.ghamdi at kaust.edu.sa
Sun Oct 3 00:05:39 CDT 2010


Thank you very much Barry.

On Sun, Oct 3, 2010 at 3:48 AM, Barry Smith <bsmith at mcs.anl.gov> wrote:

>
> On Oct 2, 2010, at 5:08 PM, Amal Alghamdi wrote:
>
> > Dear all,
> >
> > I would like to ask about the proper way to copy a value in vector x, let
> us say x[0] into places in the same vector, let us say x[1], x[100]. I want
> to do this using petsc4py.
>
>   In this case you can just make a scatter that comes from the vector and
> goes to the same vector. So create an IS with the entry 0 in it twice and
> another with the entry 1 and 100 now create the VecScatter with those two
> index sets and do the scatter. The resulting code will work on any number of
> processes
>
>   Barry
>
> >
> > Actually I have tried the method getValue in Vec class. But I received an
> error telling me that this method "Can only get local values", so I tried to
> follow example 10 in the manual, which is posted below, but when trying to
> create sequential vector I get the error
> > "
> > [1] Invalid argument
> > [1] Cannot create VECSEQ on more than one process
> > "
> >
> >
> > Vec p, x; /* initial vector, destination vector */
> > VecScatter scatter; /* scatter context */
> > IS from, to; /* index sets that define the scatter */
> > PetscScalar *values;
> > int idx_from[] = {100,200}, idx_to[] = {0,1};
> > VecCreateSeq(PETSC COMM SELF,2,&x);
> > ISCreateGeneral(PETSC COMM SELF,2,idx from,&from);
> > ISCreateGeneral(PETSC COMM SELF,2,idx to,&to);
> > VecScatterCreate(p,from,x,to,&scatter);
> > VecScatterBegin(scatter,p,x,INSERT VALUES,SCATTER FORWARD);
> > VecScatterEnd(scatter,p,x,INSERT VALUES,SCATTER FORWARD);
> > VecGetArray(x,&values);
> > ISDestroy(from);
> > ISDestroy(to);
> > VecScatterDestroy(scatter);
> >
> >
> > Thank you very much
> > Amal
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20101003/8c408465/attachment.htm>


More information about the petsc-users mailing list