<meta http-equiv="Content-Type" content="text/html; charset=GB18030"><div>Thanks sir.</div><div>I now modify my code into following.</div><div>Everything works good.</div><div><div>> -----------------------------------------------------<br>// stage 1:<br><br>Vec x1, b2;<br>Vec x1, b2;<br>Mat A, P, F;</div><div><br>PC pc;<br>// solve first system<br>MatCreateAIJ(A, ...)<br>MatSetVaules(A, ...)<br>MatAssembleBegin(A, ...)<br>MatAssembleBegin(A, ...)</div><div><br>KSPSetOperators(ksp, A, A);<br>KSPSetType(ksp, KSPPREONLY);<br>KSPGetPC(ksp, &pc);<br>PCSetType(pc, PCLU);<br>PCFactorSetMatSolverType(pc, MATSOLVERMUMPS);<br>PCFactorSetUpMatSolverType(pc);<br>PCFactorGetMatrix(pc, &F);<br>MatMumpsSetIcntl(F, 7, 5); // configure mumps.<br>KSPSolve(ksp, b1, x1);<br><br>// solve second system<br>MatZeroEntries(A);</div><div>MatSetVaules(A, ...);<br>MatAssembleBegin(A, ...);<br>MatAssembleBegin(A, ...);</div><div><br>KSPSetOperators(ksp, A, A);<br>KSPSolve(ksp, b2, x2);<br>> > -----------------------------------------------------</div><div><br></div><div style="font-size: 12px;font-family: Arial Narrow;padding:2px 0 2px 0;">------------------ 原始邮件 ------------------</div><div style="font-size: 12px;background:#efefef;padding:8px;"><div><b>发件人:</b>                                                                                                                        "Jose E. Roman"                                                                                    <jroman@dsic.upv.es>;</div><div><b>发送时间:</b> 2022年2月17日(星期四) 晚上6:49</div><div><b>收件人:</b> "459543524"<459543524@qq.com>;<wbr></div><div><b>抄送:</b> "petsc-users"<petsc-users@mcs.anl.gov>;<wbr></div><div><b>主题:</b> Re: [petsc-users] Reuse symbolic factorization with petsc - mumps</div></div><div><br></div>Please always respond to the list.<br><br>Yes, those lines are not needed every time, just the first one. Anyway, they do not imply a big overhead.<br><br>Jose<br><br><br>> El 17 feb 2022, a las 11:45, 459543524 <459543524@qq.com> escribió:<br>> <br>> Thanks for your reply sir. <br>> <br>> I now can reuse the sparsity pattern.<br>> I solve two linear system and found call 'MatLUFactorSym' 1 time and 'MatLUFactorNum' 2 time.<br>> I modify my code by following.<br>> <br>> > -----------------------------------------------------<br>> // stage 1:<br>> <br>> Vec x1, b2;<br>> Vec x1, b2;<br>> Mat A, P, F;<br>> PC pc;<br>> <br>> // solve first system<br>> MatCreateAIJ(A, ...)<br>> MatSetVaules(A, ...)<br>> MatAssembleBegin(A, ...)<br>> MatAssembleBegin(A, ...)<br>> <br>> KSPSetOperators(ksp, A, A);<br>> KSPSetType(ksp, KSPPREONLY);<br>> KSPGetPC(ksp, &pc);<br>> PCSetType(pc, PCLU);<br>> PCFactorSetMatSolverType(pc, MATSOLVERMUMPS);<br>> PCFactorSetUpMatSolverType(pc);<br>> PCFactorGetMatrix(pc, &F);<br>> MatMumpsSetIcntl(F, 7, 5); // configure mumps.<br>> KSPSolve(ksp, b1, x1);<br>> <br>> // solve second system<br>> MatZeroEntries(A);<br>> MatSetVaules(A, ...);<br>> MatAssembleBegin(A, ...);<br>> MatAssembleBegin(A, ...);<br>> <br>> KSPSetOperators(ksp, A, A);<br>> KSPSetType(ksp, KSPPREONLY);<br>> KSPGetPC(ksp, &pc);<br>> PCSetType(pc, PCLU);<br>> PCFactorSetMatSolverType(pc, MATSOLVERMUMPS);<br>> PCFactorSetUpMatSolverType(pc);<br>> PCFactorGetMatrix(pc, &F);<br>> MatMumpsSetIcntl(F, 7, 5); // configure mumps.<br>> KSPSolve(ksp, b2, x2);<br>> > -----------------------------------------------------<br>> <br>> I question is, in the code, we call follow code block twice<br>> -------------------------------<br>> KSPSetType(ksp, KSPPREONLY);<br>> KSPGetPC(ksp, &pc);<br>> PCSetType(pc, PCLU);<br>> PCFactorSetMatSolverType(pc, MATSOLVERMUMPS);<br>> PCFactorSetUpMatSolverType(pc);<br>> PCFactorGetMatrix(pc, &F);<br>> MatMumpsSetIcntl(F, 7, 5); // configure mumps.<br>> -------------------------------<br>> Does this introduce unnecessary big computation overhead?<br>> Can the code further simpilfy to enhance a better performance?<br>> <br>> Thanks for your time.<br>>  <br>> <br>> <br>> ------------------ 原始邮件 ------------------<br>> 发件人: "Jose E. Roman" <jroman@dsic.upv.es>;<br>> 发送时间: 2022年2月17日(星期四) 下午5:17<br>> 收件人: "459543524"<459543524@qq.com>;<br>> 抄送: "petsc-users"<petsc-users@mcs.anl.gov>;<br>> 主题: Re: [petsc-users] Reuse symbolic factorization with petsc - mumps<br>> <br>> Since version 3.5, KSPSetOperators() will check if the passed matrix has the same sparse pattern as the previously set one, so you don't have to do anything.<br>> <br>> The list of changes in version 3.5 has this note:<br>> "KSPSetOperators() no longer has the MatStructure argument. The Mat objects now track that information themselves. Use KSP/PCSetReusePreconditioner() to prevent the recomputation of the preconditioner if the operator changed in the way that SAME_PRECONDITIONER did with KSPSetOperators()."<br>> <br>> You don't call MatLUFactorSymbolic() yourself, it is called internally. You can check with -log_view if the number of calls to MatLUFactorSymbolic() is as expected.<br>> <br>> Jose<br>> <br>> <br>> <br>> > El 17 feb 2022, a las 9:42, 459543524 via petsc-users <petsc-users@mcs.anl.gov> escribió:<br>> > <br>> > Sir, I have a problem when using petsc.<br>> > <br>> > I want to solve a series of linear equations.<br>> > <br>> > A1*x1=b1, A2*x2=b2, A3*x3=b3 ...<br>> > <br>> > The A1,A2,A3 have the same sparstiy pattern.<br>> > <br>> > I want to use MUMPS to solve the system.<br>> > In order to enhance performance, I want to reuse the symbolic factorization.<br>> > <br>> > Here my code for solve a single linear system is<br>> > -----------------------------------------------------<br>> > Mat A, P, F;<br>> > PC pc;<br>> > Vec rhs_vec, result_vec;<br>> > KSPSetOperators(ksp, A, A);<br>> > KSPSetType(ksp, KSPPREONLY);<br>> > KSPGetPC(ksp, &pc);<br>> > PCSetType(pc, PCLU);<br>> > PCFactorSetMatSolverType(pc, MATSOLVERMUMPS);<br>> > PCFactorSetUpMatSolverType(pc);<br>> > PCFactorGetMatrix(pc, &F);<br>> > MatMumpsSetIcntl(F, 7, 5); // configure mumps.<br>> > KSPSolve(ksp, rhs_vec, result_vec);<br>> > -----------------------------------------------------<br>> > <br>> > <br>> > I have no idea how to reuse symbolic factorization when using MUMPS.<br>> > <br>> > I have see the information from interent. The petsc developper have suggested that using:<br>> > KSPSetOperators(KSP_A, A, A, DIFFERENT_NONZERO_PATTERN)<br>> > KSPSetOperators(KSP_A, A, A, SAME_NONZERO_PATTERN)<br>> > However, this API seems depreacted.<br>> > see https://lists.mcs.anl.gov/pipermail/petsc-users/2013-March/016646.html<br>> > <br>> > I have see there exist API: MatLUFactorSymbolic,  MatLUFactorNumeric(). but I have no idea how to call it.<br>> > <br>> > Could you please give me an example how to reuse the symbolic factorization when using MUMPS in petsc?<br>> > <br>> > Thanks for your time.<br>> > <br>> > Xu Hui<br>> > <br>> > <br>> >  <br></div>