• PETSC调试


    1. petsc-3.18.1/src/ksp/ksp/tutorials$ ./ex1
    2. KSP Object: 1 MPI process
    3. type: gmres
    4. restart=30, using Classical (unmodified) Gram-Schmidt Orthogonalization with no iterative refinement
    5. happy breakdown tolerance 1e-30
    6. maximum iterations=10000, initial guess is zero
    7. tolerances: relative=1e-05, absolute=1e-50, divergence=10000.
    8. left preconditioning
    9. using PRECONDITIONED norm type for convergence test
    10. PC Object: 1 MPI process
    11. type: jacobi
    12. type DIAGONAL
    13. linear system matrix = precond matrix:
    14. Mat Object: 1 MPI process
    15. type: seqaij
    16. rows=10, cols=10
    17. total: nonzeros=28, allocated nonzeros=50
    18. total number of mallocs used during MatSetValues calls=0
    19. not using I-node routines
    20. Norm of error 2.41202e-15, Iterations 5

    使用的是GMRES。

    1) gdb ex1

    130       PetscCall(KSPSolve(ksp, b, x));
     

    2)

    at /thfs1/home/***/petsc-3.18.1/src/ksp/ksp/interface/itfunc.c:1066
    不太1066      PetscFunctionBegin;

    1. (gdb) p KSP_CLASSID
    2. $1 = 1211223
    3. (gdb) p VEC_CLASSID
    4. $2 = 1211214

    不太明白这个ID是啥意思。


     实际调用的是KSPSolve_Private()

    1. (gdb) s
    2. KSPSolve_Private (ksp=0x5c62a0, b=0x4d3060, x=0x4cdc80)
    3. at /thfs1/home/monkeycode/tianya/software/petsc-3.18.1/src/ksp/ksp/interface/itfunc.c:791
    4. 791 PetscBool flg = PETSC_FALSE, inXisinB = PETSC_FALSE, guess_zero;

    3)CG可以看ex72.c

     -mat_type mpisbaij -ksp_type cg -pc_type eisenstat -ksp_monitor_short -ksp_converged_reason
          test:
    -mat_type mpisbaij -ksp_type cg -pc_type eisenstat -ksp_monitor_short -ksp_converged_reason

     -ksp_cg_single_reduction
    -ksp_ksp_type cg -ksp_pc_type bjacobi -ksp_pc_bjacobi_blocks 1

    4)

    1. 125 if (!ksp->guess_zero) {
    2. 126 PetscCall(KSP_MatMult(ksp, Amat, X, R)); /* r <- b - Ax * /
    3. 127 PetscCall(VecAYPX(R, -1.0, B));
    4. 128 } else {
    5. 129 PetscCall(VecCopy(B, R)); /* r <- b (x is 0) */
    6. 130 }
    7. switch (ksp->normtype) {
    8. 135 case KSP_NORM_PRECONDITIONED:
    9. 136 PetscCall(KSP_PCApply(ksp, R, Z)); /* z <- Br */
    10. 137 PetscCall(VecNorm(Z, NORM_2, &dp)); /* dp <- z'*z = e'*A'*B'*B*A*e */
    11. 138 KSPCheckNorm(ksp, dp);
    12. 139 break;
    13. 140 case KSP_NORM_UNPRECONDITIONED:
    14. 141 PetscCall(VecNorm(R, NORM_2, &dp)); /* dp <- r'*r = e'*A'*A*e */
    15. 142 KSPCheckNorm(ksp, dp);
    16. 143 break;
    17. 144 case KSP_NORM_NATURAL:
    18. 145 PetscCall(KSP_PCApply(ksp, R, Z)); /* z <- Br */
    19. 146 PetscCall(VecXDot(Z, R, &beta)); /* beta <- z'*r */
    20. 147 KSPCheckDot(ksp, beta);
    21. 148 dp = PetscSqrtReal(PetscAbsScalar(beta)); /* dp <- r'*z = r'*B*r = e'*A'*B*A*e */
    22. 78 /*
    23. 79 A macro used in the following KSPSolve_CG and KSPSolve_CG_SingleReduction routine s
    24. 80 */
    25. 81 #define VecXDot(x, y, a) (((cg->type) == (KSP_CG_HERMITIAN)) ? VecDot(x, y, a) : VecTD ot(x, y, a))
    26. /petsc-3.18.1/src/vec$ grep VecAYPX -rn *
    27. f90-mod/ftn-auto-interfaces/petscvec.h90:188: subroutine VecAYPX(a,b,c,z)
    28. f90-mod/ftn-auto-interfaces/petscvec.h90:194: end subroutine VecAYPX
    29. vec/interface/rvector.c:571:$ VecAYPX(y,beta,x) y = x + beta y
    30. vec/interface/rvector.c:577:.seealso: `VecAYPX()`, `VecMAXPY()`, `VecWAXPY()`, `VecAXPBYPCZ()`, `VecAXPBY()`
    31. vec/interface/rvector.c:603: VecAYPX - Computes y = x + beta y.
    32. vec/interface/rvector.c:622:PetscErrorCode VecAYPX(Vec y, PetscScalar beta, Vec x)
    33. vec/interface/rvector.c:665:.seealso: `VecAYPX()`, `VecMAXPY()`, `VecWAXPY()`, `VecAXPY()`, `VecAXPBYPCZ()`

    5)继续gdb ex1

    1. (gdb)
    2. 899 PetscUseTypeMethod(ksp, solve);
    3. (gdb) s
    4. KSPSolve_GMRES (ksp=0x5c69b0)
    5. at /thfs1/home/monkeycode/tianya/software/petsc-3.18.1/src/ksp/ksp/impls/gmres/gmres.c:212
    6. 212 KSP_GMRES *gmres = (KSP_GMRES *)ksp->data;

    函数作为参数

    有些代码和判断比较长,但是执行次数少,就并不

    也可以这样运行:

     ./ex1 -m 400 -n 400 -pc_type eisenstat -ksp_monitor_short -ksp_gmres_cgs_refinement_type refine_always
     

    应该核心是:

    1. 899 PetscUseTypeMethod(ksp, solve);
    2. (gdb)
    3. 0 KSP Residual norm 1.52753
    4. 1 KSP Residual norm 0.437136
    5. 2 KSP Residual norm 0.22205
    6. 3 KSP Residual norm 0.137425
    7. 4 KSP Residual norm 0.0952384
    8. 5 KSP Residual norm 0.0709072
    9. 6 KSP Residual norm 0.0554212
    10. 7 KSP Residual norm 0.0448558
    11. 8 KSP Residual norm 0.0372695
    12. 9 KSP Residual norm 0.0316055
    13. 10 KSP Residual norm 0.0272444

    6)

    1. (gdb)
    2. 228 PetscCall(KSPGMRESCycle(&its, ksp));
    3. (gdb)
    4. 0 KSP Residual norm 1.52753
    5. 1 KSP Residual norm 0.437136
    6. 2 KSP Residual norm 0.22205
    7. 3 KSP Residual norm 0.137425
    8. 4 KSP Residual norm 0.0952384
    9. 5 KSP Residual norm 0.0709072
    10. 6 KSP Residual norm 0.0554212
    11. 7 KSP Residual norm 0.0448558
    12. 8 KSP Residual norm 0.0372695

    1. KSPGMRESCycle (itcount=0xffffffff0560, ksp=0x5d0bd0)
    2. at /thfs1/home/monkeycode/tianya/software/petsc-3.18.1/src/ksp/ksp/impls/gmres/gmres.c:103

    这个地方是核心求解?

        /* update hessenberg matrix and do Gram-Schmidt */

        PetscCall((*gmres->orthog)(ksp, it));


    176         PetscCall((*ksp->converged)(ksp, ksp->its, res, &ksp->reason, ksp->cnvP));
     

  • 相关阅读:
    JK405R-SOP16录音芯片ic方案的测试板使用说明以及咪头如何选择
    办鹿uniapp小程序(一)
    图的基本概念
    C# Winform编程(3)对话框
    赶紧收藏!中秋节营销必备文案和海报,拿了就能用!
    保研笔记八——YOLOV5项目复习
    软件测试-测试用例
    家里蹲了七个月的大学生活是怎么度过的?
    Redis过期策略及内存淘汰机制
    PAT 1004 Counting Leaves (C++)
  • 原文地址:https://blog.csdn.net/anlongstar/article/details/128022878