<div dir="ltr">VecSetValue() also needs global indices, so you need <span style="font-family:"Droid Sans Mono","monospace",monospace;font-size:14px;white-space:pre-wrap;color:rgb(38,127,153)">PetscInt</span><span style="color:rgb(0,0,0);font-family:"Droid Sans Mono","monospace",monospace;font-size:14px;white-space:pre-wrap"> </span><span style="font-family:"Droid Sans Mono","monospace",monospace;font-size:14px;white-space:pre-wrap;color:rgb(0,16,128)">gl_row</span><span style="color:rgb(0,0,0);font-family:"Droid Sans Mono","monospace",monospace;font-size:14px;white-space:pre-wrap"> = (</span><span style="font-family:"Droid Sans Mono","monospace",monospace;font-size:14px;white-space:pre-wrap;color:rgb(38,127,153)">PetscInt</span><span style="color:rgb(0,0,0);font-family:"Droid Sans Mono","monospace",monospace;font-size:14px;white-space:pre-wrap">)(</span><span style="font-family:"Droid Sans Mono","monospace",monospace;font-size:14px;white-space:pre-wrap;color:rgb(0,16,128)">i</span><span style="color:rgb(0,0,0);font-family:"Droid Sans Mono","monospace",monospace;font-size:14px;white-space:pre-wrap">)+</span><span style="font-family:"Droid Sans Mono","monospace",monospace;font-size:14px;white-space:pre-wrap;color:rgb(0,16,128)">rstart</span><span style="color:rgb(0,0,0);font-family:"Droid Sans Mono","monospace",monospace;font-size:14px;white-space:pre-wrap">; </span><br><div><font color="#008000" face="Droid Sans Mono, monospace, monospace"><span style="font-size:14px;white-space:pre-wrap"><br clear="all"></span></font><div><div dir="ltr" class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr">--Junchao Zhang</div></div></div><br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Thu, Jan 5, 2023 at 11:25 AM Alfredo Jaramillo <<a href="mailto:ajaramillopalma@gmail.com">ajaramillopalma@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><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-wrap"><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>
</blockquote></div>