<html><head><meta http-equiv="content-type" content="text/html; charset=us-ascii"></head><body style="overflow-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;"><div><br></div> Note there is also VecSetValuesLocal() that takes ghosted local indices (ghosted local indices are different from your meaning of "local indices"). See <a href="https://petsc.org/release/docs/manualpages/Vec/VecSetValuesLocal/">https://petsc.org/release/docs/manualpages/Vec/VecSetValuesLocal/</a> <a href="https://petsc.org/release/docs/manualpages/Vec/VecSetLocalToGlobalMapping/">https://petsc.org/release/docs/manualpages/Vec/VecSetLocalToGlobalMapping/</a><div><br></div><div> Barry</div><div><br><div><br><blockquote type="cite"><div>On Jan 5, 2023, at 12:41 PM, Alfredo Jaramillo <ajaramillopalma@gmail.com> wrote:</div><br class="Apple-interchange-newline"><div><div dir="ltr"><div>omg... for some reason I was thinking it takes local indices. Yes.. modifying that line the code works well.<br></div><div><br></div><div>thank you!</div><div>Alfredo<br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Thu, Jan 5, 2023 at 10:38 AM Junchao Zhang <<a href="mailto:junchao.zhang@gmail.com">junchao.zhang@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">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="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="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="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="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="font-family: "Droid Sans Mono", monospace, monospace; font-size: 14px; white-space: pre-wrap;">; </span><br><div><font face="Droid Sans Mono, monospace, monospace" color="#008000"><span style="font-size:14px;white-space:pre-wrap"><br clear="all"></span></font><div><div dir="ltr"><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" target="_blank">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="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="">1 </span><span style="color:rgb(175,0,219)">for</span><span style=""> (</span><span style="color:rgb(0,0,255)">int</span><span style=""> </span><span style="color:rgb(0,16,128)">i</span><span style=""> = </span><span style="color:rgb(9,134,88)">0</span><span style="">; </span><span style="color:rgb(0,16,128)">i</span><span style=""> < </span><span style="color:rgb(0,16,128)">ndof_local</span><span style="">; </span><span style="color:rgb(0,16,128)">i</span><span style="">++) {</span></div><div><span style="">2 </span><span style="color:rgb(38,127,153)">PetscInt</span><span style=""> </span><span style="color:rgb(0,16,128)">gl_row</span><span style=""> = (</span><span style="color:rgb(38,127,153)">PetscInt</span><span style="">)(</span><span style="color:rgb(0,16,128)">i</span><span style="">)+</span><span style="color:rgb(0,16,128)">rstart</span><span style="">;</span></div><div><span style="">3 </span><span style="color:rgb(38,127,153)">PetscScalar</span><span style=""> </span><span style="color:rgb(0,16,128)">val</span><span style=""> = (</span><span style="color:rgb(38,127,153)">PetscScalar</span><span style="">)</span><span style="color:rgb(0,16,128)">u</span><span style="">[</span><span style="color:rgb(0,16,128)">i</span><span style="">];</span></div><div><span style="">4 </span><span style="color:rgb(121,94,38)">VecSetValues</span><span style="">(x</span><span style="">,</span><span style="color:rgb(9,134,88)">1</span><span style="">,&</span><span style="color:rgb(0,16,128)">gl_row</span><span style="">,&</span><span style="color:rgb(0,16,128)">val</span><span style="">,</span><span style="color:rgb(0,112,193)">INSERT_VALUES</span><span style="">);</span></div><div><span style="">5 }</span></div><br><div><span style=""> </span><span style="color:rgb(0,128,0)">// for (int i = 0; i < ndof_local; i++) {</span></div><div><span style=""> </span><span style="color:rgb(0,128,0)">// PetscInt gl_row = (PetscInt)(i);</span></div><div><span style=""> </span><span style="color:rgb(0,128,0)">// PetscScalar val = (PetscScalar)u[i];</span></div><div><span style=""> </span><span style="color:rgb(0,128,0)">// VecSetValue(x,gl_row,val,INSERT_VALUES);</span></div><div><span style=""> </span><span style="color:rgb(0,128,0)">// }</span></div><br><div><span style=""> </span><span style="color:rgb(121,94,38)">VecAssemblyBegin</span><span style="">(x</span><span style="">);</span></div><div><span style=""> </span><span style="color:rgb(121,94,38)">VecAssemblyEnd</span><span style="">(x</span><span style="">);</span></div><div><span style=""><br></span></div><div><span style="">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=""><br></span></div><div><span style="">What could I be doing wrong?</span></div><div><span style=""><br></span></div><div><span style="">bests regards</span></div><div><span style="">Alfredo<br></span></div></div></div></div>
</blockquote></div>
</blockquote></div>
</div></blockquote></div><br></div></body></html>