# KSPMonitorSet and KSPMonitorCancel

**URL:** https://community.freefem.org/t/kspmonitorset-and-kspmonitorcancel/1927
**Category:** General Discussion
**Created:** [August 2, 2022, 2:58pm UTC](https://community.freefem.org/t/kspmonitorset-and-kspmonitorcancel/1927 "2022-08-02T14:58:18Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![aszaboa](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/aszaboa/32/2918_2.png) [@aszaboa](https://community.freefem.org/u/aszaboa)
#### Post date: [August 2, 2022, 2:58pm UTC](https://community.freefem.org/t/kspmonitorset-and-kspmonitorcancel/1927/1 "2022-08-02T14:58:19Z")

</div>

Dear FreeFem users,

I would like to try out `PCSHELL` and `MatShell` (using `func` in FreeFem) to accelerate the solution of my problem. Everything seems to work as I wanted except for monitoring the solution. I want to monitor the outer `KSPSolve`, but not the ones inside the preconditioner `func`. The key part of the solution procedure is changing the parameters of the matrices inside the preconditioner function, which oddly turns on monitoring for the `KSPSolve` calls inside the preconditioner. The following MWE demonstrated the behaviour: is lines 46-51 are commented out, only the outer KSP call is monitored, while leaving the in the code each `KSPSolve` uses the monitor. Any ideas what causes this behaviour/how can it be circumwent?

[diffusion-2d-PETSc-FieldSplit-PCSHELL.edp](https://community.freefem.org/uploads/short-url/tr205v6NgxSvZsEIEnnYBzCXwk8.edp) (2.1 KB)

---

<div class="post-metadata">

### Author: ![prj](https://avatars.discourse-cdn.com/v4/letter/p/ecae2f/32.png) [@prj](https://community.freefem.org/u/prj)
#### Post date: [August 3, 2022, 4:37am UTC](https://community.freefem.org/t/kspmonitorset-and-kspmonitorcancel/1927/2 "2022-08-03T04:37:00Z")

</div>

You are not using any sort of prefix, making things hard to figure out.  
If you replace your `set(A, sparams = "...");` by something along these lines:

```auto
[...]
set(A, sparams = "-inner_ksp_type preonly -inner_pc_type lu -inner_ksp_reuse_preconditioner false -inner_ksp_monitor_cancel ", prefix = "inner_");
[...]
        set(A, sparams = "-inner_ksp_type preonly -inner_pc_type lu -inner_ksp_reuse_preconditioner true ", prefix="inner_");
[...]

```

Does it fix your issue?

---

<div class="post-metadata">

### Author: ![aszaboa](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/aszaboa/32/2918_2.png) [@aszaboa](https://community.freefem.org/u/aszaboa)
#### Post date: [August 3, 2022, 7:42am UTC](https://community.freefem.org/t/kspmonitorset-and-kspmonitorcancel/1927/3 "2022-08-03T07:42:14Z")

</div>

Thanks for the quick reply. Using prefixes results in the desired behavior!
