<div dir="ltr">FM matrices are slow and meant for debugging mostly (I thought, although the docs just give this warning if coloring is not available).<div><br></div><div>I would check the timings from -log_view and verify that the time is spent in MatFDColoringApply. Running with -info should print the number of colors (C). The cost of an FD matrix is about C x cost of an exact Jacobian. Roughly. You could check that.</div><div><br></div><div>Mark</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Sun, Dec 1, 2019 at 3:58 AM Li Luo <<a href="mailto:li.luo@kaust.edu.sa">li.luo@kaust.edu.sa</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"><div dir="ltr"><div><font size="2"><font face="trebuchet ms, sans-serif">Dear Developers,</font></font></div><div><font size="2"><font face="trebuchet ms, sans-serif"><br></font></font></div><div><font size="2"><font face="trebuchet ms, sans-serif">I tried to use the multi-color finite-difference (MC-FD) method for constructing the Jacobians. However, I find it is very slow compared to the exact Jacobian. </font></font></div><div><font size="2"><font face="trebuchet ms, sans-serif">My implementation of MC-FD Jacobian is posted below, would you please check whether I am correct? Anything missed? Thank you!</font></font></div><div><font size="2"><font face="trebuchet ms, sans-serif"><br></font></font></div><div><font size="2"><font face="trebuchet ms, sans-serif">////////// Setup phase:</font></font></div><div> MatStructure flag;<br> ISColoring iscoloring;<br> ierr = MatGetColoring(Jac,MATCOLORINGSL,&iscoloring);<br> ierr = MatFDColoringCreate(Jac,iscoloring,&this->matfdcoloring);<br> ierr = MatFDColoringSetFunction(this->matfdcoloring,(PetscErrorCode (*)(void))__libmesh_petsc_snes_residual,(void *)this);<br> ierr = MatFDColoringSetFromOptions(this->matfdcoloring);<br> ierr = ISColoringDestroy(&iscoloring);<font size="2"><font face="trebuchet ms, sans-serif"><br></font></font></div><div><br></div><div><font size="2"><font face="trebuchet ms, sans-serif">//////////// Apply:</font></font></div><div> ierr = MatZeroEntries(*jac);CHKERRQ(ierr);<br> ierr = MatFDColoringApply(*jac,solver->matfdcoloring,x,msflag,snes);</div><div><br></div><div>Best regards,</div><div>Li Luo</div></div></div></div>
<br>
<div><hr></div><font face="Arial" size="1">This message and its contents, including attachments are intended solely for the original recipient. If you are not the intended recipient or have received this message in error, please notify me immediately and delete this message from your computer system. Any unauthorized use or distribution is prohibited. Please consider the environment before printing this email.</font></blockquote></div>