amgcl icon indicating copy to clipboard operation
amgcl copied to clipboard

Can I change matrix A without rebuilding AMG when using CUDA as backend?

Open pcbcos opened this issue 5 months ago • 2 comments

Hello, I am using AMG with its CUDA backend to solve equations from FEM. In each time step, the matrix A will be modified a little, and I want to keep the AMG in order to make the simulation faster. I tried this:

typedef amgcl::backend::cuda<float> Backend;
typedef amgcl::make_solver<
           amgcl::amg<
                    Backend,
                    amgcl::coarsening::smoothed_aggregation,
                    amgcl::relaxation::ilu0
            >,
            amgcl::solver::bicgstab<Backend>>Solver;

auto A0=std::make_tuple(...); //from Eigen to CRS tuple
Solver solve(A0, prm, bprm);

for(double t = 0; t < tmax; t+= dt) {
    A = assemble_fresh_matrix();

    // This will solve Ax=f with the current preconditioner:
    std::tie(iters, error) = solve(A, f, x);

    if (iters > rebuild_limit) {
        // Too many iterations: time to update the preconditioner
        solve = Solver(A, prm,bprm);
    }
}

However, the program was broken, I guess the errors occured at std::tie(iters, error) = solve(A, f, x); because when I use std::tie(iters, error) = solve(f, x); , the program runs successfully without changing the matrix A.

I wonder can I change the A matrix without rebuild AMG when using CUDA as backend, just like std::tie(iters, error) = solve(A, f, x); Thank you!

pcbcos avatar Sep 10 '24 08:09 pcbcos