<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="Generator" content="Microsoft Word 15 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
        {font-family:"Cambria Math";
        panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0cm;
        margin-bottom:.0001pt;
        font-size:12.0pt;
        font-family:"Times New Roman",serif;}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:purple;
        text-decoration:underline;}
p.msonormal0, li.msonormal0, div.msonormal0
        {mso-style-name:msonormal;
        mso-margin-top-alt:auto;
        margin-right:0cm;
        mso-margin-bottom-alt:auto;
        margin-left:0cm;
        font-size:12.0pt;
        font-family:"Times New Roman",serif;}
span.gmailsignatureprefix
        {mso-style-name:gmail_signature_prefix;}
span.EmailStyle19
        {mso-style-type:personal-reply;
        font-family:"Calibri",sans-serif;
        color:#1F497D;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-family:"Calibri",sans-serif;
        mso-fareast-language:EN-US;}
@page WordSection1
        {size:612.0pt 792.0pt;
        margin:70.85pt 70.85pt 70.85pt 70.85pt;}
div.WordSection1
        {page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang="EN-GB" link="blue" vlink="purple">
<div class="WordSection1">
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D;mso-fareast-language:EN-US">The place where the problem is quite deep in a large code, I will try to isolate the problematic behaviour but this may take some time.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D;mso-fareast-language:EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D;mso-fareast-language:EN-US">@Matthew, is there a way in the Python API to check whether a vector is assembled?<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D;mso-fareast-language:EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D;mso-fareast-language:EN-US">Regards,<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D;mso-fareast-language:EN-US">Alexandre.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D;mso-fareast-language:EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><b><span lang="FR" style="font-size:11.0pt;font-family:"Calibri",sans-serif">De :</span></b><span lang="FR" style="font-size:11.0pt;font-family:"Calibri",sans-serif"> Matthew Knepley <knepley@gmail.com>
<br>
<b>Envoyé :</b> mardi 15 juillet 2025 16:06<br>
<b>À :</b> Jose E. Roman <jroman@dsic.upv.es><br>
<b>Cc :</b> SCOTTO Alexandre <alexandre.scotto@irt-saintexupery.com>; petsc-users@mcs.anl.gov<br>
<b>Objet :</b> Re: [petsc-users] When to perform PETSc.Vec assembly with petsc4py<o:p></o:p></span></p>
<p class="MsoNormal"><o:p> </o:p></p>
<div>
<p class="MsoNormal">We check that the x argument is assembled in MatMultTranspose(), but not y. It seems possible that y could have stashed values that get communicated when the operation is performed. Why do we not check that y is assembled?<o:p></o:p></p>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">  Thanks,<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">     Matt<o:p></o:p></p>
</div>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
<div>
<div>
<p class="MsoNormal">On Tue, Jul 15, 2025 at 9:36 AM Jose E. Roman <<a href="mailto:jroman@dsic.upv.es">jroman@dsic.upv.es</a>> wrote:<o:p></o:p></p>
</div>
<blockquote style="border:none;border-left:solid #CCCCCC 1.0pt;padding:0cm 0cm 0cm 6.0pt;margin-left:4.8pt;margin-right:0cm">
<p class="MsoNormal" style="margin-bottom:12.0pt">It is better if you can provide a full python script that we can run to reproduce the problem.<br>
<br>
Jose<br>
<br>
<br>
> El 15 jul 2025, a las 14:49, SCOTTO Alexandre <<a href="mailto:alexandre.scotto@irt-saintexupery.com" target="_blank">alexandre.scotto@irt-saintexupery.com</a>> escribió:<br>
> <br>
> Ok I get it, Vec.assemble() is mandatory whenever MPI communications are required to get the values to appropriate processes.<br>
>  To provide more information, I am in a situation where I perform a A.multTranspose(x, y), where y is a vector that has been filled in with values earlier in the process. At this stage, I no longer care of these values and I expect the multTranspose() to
 override the values. But what I get is:<br>
> ·         if I do y.assemble() before the transpose multiplication, then y is filled-in with the correct result.<br>
> ·         if I do not perform y.assemble() before the transpose multiplication, I actually get y = y + A^T(x), i.e. a result rather of the form multTransposeAdd().<br>
> ·         If I do A.multTranspose(x, y) twice, then I get the correct result y = A^T(x).<br>
>  This makes me think that I am misusing something at some points, but it is not clear what. If someone has a hint to explain this behaviour that would help me better understand how to properly use PETSc!<br>
>  Regards,<br>
> Alexandre.<br>
>  De : Matthew Knepley <<a href="mailto:knepley@gmail.com" target="_blank">knepley@gmail.com</a>><br>
> Envoyé : mardi 15 juillet 2025 14:18<br>
> À : SCOTTO Alexandre <<a href="mailto:alexandre.scotto@irt-saintexupery.com" target="_blank">alexandre.scotto@irt-saintexupery.com</a>><br>
> Cc : Jose E. Roman <<a href="mailto:jroman@dsic.upv.es" target="_blank">jroman@dsic.upv.es</a>>;
<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>
>  On Tue, Jul 15, 2025 at 8:13 AM SCOTTO Alexandre via petsc-users <<a href="mailto:petsc-users@mcs.anl.gov" target="_blank">petsc-users@mcs.anl.gov</a>> wrote:<br>
> 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>
>  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().<br>
>  Note that direct assignment to the array can only set local values. This is equivalent to VecGetArray().<br>
>    Thanks,<br>
>       Matt<br>
>  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$" 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$" 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>
>  -- 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<br>
>  <a href="https://urldefense.us/v3/__https://www.cse.buffalo.edu/*knepley/__;fg!!G_uCfscf7eWS!aZJ9246pF8FAjBBUhSi39ow-huolRMdyysnIQMJe6Lilwvn7xVXxabH5JBy-S32vOZA5Sk4Ma_pBzo5D7Xg5VlPa-UrOinlcL1nselY1pw$" target="_blank">https://www.cse.buffalo.edu/~knepley/</a><br>
<br>
<o:p></o:p></p>
</blockquote>
</div>
<div>
<p class="MsoNormal"><br clear="all">
<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<p class="MsoNormal"><span class="gmailsignatureprefix">-- </span><o:p></o:p></p>
<div>
<div>
<div>
<div>
<div>
<div>
<div>
<p class="MsoNormal">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<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal"><a href="https://urldefense.us/v3/__http://www.cse.buffalo.edu/*knepley/__;fg!!G_uCfscf7eWS!aZJ9246pF8FAjBBUhSi39ow-huolRMdyysnIQMJe6Lilwvn7xVXxabH5JBy-S32vOZA5Sk4Ma_pBzo5D7Xg5VlPa-UrOinlcL1l-T7g4GA$" target="_blank">https://www.cse.buffalo.edu/~knepley/</a><o:p></o:p></p>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</body>
</html>