<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head><body style="overflow-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;"><div><br></div>  The guards are supposed to be universal, not one-offs that are put into specific locations. How come no errors with debug mode are detected in this situation?<div><br></div><div>  Barry</div><div><br id="lineBreakAtBeginningOfMessage"><div><br><blockquote type="cite"><div>On Apr 26, 2025, at 1:09 PM, Matthew Knepley <knepley@gmail.com> wrote:</div><br class="Apple-interchange-newline"><div><div dir="ltr">Junchao, should we put guards in VecSet() and LocalToGlobal() for the array lock?<div><br></div><div>  Thanks,</div><div><br></div><div>     Matt</div></div><br><div class="gmail_quote gmail_quote_container"><div dir="ltr" class="gmail_attr">On Sat, Apr 26, 2025 at 11:50 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"><div dir="ltr"><div dir="ltr"><div>Yes, that is correct.</div><div><br></div><div><div dir="ltr" class="gmail_signature"><div dir="ltr">--Junchao Zhang</div></div></div><br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Sat, Apr 26, 2025 at 10:35 AM Derek Teaney <<a href="mailto:derek.teaney@stonybrook.edu" target="_blank">derek.teaney@stonybrook.edu</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">Ok -- got it -- thanks so just do the RestoreArray before the final step, e.g. <div><br></div><div><div style="color:rgb(80,0,80)">Loop over cases </div><div style="color:rgb(80,0,80)">      VecSet(dn_local, 0.)</div><div style="color:rgb(80,0,80)">      GetArray(dn_local, &dn)  // RIGHT</div><div style="color:rgb(80,0,80)">      Fill up dn </div><div style="color:rgb(80,0,80)">      Restore Array</div><div style="color:rgb(80,0,80)">      LocalToGlobal</div><div style="color:rgb(80,0,80)">    </div></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Sat, Apr 26, 2025 at 9:50 AM Junchao Zhang <<a href="mailto:junchao.zhang@gmail.com" target="_blank">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"><div dir="ltr">On Sat, Apr 26, 2025 at 8:27 AM Derek Teaney via petsc-users <<a href="mailto:petsc-users@mcs.anl.gov" target="_blank">petsc-users@mcs.anl.gov</a>> wrote:</div><div class="gmail_quote"><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">Thanks Barry -- this solved the issue.   <div><br></div><div>"probably will be fine" was fine with 3.17 and maybe 3.19,  but definitely not fine with 3.20. </div><div><br></div><div>For others the faulty logic is:</div><div><br></div><div>GetArray(dn_local, &dn)   //WRONG</div><div>Loop over cases </div><div>     VecSet(dn_local, 0.)</div><div>      Fill up dn </div><div>      LocalToGlobal</div><div>RestoreArray</div><div><br></div><div>Where as one should do: </div><div><div><br></div><div>Loop over cases </div><div>      VecSet(dn_local, 0.)</div><div>      GetArray(dn_local, &dn)  // RIGHT</div><div>      Fill up dn </div><div>      LocalToGlobal</div><div>      RestoreArray</div></div></div></blockquote><div>The above two pieces of code are both wrong, in my view. </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><div> </div></div></div></blockquote><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><div></div></div><div>So, while nothing is copied, if I think of dn as a copy (and not a view) the logic will always be correct. </div><div><br></div><div>Now I have a related question about  "Technically you should not be calling VecSet() with any outstanding arrays but it will probably be fine."</div><div>What about  GlobalToLocal?  should I always GetArray for the local array after the GlobalToLocal</div><div><br></div><div>So,  is this  also bad logic:</div><div><br></div><div>GetArray(n_local, &n) </div><div>Loop over cases:</div><div>     GlobalToLocal(n_global, &n_local)</div><div>     do stuff with n</div><div>     LocalToGlobal(n_local, n_global)</div><div> RestoreArray</div><div><br></div></div></blockquote><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>as opposed to</div><div><br></div><div><div>Loop over cases:</div><div>     GlobalToLocal(n_global, &n_local)</div><div>     GetArray(n_local, &n) </div><div>     do stuff with n</div><div>     LocalToGlobal(n_local, n_global)</div><div>     RestoreArray</div></div><div></div></div></blockquote><div>This is also wrong.</div><div>I think the rule here is: GetArray() puts the vector in an interim state. One shall not call any vector routines (ex. LocalToGlobal/GlobalToLocal) before RestoreArray().  You can only operate on the array instead.</div><div><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> </div></div></blockquote><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></div><div>Thanks again for all your help,</div><div><br></div><div>Derek</div><div><br></div><div><br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Fri, Apr 25, 2025 at 5:30 PM Barry Smith <<a href="mailto:bsmith@petsc.dev" target="_blank">bsmith@petsc.dev</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><div><br></div>   Technically you should not be calling VecSet() with any outstanding arrays but it will probably be fine.<div><br></div><div>    Even though GetArray() does not copy the array values; both GetArray/RestoreArray and Set track the current "state" of the vector and that count might get confused if they are used improperly.</div><div><br></div><div><br id="m_7160567137056875502m_2126373319219801003m_1567668949999083421m_-4639194555589334167m_-6798224039848759460m_-7042047038681105189lineBreakAtBeginningOfMessage"><div><br><blockquote type="cite"><div>On Apr 25, 2025, at 4:42 PM, Derek Teaney <<a href="mailto:derek.teaney@stonybrook.edu" target="_blank">derek.teaney@stonybrook.edu</a>> wrote:</div><br><div><div dir="ltr">Thanks,   I am working on providing a standalone code. A related question is -  if I did have a view of a local vector provided by:<div><br></div><div>data_node ***dn_array;<br></div><div>DMDAVecGetArray(domain, dn_local, &dn_array);<br><br></div><div>Can I assume through multiple calls to VecSet that the view  dn_array is valid, or should this be restored, between calls.</div><div><br></div><div>Thanks, </div><div><br></div><div>Derek</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Fri, Apr 25, 2025 at 1:26 PM Barry Smith <<a href="mailto:bsmith@petsc.dev" target="_blank">bsmith@petsc.dev</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>  <div>   You absolutely should not need to do an assembly after a VecSet. Please post a full reproducer that demonstrates the problem.</div><div><br></div><div>  Barry</div><div><br id="m_7160567137056875502m_2126373319219801003m_1567668949999083421m_-4639194555589334167m_-6798224039848759460m_-7042047038681105189m_2436412066008797061lineBreakAtBeginningOfMessage"><div><br><blockquote type="cite"><div>On Apr 25, 2025, at 1:23 PM, Derek Teaney via petsc-users <<a href="mailto:petsc-users@mcs.anl.gov" target="_blank">petsc-users@mcs.anl.gov</a>> wrote:</div><br><div><div dir="ltr"><div>Hi, </div><div><br></div><div>I was under the (mistaken) impression that one does not need to due a VecAssemblyBegin etc following a VecSet, e.g. </div><div><br></div><div>      VecSet(dn_local, 0.);<br>      VecAssemblyBegin(dn_local) ;<br>      VecAssemblyEnd(dn_local) ;<br></div><div><br></div><div>Seems to give different results without the Assembly.  </div><div><br></div><div>Thanks for clarifying, </div><div><br></div><div>Derek</div><div><br></div><span class="gmail_signature_prefix">-- </span><br><div dir="ltr" class="gmail_signature"><div dir="ltr"><span style="font-family:Helvetica;font-size:12px">------------------------------------------------------------------------</span><br style="font-family:Helvetica;font-size:12px"><span style="font-family:Helvetica;font-size:12px"><font>Derek Teaney</font></span><div><font>Professor and Graduate Program Director<br style="font-family:Helvetica;font-size:12px"><span style="font-family:Helvetica;font-size:12px">Dept. of Physics & Astronomy</span><br style="font-family:Helvetica;font-size:12px"><span style="font-family:Helvetica;font-size:12px">Stony Brook University</span><br style="font-family:Helvetica;font-size:12px"><span style="font-family:Helvetica;font-size:12px">Stony Brook, NY 11794-3800</span><br style="font-family:Helvetica;font-size:12px"><span style="font-family:Helvetica;font-size:12px">Tel: (631) 632-4489</span><br style="font-family:Helvetica;font-size:12px"><span style="font-family:Helvetica;font-size:12px">Fax: (631) 632-9718</span></font><br style="font-family:Helvetica;font-size:12px"><span style="font-family:Helvetica;font-size:12px">e-mail: <a href="mailto:Derek.Teaney@stonybrook.edu" target="_blank">Derek.Teaney@stonybrook.edu</a></span><br style="font-family:Helvetica;font-size:12px"><span style="font-family:Helvetica;font-size:12px">------------------------------------------------------------------------</span><br style="font-family:Helvetica;font-size:12px"><div><span style="font-family:Helvetica;font-size:12px"><br></span></div></div></div></div></div>
</div></blockquote></div><br></div></div></blockquote></div><div><br clear="all"></div><div><br></div><span class="gmail_signature_prefix">-- </span><br><div dir="ltr" class="gmail_signature"><div dir="ltr"><span style="font-family:Helvetica;font-size:12px">------------------------------------------------------------------------</span><br style="font-family:Helvetica;font-size:12px"><span style="font-family:Helvetica;font-size:12px"><font>Derek Teaney</font></span><div><font>Professor and Graduate Program Director<br style="font-family:Helvetica;font-size:12px"><span style="font-family:Helvetica;font-size:12px">Dept. of Physics & Astronomy</span><br style="font-family:Helvetica;font-size:12px"><span style="font-family:Helvetica;font-size:12px">Stony Brook University</span><br style="font-family:Helvetica;font-size:12px"><span style="font-family:Helvetica;font-size:12px">Stony Brook, NY 11794-3800</span><br style="font-family:Helvetica;font-size:12px"><span style="font-family:Helvetica;font-size:12px">Tel: (631) 632-4489</span><br style="font-family:Helvetica;font-size:12px"><span style="font-family:Helvetica;font-size:12px">Fax: (631) 632-9718</span></font><br style="font-family:Helvetica;font-size:12px"><span style="font-family:Helvetica;font-size:12px">e-mail: <a href="mailto:Derek.Teaney@stonybrook.edu" target="_blank">Derek.Teaney@stonybrook.edu</a></span><br style="font-family:Helvetica;font-size:12px"><span style="font-family:Helvetica;font-size:12px">------------------------------------------------------------------------</span><br style="font-family:Helvetica;font-size:12px"><div><span style="font-family:Helvetica;font-size:12px"><br></span></div></div></div></div>
</div></blockquote></div><br></div></div></blockquote></div><div><br clear="all"></div><div><br></div><span class="gmail_signature_prefix">-- </span><br><div dir="ltr" class="gmail_signature"><div dir="ltr"><span style="font-family: Helvetica; font-size: 12px;">------------------------------------------------------------------------</span><br style="font-family: Helvetica; font-size: 12px;"><span style="font-family:Helvetica;font-size:12px"><font>Derek Teaney</font></span><div><font>Professor and Graduate Program Director<br style="font-family:Helvetica;font-size:12px"><span style="font-family:Helvetica;font-size:12px">Dept. of Physics & Astronomy</span><br style="font-family:Helvetica;font-size:12px"><span style="font-family:Helvetica;font-size:12px">Stony Brook University</span><br style="font-family:Helvetica;font-size:12px"><span style="font-family:Helvetica;font-size:12px">Stony Brook, NY 11794-3800</span><br style="font-family:Helvetica;font-size:12px"><span style="font-family:Helvetica;font-size:12px">Tel: (631) 632-4489</span><br style="font-family:Helvetica;font-size:12px"><span style="font-family:Helvetica;font-size:12px">Fax: (631) 632-9718</span></font><br style="font-family: Helvetica; font-size: 12px;"><span style="font-family: Helvetica; font-size: 12px;">e-mail: <a href="mailto:Derek.Teaney@stonybrook.edu" target="_blank">Derek.Teaney@stonybrook.edu</a></span><br style="font-family: Helvetica; font-size: 12px;"><span style="font-family: Helvetica; font-size: 12px;">------------------------------------------------------------------------</span><br style="font-family: Helvetica; font-size: 12px;"><div><span style="font-family: Helvetica; font-size: 12px;"><br></span></div></div></div></div>
</blockquote></div></div>
</blockquote></div><div><br clear="all"></div><div><br></div><span class="gmail_signature_prefix">-- </span><br><div dir="ltr" class="gmail_signature"><div dir="ltr"><span style="font-family: Helvetica; font-size: 12px;">------------------------------------------------------------------------</span><br style="font-family: Helvetica; font-size: 12px;"><span style="font-family:Helvetica;font-size:12px"><font>Derek Teaney</font></span><div><font>Professor and Graduate Program Director<br style="font-family:Helvetica;font-size:12px"><span style="font-family:Helvetica;font-size:12px">Dept. of Physics & Astronomy</span><br style="font-family:Helvetica;font-size:12px"><span style="font-family:Helvetica;font-size:12px">Stony Brook University</span><br style="font-family:Helvetica;font-size:12px"><span style="font-family:Helvetica;font-size:12px">Stony Brook, NY 11794-3800</span><br style="font-family:Helvetica;font-size:12px"><span style="font-family:Helvetica;font-size:12px">Tel: (631) 632-4489</span><br style="font-family:Helvetica;font-size:12px"><span style="font-family:Helvetica;font-size:12px">Fax: (631) 632-9718</span></font><br style="font-family: Helvetica; font-size: 12px;"><span style="font-family: Helvetica; font-size: 12px;">e-mail: <a href="mailto:Derek.Teaney@stonybrook.edu" target="_blank">Derek.Teaney@stonybrook.edu</a></span><br style="font-family: Helvetica; font-size: 12px;"><span style="font-family: Helvetica; font-size: 12px;">------------------------------------------------------------------------</span><br style="font-family: Helvetica; font-size: 12px;"><div><span style="font-family: Helvetica; font-size: 12px;"><br></span></div></div></div></div>
</blockquote></div></div>
</div>
</blockquote></div><div><br clear="all"></div><div><br></div><span class="gmail_signature_prefix">-- </span><br><div dir="ltr" class="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div>What most experimenters take for granted before they begin their experiments is infinitely more interesting than any results to which their experiments lead.<br>-- Norbert Wiener</div><div><br></div><div><a href="https://urldefense.us/v3/__http://www.cse.buffalo.edu/*knepley/__;fg!!G_uCfscf7eWS!aIL-dQ6HGo2zkrc1_qEB3XbGFGhwsiPuJRK68V4emqBz31A_jzsgI-sJS8ki4Sx6hcqI_Ya3tzpzdl8ciLTN$" target="_blank">https://www.cse.buffalo.edu/~knepley/</a><br></div></div></div></div></div></div></div>
</div></blockquote></div><br></div></body></html>