<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=Windows-1252">
<style type="text/css" style="display:none;"> P {margin-top:0;margin-bottom:0;} </style>
</head>
<body dir="ltr">
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
Pierre,</div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
I believe you are in the correct direction for debugging <span style="font-family:"Segoe UI", "Segoe UI Web (West European)", "Segoe UI", -apple-system, "system-ui", Roboto, "Helvetica Neue", sans-serif;font-size:14px;background-color:rgb(255, 255, 255);display:inline !important">MatProductReplaceMats()<span> .
 I 'll investigate it and let you know the result. </span></span></div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<span style="font-family:"Segoe UI", "Segoe UI Web (West European)", "Segoe UI", -apple-system, "system-ui", Roboto, "Helvetica Neue", sans-serif;font-size:14px;background-color:rgb(255, 255, 255);display:inline !important"><span>Hong</span></span></div>
<div id="appendonsend"></div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
<br>
</div>
<hr tabindex="-1" style="display:inline-block; width:98%">
<div id="divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif" color="#000000" style="font-size:11pt"><b>From:</b> Pierre Jolivet <pierre@joliv.et><br>
<b>Sent:</b> Friday, July 15, 2022 12:01 AM<br>
<b>To:</b> Zhang, Hong <hzhang@mcs.anl.gov><br>
<b>Cc:</b> Barry Smith <bsmith@petsc.dev>; For users of the development version of PETSc <petsc-dev@mcs.anl.gov><br>
<b>Subject:</b> Re: [petsc-dev] MatProduct_AtB --with-scalar-type=complex</font>
<div> </div>
</div>
<div class="" style="word-wrap:break-word; line-break:after-white-space">Barry,
<div class="">MatTransposeMatMultSymbolic_SeqAIJ_SeqAIJ() is indeed called.</div>
<div class="">product->alg is default, square is PETSC_FALSE.</div>
<div class=""><br class="">
</div>
<div class="">Hong,</div>
<div class="">I believe the issue comes from the fact that atb->updateAt is PETSC_FALSE in MatProductNumeric_AtB_SeqAIJ_SeqAIJ().</div>
<div class="">If the name of this variable is relevant to its purpose, I believe it should be set to PETSC_TRUE when calling MatProductReplaceMats() whenever A is changed.</div>
<div class="">I would prefer using MatProductReplaceMats() because I’m implementing the same MatConvert() as MatNormal for the Hermitian case and it’s the only way to reuse the symbolic product, cf. <a href="https://petsc.org/main/src/mat/impls/normal/normm.c.html#line315" data-auth="NotApplicable" class="">https://petsc.org/main/src/mat/impls/normal/normm.c.html#line315</a> in
 the case where --with-scalar-type=real<br class="">
<div><br class="">
</div>
<div>Thanks,</div>
<div>Pierre</div>
<div><br class="">
<blockquote type="cite" class="">
<div class="">On 15 Jul 2022, at 5:52 AM, Zhang, Hong <<a href="mailto:hzhang@mcs.anl.gov" data-auth="NotApplicable" class="">hzhang@mcs.anl.gov</a>> wrote:</div>
<br class="x_Apple-interchange-newline">
<div class="">
<div class="" style="font-style:normal; font-variant-caps:normal; font-weight:400; letter-spacing:normal; text-align:start; text-indent:0px; text-transform:none; white-space:normal; word-spacing:0px; text-decoration:none; font-family:Calibri,Arial,Helvetica,sans-serif; font-size:12pt">
<span class="" style="color:rgb(32,31,30); font-size:14.6667px; background-color:rgb(255,255,255); display:inline!important">Pierre,</span><br class="">
</div>
<div class="" style="font-style:normal; font-variant-caps:normal; font-weight:400; letter-spacing:normal; text-align:start; text-indent:0px; text-transform:none; white-space:normal; word-spacing:0px; text-decoration:none; font-family:Calibri,Arial,Helvetica,sans-serif; font-size:12pt">
<span class="" style="color:rgb(32,31,30); font-size:14.6667px; background-color:rgb(255,255,255); display:inline!important">Our MatProductReplaceMats() is not well tested, which might be buggy. I simplified your code without calling <span class="" style="background-color:rgb(255,255,255); display:inline!important">MatProductReplaceMats()
 and got correct results in the cases</span></span></div>
<div class="" style="font-style:normal; font-variant-caps:normal; font-weight:400; letter-spacing:normal; text-align:start; text-indent:0px; text-transform:none; white-space:normal; word-spacing:0px; text-decoration:none; font-family:Calibri,Arial,Helvetica,sans-serif; font-size:12pt">
<span class="" style="color:rgb(32,31,30); font-size:14.6667px; background-color:rgb(255,255,255); display:inline!important"><span class="" style="background-color:rgb(255,255,255); display:inline!important">./ex1111 -product_view ::ascii_matlab -convert false/true <span class="" style="background-color:rgb(255,255,255); display:inline!important">-correct
 false</span><br class="">
</span></span></div>
<div class="" style="font-style:normal; font-variant-caps:normal; font-weight:400; letter-spacing:normal; text-align:start; text-indent:0px; text-transform:none; white-space:normal; word-spacing:0px; text-decoration:none; font-family:Calibri,Arial,Helvetica,sans-serif; font-size:12pt">
<span class="" style="color:rgb(32,31,30); font-size:14.6667px; background-color:rgb(255,255,255); display:inline!important"><span class="" style="background-color:rgb(255,255,255); display:inline!important">and</span></span></div>
<div class="" style="font-style:normal; font-variant-caps:normal; font-weight:400; letter-spacing:normal; text-align:start; text-indent:0px; text-transform:none; white-space:normal; word-spacing:0px; text-decoration:none; font-family:Calibri,Arial,Helvetica,sans-serif; font-size:12pt">
<span class="" style="color:rgb(32,31,30); font-size:14.6667px; background-color:rgb(255,255,255); display:inline!important"><span class="" style="background-color:rgb(255,255,255); display:inline!important">./ex1111 -product_view ::ascii_matlab -convert false/true
 -correct true<br class="">
</span></span></div>
<div class="" style="font-style:normal; font-variant-caps:normal; font-weight:400; letter-spacing:normal; text-align:start; text-indent:0px; text-transform:none; white-space:normal; word-spacing:0px; text-decoration:none; font-family:Calibri,Arial,Helvetica,sans-serif; font-size:12pt">
<span class="" style="color:rgb(32,31,30); font-size:14.6667px; background-color:rgb(255,255,255); display:inline!important"><span class="" style="background-color:rgb(255,255,255); display:inline!important"><br class="">
</span></span></div>
<div class="" style="font-family:Helvetica; font-size:12px; font-style:normal; font-variant-caps:normal; font-weight:400; letter-spacing:normal; text-align:start; text-indent:0px; text-transform:none; white-space:normal; word-spacing:0px; text-decoration:none">
<font color="#201f1e" class=""><span class="" style="font-size:14.6667px">My code is attached. I'll investigate <span class="" style="background-color:rgb(255,255,255); display:inline!important">MatProductReplaceMats().</span></span></font></div>
<div class="" style="font-family:Helvetica; font-size:12px; font-style:normal; font-variant-caps:normal; font-weight:400; letter-spacing:normal; text-align:start; text-indent:0px; text-transform:none; white-space:normal; word-spacing:0px; text-decoration:none">
<font color="#201f1e" class=""><span class="" style="font-size:14.6667px">Hong</span></font></div>
<div class="" style="font-style:normal; font-variant-caps:normal; font-weight:400; letter-spacing:normal; text-align:start; text-indent:0px; text-transform:none; white-space:normal; word-spacing:0px; text-decoration:none; font-family:Calibri,Arial,Helvetica,sans-serif; font-size:12pt">
<span class="" style="color:rgb(32,31,30); font-size:14.6667px; background-color:rgb(255,255,255); display:inline!important"><span class="" style="background-color:rgb(255,255,255); display:inline!important"><br class="">
</span></span></div>
<div class="" style="font-style:normal; font-variant-caps:normal; font-weight:400; letter-spacing:normal; text-align:start; text-indent:0px; text-transform:none; white-space:normal; word-spacing:0px; text-decoration:none; font-family:Calibri,Arial,Helvetica,sans-serif; font-size:12pt">
<span class="" style="color:rgb(32,31,30); font-size:14.6667px; background-color:rgb(255,255,255); display:inline!important"><span class="" style="background-color:rgb(255,255,255); display:inline!important"><br class="">
</span></span></div>
<div class="" style="font-style:normal; font-variant-caps:normal; font-weight:400; letter-spacing:normal; text-align:start; text-indent:0px; text-transform:none; white-space:normal; word-spacing:0px; text-decoration:none; font-family:Calibri,Arial,Helvetica,sans-serif; font-size:12pt">
<span class="" style="color:rgb(32,31,30); font-size:14.6667px; background-color:rgb(255,255,255); display:inline!important"><span class="" style="background-color:rgb(255,255,255); display:inline!important"><br class="">
</span></span></div>
<div class="" style="font-style:normal; font-variant-caps:normal; font-weight:400; letter-spacing:normal; text-align:start; text-indent:0px; text-transform:none; white-space:normal; word-spacing:0px; text-decoration:none; font-family:Calibri,Arial,Helvetica,sans-serif; font-size:12pt">
<span class="" style="color:rgb(32,31,30); font-size:14.6667px; background-color:rgb(255,255,255); display:inline!important"><span class="" style="background-color:rgb(255,255,255); display:inline!important"><br class="">
</span></span></div>
<div id="x_appendonsend" class="" style="font-family:Helvetica; font-size:12px; font-style:normal; font-variant-caps:normal; font-weight:400; letter-spacing:normal; text-align:start; text-indent:0px; text-transform:none; white-space:normal; word-spacing:0px; text-decoration:none">
</div>
<hr tabindex="-1" class="" style="font-family:Helvetica; font-size:12px; font-style:normal; font-variant-caps:normal; font-weight:400; letter-spacing:normal; text-align:start; text-indent:0px; text-transform:none; white-space:normal; word-spacing:0px; text-decoration:none; display:inline-block; width:1154.4375px">
<span class="" style="font-family:Helvetica; font-size:12px; font-style:normal; font-variant-caps:normal; font-weight:400; letter-spacing:normal; text-align:start; text-indent:0px; text-transform:none; white-space:normal; word-spacing:0px; text-decoration:none; float:none; display:inline!important"></span>
<div id="x_divRplyFwdMsg" dir="ltr" class="" style="font-family:Helvetica; font-size:12px; font-style:normal; font-variant-caps:normal; font-weight:400; letter-spacing:normal; text-align:start; text-indent:0px; text-transform:none; white-space:normal; word-spacing:0px; text-decoration:none">
<font face="Calibri, sans-serif" class="" style="font-size:11pt"><b class="">From:</b><span class="x_Apple-converted-space"> </span>petsc-dev <<a href="mailto:petsc-dev-bounces@mcs.anl.gov" data-auth="NotApplicable" class="">petsc-dev-bounces@mcs.anl.gov</a>>
 on behalf of Barry Smith <<a href="mailto:bsmith@petsc.dev" data-auth="NotApplicable" class="">bsmith@petsc.dev</a>><br class="">
<b class="">Sent:</b><span class="x_Apple-converted-space"> </span>Thursday, July 14, 2022 4:38 PM<br class="">
<b class="">To:</b><span class="x_Apple-converted-space"> </span>Pierre Jolivet <<a href="mailto:pierre@joliv.et" data-auth="NotApplicable" class="">pierre@joliv.et</a>><br class="">
<b class="">Cc:</b><span class="x_Apple-converted-space"> </span>For users of the development version of PETSc <<a href="mailto:petsc-dev@mcs.anl.gov" data-auth="NotApplicable" class="">petsc-dev@mcs.anl.gov</a>><br class="">
<b class="">Subject:</b><span class="x_Apple-converted-space"> </span>Re: [petsc-dev] MatProduct_AtB --with-scalar-type=complex</font>
<div class=""> </div>
</div>
<div class="x_BodyFragment" style="font-family:Helvetica; font-size:12px; font-style:normal; font-variant-caps:normal; font-weight:400; letter-spacing:normal; text-align:start; text-indent:0px; text-transform:none; white-space:normal; word-spacing:0px; text-decoration:none">
<font size="2" class=""><span class="" style="font-size:11pt">
<div class="x_PlainText"><br class="">
  Can you confirm if MatTransposeMatMultSymbolic_SeqAIJ_SeqAIJ() ends up being called for you and what path it takes inside that routine (depends) on the algorithm it is using.<span class="x_Apple-converted-space"> </span><br class="">
<br class="">
<br class="">
<br class="">
> On Jul 14, 2022, at 4:30 PM, Pierre Jolivet <<a href="mailto:pierre@joliv.et" data-auth="NotApplicable" class="">pierre@joliv.et</a>> wrote:<br class="">
><span class="x_Apple-converted-space"> </span><br class="">
> Hello,<br class="">
> In the following example, the SeqAIJ implementation of MatProduct_AtB produce a different (and wrong) result, compared to the SeqDense implementation or MATLAB.<br class="">
> I want to compute B = A^H A (where ^H is the Hermitian transpose).<br class="">
> So I create a MatProduct with A and A.<br class="">
> Duplicate A into another Mat which I conjugate.<br class="">
> And I replace the first Mat of the product with this conjugate.<br class="">
> I expect to get the proper result, which I don’t.<br class="">
> Is the MatProduct_AtB implementation in the complex case not computing A^T B (where ^T is the transpose)?<span class="x_Apple-converted-space"> </span><br class="">
> For reference, here is how to properly compute A^H A with current main: conj(A^H conj(A)) — so it requires an extra MatConjugate I’d like to avoid.<br class="">
><span class="x_Apple-converted-space"> </span><br class="">
> Thanks,<br class="">
> Pierre<br class="">
><span class="x_Apple-converted-space"> </span><br class="">
> <ex1111.c><br class="">
><span class="x_Apple-converted-space"> </span><br class="">
> $ ./ex1111 -product_view ::ascii_matlab -A_view ::ascii_matlab -convert false              <span class="x_Apple-converted-space"> </span><br class="">
> %Mat Object: 1 MPI process<br class="">
> %  type: seqdense<br class="">
> % Size = 2 2<span class="x_Apple-converted-space"> </span><br class="">
> Mat_0xc4000001_0 = zeros(2,2);<br class="">
> Mat_0xc4000001_0 = [<br class="">
> 7.2003197397953400e-01 + 6.1793966542126100e-02i 3.9777780919128602e-01 + 7.3036588248200474e-02i<span class="x_Apple-converted-space"> </span><br class="">
> 1.0022337819588500e-02 + 1.4463931936456476e-01i 1.0386628927366459e-01 + 2.5078039364333193e-01i<span class="x_Apple-converted-space"> </span><br class="">
> ];<br class="">
> %Mat Object: 1 MPI process<br class="">
> %  type: seqdense<br class="">
> % Size = 2 2<span class="x_Apple-converted-space"> </span><br class="">
> Mat_0xc4000001_1 = zeros(2,2);<br class="">
> Mat_0xc4000001_1 = [<br class="">
> 5.4328551781548817e-01 + 0.0000000000000000e+00i 3.2823965013353340e-01 + 1.5498666614872689e-02i<span class="x_Apple-converted-space"> </span><br class="">
> 3.2823965013353340e-01 + -1.5498666614872689e-02i 2.3724054059134142e-01 + 0.0000000000000000e+00i<span class="x_Apple-converted-space"> </span><br class="">
> ];<br class="">
><span class="x_Apple-converted-space"> </span><br class="">
> $ ./ex1111 -product_view ::ascii_matlab -convert true                      <span class="x_Apple-converted-space"> </span><br class="">
> %Mat Object: 1 MPI process<br class="">
> %  type: seqaij<br class="">
> % Size = 2 2<span class="x_Apple-converted-space"> </span><br class="">
> % Nonzeros = 4<span class="x_Apple-converted-space"> </span><br class="">
> zzz = zeros(4,4);<br class="">
> zzz = [<br class="">
> 1 1  4.9380746380098023e-01 9.1886511660038694e-02<br class="">
> 1 2  2.4666779825931440e-01 9.4705502650537468e-02<br class="">
> 2 1  2.4666779825931440e-01 9.4705502650537468e-02<br class="">
> 2 2  1.0079024247365802e-01 1.1019992594899400e-01<br class="">
> ];<br class="">
> Mat_0xc4000001_0 = spconvert(zzz);<br class="">
><span class="x_Apple-converted-space"> </span><br class="">
> $ ./ex1111 -product_view ::ascii_matlab -convert true -correct true<br class="">
> %Mat Object: 1 MPI process<br class="">
> %  type: seqaij<br class="">
> % Size = 2 2<span class="x_Apple-converted-space"> </span><br class="">
> % Nonzeros = 4<span class="x_Apple-converted-space"> </span><br class="">
> zzz = zeros(4,4);<br class="">
> zzz = [<br class="">
> 1 1  5.4328551781548828e-01 -0.0000000000000000e+00<br class="">
> 1 2  3.2823965013353340e-01 1.5498666614872696e-02<br class="">
> 2 1  3.2823965013353340e-01 -1.5498666614872696e-02<br class="">
> 2 2  2.3724054059134142e-01 -0.0000000000000000e+00<br class="">
> ];<br class="">
> Mat_0xc4000001_0 = spconvert(zzz);<br class="">
><span class="x_Apple-converted-space"> </span><br class="">
> <Screenshot 2022-07-14 at 10.12.53 PM.png><br class="">
<br class="">
</div>
</span></font></div>
<span id="x_cid:DF1684A1-E96D-441F-97D6-446550B56DF1"><ex1111.c></span></div>
</blockquote>
</div>
<br class="">
</div>
</div>
</body>
</html>