<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class="">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" 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" class="">hzhang@mcs.anl.gov</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><meta charset="UTF-8" class=""><div 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; -webkit-text-stroke-width: 0px; text-decoration: none; font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt;" class=""><span style="color: rgb(32, 31, 30); font-family: "Segoe UI", "Segoe UI Web (West European)", "Segoe UI", -apple-system, system-ui, Roboto, "Helvetica Neue", sans-serif; font-size: 14.6667px; background-color: rgb(255, 255, 255); display: inline !important;" class="">Pierre,</span><br class=""></div><div 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; -webkit-text-stroke-width: 0px; text-decoration: none; font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt;" class=""><span style="color: rgb(32, 31, 30); font-family: "Segoe UI", "Segoe UI Web (West European)", "Segoe UI", -apple-system, system-ui, Roboto, "Helvetica Neue", sans-serif; font-size: 14.6667px; background-color: rgb(255, 255, 255); display: inline !important;" class="">Our MatProductReplaceMats() is not well tested, which might be buggy. I simplified your code without calling <span style="background-color: rgb(255, 255, 255); display: inline !important;" class="">MatProductReplaceMats() and got correct results in the cases</span></span></div><div 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; -webkit-text-stroke-width: 0px; text-decoration: none; font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt;" class=""><span style="color: rgb(32, 31, 30); font-family: "Segoe UI", "Segoe UI Web (West European)", "Segoe UI", -apple-system, system-ui, Roboto, "Helvetica Neue", sans-serif; font-size: 14.6667px; background-color: rgb(255, 255, 255); display: inline !important;" class=""><span style="background-color: rgb(255, 255, 255); display: inline !important;" class="">./ex1111 -product_view ::ascii_matlab -convert false/true <span style="background-color: rgb(255, 255, 255); display: inline !important;" class="">-correct false</span><br class=""></span></span></div><div 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; -webkit-text-stroke-width: 0px; text-decoration: none; font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt;" class=""><span style="color: rgb(32, 31, 30); font-family: "Segoe UI", "Segoe UI Web (West European)", "Segoe UI", -apple-system, system-ui, Roboto, "Helvetica Neue", sans-serif; font-size: 14.6667px; background-color: rgb(255, 255, 255); display: inline !important;" class=""><span style="background-color: rgb(255, 255, 255); display: inline !important;" class="">and</span></span></div><div 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; -webkit-text-stroke-width: 0px; text-decoration: none; font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt;" class=""><span style="color: rgb(32, 31, 30); font-family: "Segoe UI", "Segoe UI Web (West European)", "Segoe UI", -apple-system, system-ui, Roboto, "Helvetica Neue", sans-serif; font-size: 14.6667px; background-color: rgb(255, 255, 255); display: inline !important;" class=""><span style="background-color: rgb(255, 255, 255); display: inline !important;" class="">./ex1111 -product_view ::ascii_matlab -convert false/true -correct true<br class=""></span></span></div><div 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; -webkit-text-stroke-width: 0px; text-decoration: none; font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt;" class=""><span style="color: rgb(32, 31, 30); font-family: "Segoe UI", "Segoe UI Web (West European)", "Segoe UI", -apple-system, system-ui, Roboto, "Helvetica Neue", sans-serif; font-size: 14.6667px; background-color: rgb(255, 255, 255); display: inline !important;" class=""><span style="background-color: rgb(255, 255, 255); display: inline !important;" class=""><br class=""></span></span></div><div style="caret-color: rgb(0, 0, 0); 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; -webkit-text-stroke-width: 0px; text-decoration: none;" class=""><font color="#201f1e" class=""><span style="font-size: 14.6667px;" class="">My code is attached. I'll investigate <span style="background-color: rgb(255, 255, 255); display: inline !important;" class="">MatProductReplaceMats().</span></span></font></div><div style="caret-color: rgb(0, 0, 0); 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; -webkit-text-stroke-width: 0px; text-decoration: none;" class=""><font color="#201f1e" class=""><span style="font-size: 14.6667px;" class="">Hong</span></font></div><div 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; -webkit-text-stroke-width: 0px; text-decoration: none; font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt;" class=""><span style="color: rgb(32, 31, 30); font-family: "Segoe UI", "Segoe UI Web (West European)", "Segoe UI", -apple-system, system-ui, Roboto, "Helvetica Neue", sans-serif; font-size: 14.6667px; background-color: rgb(255, 255, 255); display: inline !important;" class=""><span style="background-color: rgb(255, 255, 255); display: inline !important;" class=""><br class=""></span></span></div><div 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; -webkit-text-stroke-width: 0px; text-decoration: none; font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt;" class=""><span style="color: rgb(32, 31, 30); font-family: "Segoe UI", "Segoe UI Web (West European)", "Segoe UI", -apple-system, system-ui, Roboto, "Helvetica Neue", sans-serif; font-size: 14.6667px; background-color: rgb(255, 255, 255); display: inline !important;" class=""><span style="background-color: rgb(255, 255, 255); display: inline !important;" class=""><br class=""></span></span></div><div 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; -webkit-text-stroke-width: 0px; text-decoration: none; font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt;" class=""><span style="color: rgb(32, 31, 30); font-family: "Segoe UI", "Segoe UI Web (West European)", "Segoe UI", -apple-system, system-ui, Roboto, "Helvetica Neue", sans-serif; font-size: 14.6667px; background-color: rgb(255, 255, 255); display: inline !important;" class=""><span style="background-color: rgb(255, 255, 255); display: inline !important;" class=""><br class=""></span></span></div><div 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; -webkit-text-stroke-width: 0px; text-decoration: none; font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt;" class=""><span style="color: rgb(32, 31, 30); font-family: "Segoe UI", "Segoe UI Web (West European)", "Segoe UI", -apple-system, system-ui, Roboto, "Helvetica Neue", sans-serif; font-size: 14.6667px; background-color: rgb(255, 255, 255); display: inline !important;" class=""><span style="background-color: rgb(255, 255, 255); display: inline !important;" class=""><br class=""></span></span></div><div id="appendonsend" style="caret-color: rgb(0, 0, 0); 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; -webkit-text-stroke-width: 0px; text-decoration: none;" class=""></div><hr tabindex="-1" style="caret-color: rgb(0, 0, 0); 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; -webkit-text-stroke-width: 0px; text-decoration: none; display: inline-block; width: 1154.4375px;" class=""><span style="caret-color: rgb(0, 0, 0); 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; -webkit-text-stroke-width: 0px; text-decoration: none; float: none; display: inline !important;" class=""></span><div id="divRplyFwdMsg" dir="ltr" style="caret-color: rgb(0, 0, 0); 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; -webkit-text-stroke-width: 0px; text-decoration: none;" class=""><font face="Calibri, sans-serif" style="font-size: 11pt;" class=""><b class="">From:</b><span class="Apple-converted-space"> </span>petsc-dev <<a href="mailto:petsc-dev-bounces@mcs.anl.gov" class="">petsc-dev-bounces@mcs.anl.gov</a>> on behalf of Barry Smith <<a href="mailto:bsmith@petsc.dev" class="">bsmith@petsc.dev</a>><br class=""><b class="">Sent:</b><span class="Apple-converted-space"> </span>Thursday, July 14, 2022 4:38 PM<br class=""><b class="">To:</b><span class="Apple-converted-space"> </span>Pierre Jolivet <<a href="mailto:pierre@joliv.et" class="">pierre@joliv.et</a>><br class=""><b class="">Cc:</b><span class="Apple-converted-space"> </span>For users of the development version of PETSc <<a href="mailto:petsc-dev@mcs.anl.gov" class="">petsc-dev@mcs.anl.gov</a>><br class=""><b class="">Subject:</b><span class="Apple-converted-space"> </span>Re: [petsc-dev] MatProduct_AtB --with-scalar-type=complex</font><div class=""> </div></div><div class="BodyFragment" style="caret-color: rgb(0, 0, 0); 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; -webkit-text-stroke-width: 0px; text-decoration: none;"><font size="2" class=""><span style="font-size: 11pt;" class=""><div class="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="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" class="">pierre@joliv.et</a>> wrote:<br class="">><span class="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="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="Apple-converted-space"> </span><br class="">> Thanks,<br class="">> Pierre<br class="">><span class="Apple-converted-space"> </span><br class="">> <ex1111.c><br class="">><span class="Apple-converted-space"> </span><br class="">> $ ./ex1111 -product_view ::ascii_matlab -A_view ::ascii_matlab -convert false <span class="Apple-converted-space"> </span><br class="">> %Mat Object: 1 MPI process<br class="">> % type: seqdense<br class="">> % Size = 2 2<span class="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="Apple-converted-space"> </span><br class="">> 1.0022337819588500e-02 + 1.4463931936456476e-01i 1.0386628927366459e-01 + 2.5078039364333193e-01i<span class="Apple-converted-space"> </span><br class="">> ];<br class="">> %Mat Object: 1 MPI process<br class="">> % type: seqdense<br class="">> % Size = 2 2<span class="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="Apple-converted-space"> </span><br class="">> 3.2823965013353340e-01 + -1.5498666614872689e-02i 2.3724054059134142e-01 + 0.0000000000000000e+00i<span class="Apple-converted-space"> </span><br class="">> ];<br class="">><span class="Apple-converted-space"> </span><br class="">> $ ./ex1111 -product_view ::ascii_matlab -convert true <span class="Apple-converted-space"> </span><br class="">> %Mat Object: 1 MPI process<br class="">> % type: seqaij<br class="">> % Size = 2 2<span class="Apple-converted-space"> </span><br class="">> % Nonzeros = 4<span class="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="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="Apple-converted-space"> </span><br class="">> % Nonzeros = 4<span class="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="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="cid:DF1684A1-E96D-441F-97D6-446550B56DF1"><ex1111.c></span></div></blockquote></div><br class=""></div></body></html>