-
Notifications
You must be signed in to change notification settings - Fork 196
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
Implement KrylovPoissonSolver #3803
Comments
We'll also write a simple script that solves a problem: using Oceananigans
using Krylov
# make a grid
# choose a preconditioner
solver = Oceananigans.Solvers.KrylovPoissonSolver(grid; preconditioner=cool_preconditioner)
x = CenterField(grid)
b = CenterField(grid)
set!(b, rand(size(grid)...))
solve!(x, solver, b) |
cc @xkykai |
This is super exciting! Out of curiosity is there any/which Krylov solver is compatible on multiple GPUs? Seems to be an important bottleneck for our current |
All Krylov solvers in |
The only parts of the solver algorithm that require communication between nodes are The "matrix product" --- a Poisson operator for us --- has unavoidable communication as well. But, we should be able to keep this limited in scope and we only need 1 halo. The trickier part where I think there is room for significant optimization is in the development of an effective multi-GPU preconditioner that is also efficient in parallel. |
Yes, you are right. |
Also to be clear about what this can do --- with Krylov, we can still use the FFT preconditioner. When we do that the parallelism issues are identical to the issues with our current CG solver, it's just that tweaking the solver method might allow us to do fewer iterations. So there are two things going on in this discussion which are independent. First is whether conjugate gradient is optimal or whether we should use a different method. The second issue is the preconditioner, which is the more uncertain part but where we might have more gains. |
Here's a https://jso.dev/Krylov.jl/stable/examples/cg/ @amontoison is there an in-place version that accepts a preallocated solution |
@glwagner I wrote a section about in-place methods in the documentation: The in-place version of CG is detailed here. The cost in terms of storage of each solver is also documented: |
We maybe need to adapt the constructor of the It works fine for CPU / GPU arrays as well as various partitioned arrays but |
Hmm yes. We can implement a custom constructor. Or we can capture the additional info needed for the "constructor" We can also add constructors to Oceananigans.jl/src/Solvers/conjugate_gradient_solver.jl Lines 87 to 89 in 45838a5
I think using a closure is simpler though. |
With @amontoison
We'd like to implement a Poisson solver that uses
Krylov
under the hood instead of our custom (preconditioned) conjugate gradient solver. This will open the door to more solvers (that may be more appropriate for our pressure Poisson equation than conjugate gradient) like conjugate residual, etc.To make this work we need to overload some of Krylov's operators for Oceananigans
Field
:kaxpby!(n, s, x, dx, y, dy)
which performsy = y + s * x
wheren
is the total length (egNx * Ny * Nz
),s
is the output,dx
anddy
are strides (irrelevant for us)kaxpby!(n, s, x, dx, t, y, dy)
which performsy = t * y + s * x
wheren
is the total length (egNx * Ny * Nz
),s
is the output,dx
anddy
are strides (irrelevant for us)kdot
knrm2
kcopy!
orcopyto!
The text was updated successfully, but these errors were encountered: