<div dir="ltr">Thank you very much Barry.<br><br><div class="gmail_quote">On Sun, Oct 3, 2010 at 3:48 AM, Barry Smith <span dir="ltr"><<a href="mailto:bsmith@mcs.anl.gov">bsmith@mcs.anl.gov</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<div class="im"><br>
On Oct 2, 2010, at 5:08 PM, Amal Alghamdi wrote:<br>
<br>
> Dear all,<br>
><br>
> 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.<br>
<br>
</div> 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<br>
<font color="#888888"><br>
Barry<br>
</font><div><div></div><div class="h5"><br>
><br>
> 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<br>
> "<br>
> [1] Invalid argument<br>
> [1] Cannot create VECSEQ on more than one process<br>
> "<br>
><br>
><br>
> Vec p, x; /* initial vector, destination vector */<br>
> VecScatter scatter; /* scatter context */<br>
> IS from, to; /* index sets that define the scatter */<br>
> PetscScalar *values;<br>
> int idx_from[] = {100,200}, idx_to[] = {0,1};<br>
> VecCreateSeq(PETSC COMM SELF,2,&x);<br>
> ISCreateGeneral(PETSC COMM SELF,2,idx from,&from);<br>
> ISCreateGeneral(PETSC COMM SELF,2,idx to,&to);<br>
> VecScatterCreate(p,from,x,to,&scatter);<br>
> VecScatterBegin(scatter,p,x,INSERT VALUES,SCATTER FORWARD);<br>
> VecScatterEnd(scatter,p,x,INSERT VALUES,SCATTER FORWARD);<br>
> VecGetArray(x,&values);<br>
> ISDestroy(from);<br>
> ISDestroy(to);<br>
> VecScatterDestroy(scatter);<br>
><br>
><br>
> Thank you very much<br>
> Amal<br>
<br>
</div></div></blockquote></div><br></div>