How to implement the caching of AMG preconditioner?
Dear,
In the SIMPLE iterations of CFD simulation, the coefficient matrix A of the pressure Poisson equation changes slowly. Utilizing the AMG preconditioner configuration from previous iterations (caching the AMG structure) can significantly improve performance, as the setup phase of AMG is often one of the most computationally expensive parts.
Is there easy way to implement this caching strategy?
Regards, xg
Hello, @xiaochiyue . Using "structure_reuse_levels=N", where N is number of levels that you want to reuse (-1 to reuse all levels structures), should do what you want. It will keep R and P matriсes, but will recalculate coarse level matrix based on the updated values. I.e.
"preconditioner": {
"solver": "AMG",
...
"structure_reuse_levels": 3,
...
},
Hello, marsaev
Thank you very much.
Is there a way to set "structure_reuse_levels" dynamically in iterations? Or a more convenient way to achieve the same effect?
I.e.
//...
//set structure_reuse_levels=0
//init solver
//...
for(it=0; it<N; it++)
{
if(it%10==9)
{
//set structure_reuse_levels=0
}
else
{
//set structure_reuse_levels=-1
}
//Assemble matrix A
//solver.reconfig(config);
//solver.setup(A);
//solver.solve(A,b,x);
}
Hello, @xiaochiyue . Using "structure_reuse_levels=N", where N is number of levels that you want to reuse (-1 to reuse all levels structures), should do what you want. It will keep R and P matriсes, but will recalculate coarse level matrix based on the updated values. I.e.
"preconditioner": { "solver": "AMG", ... "structure_reuse_levels": 3, ... },
Not really. Reconfig in a way you describe might bring a lot of troubles - i.e. some parameters are only a variable in an algorithm, while other control algorithm workflow and require "deep" resetup. Structure re-use levels is of the first type, so it's possible to adjust it (to my recollection) safely. If that's the only thing you need and you are willing to hack it, i would add some callback to control related variable here https://github.com/NVIDIA/AMGX/blob/main/include/amg.h#L167 in the setup.