<meta http-equiv="Content-Type" content="text/html; charset=utf-8"><div dir="ltr"><div>Matt and Lisandro,<br></div><div>Let me explain a little more about new API for mat-mat operations, which include MatMaMult (AB), MatPtAP (PtAP), MatMatMatMult (ABC), with a total 6 matproduct types.</div><div><br></div><div>1) MatProduct is logically similar to MatFactor, not a single Mat. Calling</div><div>MatProductCreate(A,B,NULL,&D);</div><div>MatProductSetType(D, MATPRODUCT_AB);</div><div><div>MatDestory(&A); // A is gone </div><div>MatDestory(&B); // B is gone <br></div><div>MatProductSymbolic(D);</div></div> is equivalent to calling MatMatMult(null, null, ..., &D) or MatGetFactor(null, ...,&F). <div>If you do this, you'll get segfault (I'll add additional error message for this use case).</div><div><br></div><div>2) New API is an incremental improvement over the old API, e.g., </div><div>MatMatMultSymbolic(A,B, fill,&C); MatMatMultNumeric(A,B,C)</div><div>are replaced by</div><div>MatProductCreate(A,B,NULL,&D);</div><div>MatProductSetType(D, MATPRODUCT_AB);<br></div><div> MatProductSetFill(D,fill);<br> MatProductSetFromOptions(D);<br></div><div>MatProductSymbolic(D):<br></div><div>MatProductNumeric(D);<br></div><div><br></div><div>There are at least two reasons we decided to introduce new API.</div><div>a) there are multiple implementations (algorithms) for some product types and matrix types, e.g., A*B  and PtAP for mpiaij_mpiaij matrices. Developers are adding more and more special implementations, e.g, for gpu etc. Previously, the options of algorithms are selected in MatMatMultSymbolic_xxx(...,&D) with random option names. However, some options need to be selected before D is setup, and attached to D. For this reason, we introduced new API, and add MatProductSetFromOptions(D) to handle all the options. Note: the options can only be determined at the level of producttype and mattype are known, thus the options are enabled in MatProductSetFromOptions_mattype_producttype().</div><div><br></div><div>b) Reuse of MatProduct D = A*B means same A and B with updated values. However, some users change A or B, some use different  D without knowing original D might contain internal data structure that is associated with A and B. The new API forces reuse same A, B, unless user calls MatProductReplaceMats(A,B,C,D).</div><div><br></div><div>3) For MatProduct, I consider</div><div>MatProductSetFromOptions() is logically equivalent to MatSetFromOptions(), <br></div><div>MatProductSymbolic() is logically equivalent to MatSetUp(),</div><div>and</div><div>MatProductNumeric() assembles the matproduct  D repeatedly when A or B are updated.</div><div><br></div><div>I'm willing to incorporate your thoughts and comments into this new API.</div><div>Hong</div><div><br></div><div><div><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Mon, Mar 23, 2020 at 4:29 PM Matthew Knepley <<a href="mailto:knepley@gmail.com">knepley@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 Mon, Mar 23, 2020 at 5:12 PM Lisandro Dalcin <<a href="mailto:dalcinl@gmail.com" target="_blank">dalcinl@gmail.com</a>> wrote:<br></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"><div dir="ltr"><br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Mon, 23 Mar 2020 at 17:57, <a href="mailto:hzhang@mcs.anl.gov" target="_blank">hzhang@mcs.anl.gov</a> <<a href="mailto:hzhang@mcs.anl.gov" target="_blank">hzhang@mcs.anl.gov</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">Lisandro:<br></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">MatProductSetFromOptions() is not really setting any options. It looks like the correct name for this API is MatProductSetUp(). In any case, it looks like both SetFromOptions() and SetUp() should be provided.</div></blockquote><div> </div><div>Not all product and matrix types enable algorithmic options. For those who do have options, </div><div>MatProductSetFromOptions_mattype_producttype() enables it. See MatProductSetFromOptions_MPIAIJ_AB().<br></div></div></div></blockquote><div><br></div><div>I have to insist, you should separate SetFromOptions() from SetUp(). For many types, SetFromOptions may be empty (you can even use a NULL pointer to handle these cases), but the rest of the code that does setup stuff (that is, preparing the data structures) should go SetUp() routines.</div><div>This design pattern is used everywhere in PETSc. That's the proper way to do it, IMHO. This way is the one that gives maximum flexibility to power users/developers, because some times developers may want to configure objects with some parameters, and do a SetUp() without calling SetFromOptions() to prevent users to mess up with the parameters the developer carefully chose.</div></div></div></blockquote><div><br></div><div>I agree here. We should not be using options in SetUp or setting up in SetFromOptions() since it might not be called. I am tying to fix all this in DM.</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"><div dir="ltr">-- <br><div dir="ltr"><div dir="ltr"><div>Lisandro Dalcin<br>============<br>Research Scientist<br>Extreme Computing Research Center (ECRC)<br>King Abdullah University of Science and Technology (KAUST)<br><a href="http://ecrc.kaust.edu.sa/" target="_blank">http://ecrc.kaust.edu.sa/</a><br></div></div></div></div>
</blockquote></div><br clear="all"><div><br></div>-- <br><div dir="ltr"><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="http://www.cse.buffalo.edu/~knepley/" target="_blank">https://www.cse.buffalo.edu/~knepley/</a><br></div></div></div></div></div></div></div></div>
</blockquote></div></div></div></div>