<div dir="ltr"><div>dear PETSc developers,</div><div><br></div><div>I have a code where I copy an array to a distributed petsc vector with the next lines:</div><div><br></div><div><div style="color:rgb(0,0,0);background-color:rgb(255,255,255);font-family:"Droid Sans Mono","monospace",monospace;font-weight:normal;font-size:14px;line-height:19px;white-space:pre"><div><span style="color:rgb(0,0,0)">1        </span><span style="color:rgb(175,0,219)">for</span><span style="color:rgb(0,0,0)"> (</span><span style="color:rgb(0,0,255)">int</span><span style="color:rgb(0,0,0)"> </span><span style="color:rgb(0,16,128)">i</span><span style="color:rgb(0,0,0)"> = </span><span style="color:rgb(9,134,88)">0</span><span style="color:rgb(0,0,0)">; </span><span style="color:rgb(0,16,128)">i</span><span style="color:rgb(0,0,0)"> < </span><span style="color:rgb(0,16,128)">ndof_local</span><span style="color:rgb(0,0,0)">; </span><span style="color:rgb(0,16,128)">i</span><span style="color:rgb(0,0,0)">++) {</span></div><div><span style="color:rgb(0,0,0)">2            </span><span style="color:rgb(38,127,153)">PetscInt</span><span style="color:rgb(0,0,0)"> </span><span style="color:rgb(0,16,128)">gl_row</span><span style="color:rgb(0,0,0)"> = (</span><span style="color:rgb(38,127,153)">PetscInt</span><span style="color:rgb(0,0,0)">)(</span><span style="color:rgb(0,16,128)">i</span><span style="color:rgb(0,0,0)">)+</span><span style="color:rgb(0,16,128)">rstart</span><span style="color:rgb(0,0,0)">;</span></div><div><span style="color:rgb(0,0,0)">3            </span><span style="color:rgb(38,127,153)">PetscScalar</span><span style="color:rgb(0,0,0)"> </span><span style="color:rgb(0,16,128)">val</span><span style="color:rgb(0,0,0)"> = (</span><span style="color:rgb(38,127,153)">PetscScalar</span><span style="color:rgb(0,0,0)">)</span><span style="color:rgb(0,16,128)">u</span><span style="color:rgb(0,0,0)">[</span><span style="color:rgb(0,16,128)">i</span><span style="color:rgb(0,0,0)">];</span></div><div><span style="color:rgb(0,0,0)">4            </span><span style="color:rgb(121,94,38)">VecSetValues</span><span style="color:rgb(0,0,0)">(x</span><span style="color:rgb(0,0,0)">,</span><span style="color:rgb(9,134,88)">1</span><span style="color:rgb(0,0,0)">,&</span><span style="color:rgb(0,16,128)">gl_row</span><span style="color:rgb(0,0,0)">,&</span><span style="color:rgb(0,16,128)">val</span><span style="color:rgb(0,0,0)">,</span><span style="color:rgb(0,112,193)">INSERT_VALUES</span><span style="color:rgb(0,0,0)">);</span></div><div><span style="color:rgb(0,0,0)">5        }</span></div><br><div><span style="color:rgb(0,0,0)">        </span><span style="color:rgb(0,128,0)">// for (int i = 0; i < ndof_local; i++) {</span></div><div><span style="color:rgb(0,0,0)">        </span><span style="color:rgb(0,128,0)">//     PetscInt gl_row = (PetscInt)(i);</span></div><div><span style="color:rgb(0,0,0)">        </span><span style="color:rgb(0,128,0)">//     PetscScalar val = (PetscScalar)u[i];</span></div><div><span style="color:rgb(0,0,0)">        </span><span style="color:rgb(0,128,0)">//     VecSetValue(x,gl_row,val,INSERT_VALUES);</span></div><div><span style="color:rgb(0,0,0)">        </span><span style="color:rgb(0,128,0)">// }</span></div><br><div><span style="color:rgb(0,0,0)">        </span><span style="color:rgb(121,94,38)">VecAssemblyBegin</span><span style="color:rgb(0,0,0)">(x</span><span style="color:rgb(0,0,0)">);</span></div><div><span style="color:rgb(0,0,0)">        </span><span style="color:rgb(121,94,38)">VecAssemblyEnd</span><span style="color:rgb(0,0,0)">(x</span><span style="color:rgb(0,0,0)">);</span></div><div><span style="color:rgb(0,0,0)"><br></span></div><div><span style="color:rgb(0,0,0)">This works as expected. If, instead of using lines 1-5, I use the lines where VecSetValue is used with local indices, then the vector is null on all the processes but rank 0, and the piece of information at rank zero is incorrect.<br></span></div><div><span style="color:rgb(0,0,0)"><br></span></div><div><span style="color:rgb(0,0,0)">What could I be doing wrong?</span></div><div><span style="color:rgb(0,0,0)"><br></span></div><div><span style="color:rgb(0,0,0)">bests regards</span></div><div><span style="color:rgb(0,0,0)">Alfredo<br></span></div></div></div></div>