[petsc-users] Reuse symbolic factorization with petsc - mumps

459543524 459543524 at qq.com
Thu Feb 17 05:02:33 CST 2022


Thanks sir.
I now modify my code into following.
Everything works good.
> -----------------------------------------------------
// stage 1:

Vec x1, b2;
Vec x1, b2;
Mat A, P, F;

PC pc;
// solve first system
MatCreateAIJ(A, ...)
MatSetVaules(A, ...)
MatAssembleBegin(A, ...)
MatAssembleBegin(A, ...)

KSPSetOperators(ksp, A, A);
KSPSetType(ksp, KSPPREONLY);
KSPGetPC(ksp, &pc);
PCSetType(pc, PCLU);
PCFactorSetMatSolverType(pc, MATSOLVERMUMPS);
PCFactorSetUpMatSolverType(pc);
PCFactorGetMatrix(pc, &F);
MatMumpsSetIcntl(F, 7, 5); // configure mumps.
KSPSolve(ksp, b1, x1);

// solve second system
MatZeroEntries(A);
MatSetVaules(A, ...);
MatAssembleBegin(A, ...);
MatAssembleBegin(A, ...);

KSPSetOperators(ksp, A, A);
KSPSolve(ksp, b2, x2);
> > -----------------------------------------------------


------------------ 原始邮件 ------------------
发件人:                                                                                                                        "Jose E. Roman"                                                                                    <jroman at dsic.upv.es>;
发送时间: 2022年2月17日(星期四) 晚上6:49
收件人: "459543524"<459543524 at qq.com>;
抄送: "petsc-users"<petsc-users at mcs.anl.gov>;
主题: Re: [petsc-users] Reuse symbolic factorization with petsc - mumps



Please always respond to the list.

Yes, those lines are not needed every time, just the first one. Anyway, they do not imply a big overhead.

Jose


> El 17 feb 2022, a las 11:45, 459543524 <459543524 at qq.com> escribió:
> 
> Thanks for your reply sir. 
> 
> I now can reuse the sparsity pattern.
> I solve two linear system and found call 'MatLUFactorSym' 1 time and 'MatLUFactorNum' 2 time.
> I modify my code by following.
> 
> > -----------------------------------------------------
> // stage 1:
> 
> Vec x1, b2;
> Vec x1, b2;
> Mat A, P, F;
> PC pc;
> 
> // solve first system
> MatCreateAIJ(A, ...)
> MatSetVaules(A, ...)
> MatAssembleBegin(A, ...)
> MatAssembleBegin(A, ...)
> 
> KSPSetOperators(ksp, A, A);
> KSPSetType(ksp, KSPPREONLY);
> KSPGetPC(ksp, &pc);
> PCSetType(pc, PCLU);
> PCFactorSetMatSolverType(pc, MATSOLVERMUMPS);
> PCFactorSetUpMatSolverType(pc);
> PCFactorGetMatrix(pc, &F);
> MatMumpsSetIcntl(F, 7, 5); // configure mumps.
> KSPSolve(ksp, b1, x1);
> 
> // solve second system
> MatZeroEntries(A);
> MatSetVaules(A, ...);
> MatAssembleBegin(A, ...);
> MatAssembleBegin(A, ...);
> 
> KSPSetOperators(ksp, A, A);
> KSPSetType(ksp, KSPPREONLY);
> KSPGetPC(ksp, &pc);
> PCSetType(pc, PCLU);
> PCFactorSetMatSolverType(pc, MATSOLVERMUMPS);
> PCFactorSetUpMatSolverType(pc);
> PCFactorGetMatrix(pc, &F);
> MatMumpsSetIcntl(F, 7, 5); // configure mumps.
> KSPSolve(ksp, b2, x2);
> > -----------------------------------------------------
> 
> I question is, in the code, we call follow code block twice
> -------------------------------
> KSPSetType(ksp, KSPPREONLY);
> KSPGetPC(ksp, &pc);
> PCSetType(pc, PCLU);
> PCFactorSetMatSolverType(pc, MATSOLVERMUMPS);
> PCFactorSetUpMatSolverType(pc);
> PCFactorGetMatrix(pc, &F);
> MatMumpsSetIcntl(F, 7, 5); // configure mumps.
> -------------------------------
> Does this introduce unnecessary big computation overhead?
> Can the code further simpilfy to enhance a better performance?
> 
> Thanks for your time.
>  
> 
> 
> ------------------ 原始邮件 ------------------
> 发件人: "Jose E. Roman" <jroman at dsic.upv.es>;
> 发送时间: 2022年2月17日(星期四) 下午5:17
> 收件人: "459543524"<459543524 at qq.com>;
> 抄送: "petsc-users"<petsc-users at mcs.anl.gov>;
> 主题: Re: [petsc-users] Reuse symbolic factorization with petsc - mumps
> 
> 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.
> 
> The list of changes in version 3.5 has this note:
> "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()."
> 
> 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.
> 
> Jose
> 
> 
> 
> > El 17 feb 2022, a las 9:42, 459543524 via petsc-users <petsc-users at mcs.anl.gov> escribió:
> > 
> > Sir, I have a problem when using petsc.
> > 
> > I want to solve a series of linear equations.
> > 
> > A1*x1=b1, A2*x2=b2, A3*x3=b3 ...
> > 
> > The A1,A2,A3 have the same sparstiy pattern.
> > 
> > I want to use MUMPS to solve the system.
> > In order to enhance performance, I want to reuse the symbolic factorization.
> > 
> > Here my code for solve a single linear system is
> > -----------------------------------------------------
> > Mat A, P, F;
> > PC pc;
> > Vec rhs_vec, result_vec;
> > KSPSetOperators(ksp, A, A);
> > KSPSetType(ksp, KSPPREONLY);
> > KSPGetPC(ksp, &pc);
> > PCSetType(pc, PCLU);
> > PCFactorSetMatSolverType(pc, MATSOLVERMUMPS);
> > PCFactorSetUpMatSolverType(pc);
> > PCFactorGetMatrix(pc, &F);
> > MatMumpsSetIcntl(F, 7, 5); // configure mumps.
> > KSPSolve(ksp, rhs_vec, result_vec);
> > -----------------------------------------------------
> > 
> > 
> > I have no idea how to reuse symbolic factorization when using MUMPS.
> > 
> > I have see the information from interent. The petsc developper have suggested that using:
> > KSPSetOperators(KSP_A, A, A, DIFFERENT_NONZERO_PATTERN)
> > KSPSetOperators(KSP_A, A, A, SAME_NONZERO_PATTERN)
> > However, this API seems depreacted.
> > see https://lists.mcs.anl.gov/pipermail/petsc-users/2013-March/016646.html
> > 
> > I have see there exist API: MatLUFactorSymbolic,  MatLUFactorNumeric(). but I have no idea how to call it.
> > 
> > Could you please give me an example how to reuse the symbolic factorization when using MUMPS in petsc?
> > 
> > Thanks for your time.
> > 
> > Xu Hui
> > 
> > 
>-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20220217/bdecaa6f/attachment-0001.html>


More information about the petsc-users mailing list