Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
pcbcos opened this issue Sep 10, 2024 · 2 comments
Open

Comments

@pcbcos
Copy link

pcbcos commented Sep 10, 2024

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 pcbcos changed the title Can I change matrix A without rebuild AMG when using CUDA as backend? Can I change matrix A without rebuilding AMG when using CUDA as backend? Sep 10, 2024
@ddemidov
Copy link
Owner

ddemidov commented Sep 11, 2024

If assemble_fresh_matrix returns a matrix assembled on the CPU (same format as A0), then you need to transfer A to the gpu memory.

Something like this should work:

auto A_gpu = SBackend::copy_matrix(
std::make_shared<amgcl::backend::crs<dmat_type>>(Ab), bprm);

@pcbcos
Copy link
Author

pcbcos commented Sep 12, 2024

Thank you, I will try this. In fact, I have tried directly cudaMemcpy to the val of the system_martix on the GPU, it also works.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants