AMGX icon indicating copy to clipboard operation
AMGX copied to clipboard

How to implement the caching of AMG preconditioner?

Open xiaochiyue opened this issue 4 weeks ago • 3 comments

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

xiaochiyue avatar Dec 09 '25 08:12 xiaochiyue

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,
            ...
        },

marsaev avatar Dec 10 '25 00:12 marsaev

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,
            ...
        },

xiaochiyue avatar Dec 10 '25 04:12 xiaochiyue

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.

marsaev avatar Dec 10 '25 09:12 marsaev