[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
Sat Oct 2 17:08:38 CDT 2010


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.

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/a1050349/attachment.htm>


More information about the petsc-users mailing list