<div dir="ltr"><div dir="ltr">On Tue, Jul 15, 2025 at 8:13 AM SCOTTO Alexandre via petsc-users <<a href="mailto:petsc-users@mcs.anl.gov">petsc-users@mcs.anl.gov</a>> wrote:</div><div class="gmail_quote gmail_quote_container"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Hello Jose,<br>
<br>
Thanks for your answer. Then it seems that I have under the hood usages of setValues() in my code since I do not explicitly make use of it but still has problems when not assembling my vector. Do I need to assemble vectors after Mat.mult or Scatter.scatter?<br></blockquote><div><br></div><div>No. The purpose of VecAsseblyBegin/End() is to move values from processes that do not own them to the processes that do. PETSc does this automatically for MatMult() and VecScatter routines because we know exactly where values are headed. However, when users call VecSetValues(), they may set locations that are owned by other processes. We could communicate these immediately, but that might be expensive for a series of VecSetValues() calls, so we wait until you call VecAssembly().</div><div><br></div><div>Note that direct assignment to the array can only set local values. This is equivalent to VecGetArray().</div><div><br></div><div>  Thanks,</div><div><br></div><div>     Matt</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
By the way, I did not know that PETSc.Vec objects supported direct assignments like x[i] = ..., so I rather use assignments of the form x.array = ...<br>
<br>
>From what I understand from the GitHub page (<a href="https://urldefense.us/v3/__https://gitlab.com/petsc/petsc/-/blob/main/src/binding/petsc4py/src/petsc4py/PETSc/Vec.pyx__;!!G_uCfscf7eWS!f3M5SmfhSqew4tgfvFDjdLnd3q3kT_KzcCitJTJC0HRl1YvbSNBr5Uuzv6OWP1pVQBgbi_WJlekerylpGcBHQ9vsbzL1suFBQHkoPIwhdw$" rel="noreferrer" target="_blank">https://urldefense.us/v3/__https://gitlab.com/petsc/petsc/-/blob/main/src/binding/petsc4py/src/petsc4py/PETSc/Vec.pyx__;!!G_uCfscf7eWS!f3M5SmfhSqew4tgfvFDjdLnd3q3kT_KzcCitJTJC0HRl1YvbSNBr5Uuzv6OWP1pVQBgbi_WJlekerylpGcBHQ9vsbzL1suFBQHkoPIwhdw$</a> ) it seems, that doing so, we only access the local portion of the array which should not require any assemble() am I right?<br>
<br>
Best regards,<br>
Alexandre.<br>
<br>
<br>
-----Message d'origine-----<br>
De : Jose E. Roman <<a href="mailto:jroman@dsic.upv.es" target="_blank">jroman@dsic.upv.es</a>> <br>
Envoyé : mardi 15 juillet 2025 12:21<br>
À : SCOTTO Alexandre <<a href="mailto:alexandre.scotto@irt-saintexupery.com" target="_blank">alexandre.scotto@irt-saintexupery.com</a>><br>
Cc : <a href="mailto:petsc-users@mcs.anl.gov" target="_blank">petsc-users@mcs.anl.gov</a><br>
Objet : Re: [petsc-users] When to perform PETSc.Vec assembly with petsc4py<br>
<br>
Assembly is needed after a call to x.setValues() or any of its variants.<br>
<a href="https://urldefense.us/v3/__https://petsc.org/main/petsc4py/reference/petsc4py.PETSc.Vec.html*petsc4py.PETSc.Vec.setValue__;Iw!!G_uCfscf7eWS!f3M5SmfhSqew4tgfvFDjdLnd3q3kT_KzcCitJTJC0HRl1YvbSNBr5Uuzv6OWP1pVQBgbi_WJlekerylpGcBHQ9vsbzL1suFBQHlKEPOyQg$" rel="noreferrer" target="_blank">https://urldefense.us/v3/__https://petsc.org/main/petsc4py/reference/petsc4py.PETSc.Vec.html*petsc4py.PETSc.Vec.setValue__;Iw!!G_uCfscf7eWS!f3M5SmfhSqew4tgfvFDjdLnd3q3kT_KzcCitJTJC0HRl1YvbSNBr5Uuzv6OWP1pVQBgbi_WJlekerylpGcBHQ9vsbzL1suFBQHlKEPOyQg$</a> <br>
Take into account that in python the notation x[i] = ...  with call x.setValues() under the hood.<br>
<br>
Jose<br>
<br>
<br>
> El 15 jul 2025, a las 12:02, SCOTTO Alexandre via petsc-users <<a href="mailto:petsc-users@mcs.anl.gov" target="_blank">petsc-users@mcs.anl.gov</a>> escribió:<br>
> <br>
> Dear PETSc community,<br>
>  As a beginner in the MPI world and with the PETSc library, I come with a possibly very naive question.<br>
> I know from the documentation that assembling vectors must be done, but it is not clear to me when to perform this operation.<br>
> Is there a simple way to know when a vector need be assembled and when it is not?<br>
>  Thanks in advance.<br>
> Regards,<br>
> Alexandre. <br>
<br>
</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!fx-I-mCGkHBLHWAaiP_nkFN7915JhuHJsjJm8Qpi3_otAh9GDsilnbnEQsr0-PfcqLdM5RdSw58rYq7e9dsG$" target="_blank">https://www.cse.buffalo.edu/~knepley/</a><br></div></div></div></div></div></div></div></div>