<div dir="ltr">Dear all,<div><br></div><div>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.</div>
<div><br></div><div>Actually I have tried the method getValue in Vec class. But I received an error telling me that this method &quot;Can only get local values&quot;, 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</div>
<div>&quot;</div><div>[1] Invalid argument</div><div>[1] Cannot create VECSEQ on more than one process</div><div>&quot;</div><div><br></div><div><br></div><div><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Helvetica">
<span style="color: #ff42f6">Vec </span>p, x; /* initial vector, destination vector */</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Helvetica"><span style="color: #ff42f6">VecScatter </span>scatter; /* scatter context */</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Helvetica"><span style="color: #ff42f6">IS </span>from, to; /* index sets that define the scatter */</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Helvetica; color: #ff42f6">PetscScalar <span style="color: #000000">*values;</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Helvetica">int idx_from[] = {100,200}, idx_to[] = {0,1};</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Helvetica"><span style="color: #ff42f6">VecCreateSeq</span>(PETSC COMM SELF,2,&amp;x);</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Helvetica"><span style="color: #ff42f6">ISCreateGeneral</span>(PETSC COMM SELF,2,idx from,&amp;from);</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Helvetica"><span style="color: #ff42f6">ISCreateGeneral</span>(PETSC COMM SELF,2,idx to,&amp;to);</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Helvetica"><span style="color: #ff42f6">VecScatterCreate</span>(p,from,x,to,&amp;scatter);</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Helvetica"><span style="color: #ff42f6">VecScatterBegin</span>(scatter,p,x,INSERT VALUES,SCATTER FORWARD);</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Helvetica"><span style="color: #ff42f6">VecScatterEnd</span>(scatter,p,x,INSERT VALUES,SCATTER FORWARD);</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Helvetica"><span style="color: #ff42f6">VecGetArray</span>(x,&amp;values);</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Helvetica; color: #ff42f6">ISDestroy<span style="color: #000000">(from);</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Helvetica; color: #ff42f6">ISDestroy<span style="color: #000000">(to);</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Helvetica; color: #ff42f6">VecScatterDestroy<span style="color: #000000">(scatter);</span></p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Helvetica; color: #ff42f6">
<span style="color: #000000"><br></span></p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Helvetica; color: #ff42f6"><font class="Apple-style-span" color="#000000"><span class="Apple-style-span" style="font-family: arial; font-size: small; "><br>
</span></font></p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Helvetica; color: #ff42f6"><font class="Apple-style-span" color="#000000"><span class="Apple-style-span" style="font-family: arial; font-size: small; ">Thank you very much</span></font></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Helvetica; color: #ff42f6"><font class="Apple-style-span" color="#000000"><span class="Apple-style-span" style="font-family: arial; font-size: small; ">Amal</span></font></p>
</div></div>