Oceananigans.jl icon indicating copy to clipboard operation
Oceananigans.jl copied to clipboard

[WIP] Preconditioning CG solver with multigrid

Open elise-palethorpe opened this issue 3 years ago • 1 comments

Using multigrid as a preconditioner to the congujacte gradient solver

cc @navidcy

closes #2655

elise-palethorpe avatar Jul 13 '22 07:07 elise-palethorpe

Just a minor comment to use nouns for file names (and as descriptive as possible), ie "multigrid_preconditioner" rather than "testing_preconditioner"

glwagner avatar Jul 15 '22 21:07 glwagner

@elise-palethorpe, MGImplicitFreeSurfaceSolver needed to be defined first before used as a preconditioned method in PGC. I flipped the order of the include files.

navidcy avatar Sep 03 '22 20:09 navidcy

@elise-palethorpe also perhaps change the validation script name as @glwagner suggest?

navidcy avatar Sep 03 '22 21:09 navidcy

@glwagner would you be keen to review this?

navidcy avatar Sep 03 '22 23:09 navidcy

@elise-palethorpe also perhaps change the validation script name as @glwagner suggest?

Do we need the file at all? Can I just include mg preconditioner in doubly_bounded_poisson.jl

elise-palethorpe avatar Sep 03 '22 23:09 elise-palethorpe

@elise-palethorpe also perhaps change the validation script name as @glwagner suggest?

Do we need the file at all? Can I just include mg preconditioner in doubly_bounded_poisson.jl

Yes, do that!

navidcy avatar Sep 03 '22 23:09 navidcy

@elise-palethorpe, I added some proper bench tests in doubly_bounded_poisson.jl.

Seems like the PCG solve! has many allocations! I don't know why... @glwagner, @simone-silvestri?

navidcy avatar Sep 04 '22 00:09 navidcy

I used Julia v1.8 memory allocation profiler and I saw that this https://github.com/CliMA/Oceananigans.jl/blob/a5409c27380a205f27961cc6ce4f24581b98fab8/src/Fields/field.jl#L500 creates a bunch of allocations.

navidcy avatar Sep 04 '22 02:09 navidcy

Also, maybe we want to have a dot product that allows masking immersed regions

simone-silvestri avatar Sep 05 '22 14:09 simone-silvestri

Some benches.

julia> include("validation/elliptic_solvers/doubly_bounded_poisson.jl")

julia> include("doubly_bounded_poisson.jl")
[ Info: Solving the Poisson equation with an FFT-based solver...
  123.083 μs (93 allocations: 17.56 KiB)
[ Info: Solving the Poisson equation with a conjugate gradient iterative solver...
  64.748 ms (80482 allocations: 25.93 MiB)
[ Info: Solving the Poisson equation with the Algebraic Multigrid solver...
  9.491 ms (498 allocations: 8.46 MiB)
[ Info: Solving the Poisson equation with a conjugate gradient preconditioned iterative solver w/ AMG as preconditioner...
  47.891 ms (12771 allocations: 111.97 MiB)

(The above are results with @btime... It's pretty obvious than PCG brings allocations to the roof...)

doubly_bounded_poisson

navidcy avatar Sep 05 '22 23:09 navidcy

ok @glwagner this is ready to review!

A question for you: We didn't include fill_halos!(z) in the MG-preconditioning:

https://github.com/CliMA/Oceananigans.jl/blob/bd0363a54c6f0054cc7a67f5f61e30f12a839bc1/src/Models/HydrostaticFreeSurfaceModels/pcg_implicit_free_surface_solver.jl#L231-L235

Do you think we should have had?

navidcy avatar Sep 07 '22 05:09 navidcy