ginkgo icon indicating copy to clipboard operation
ginkgo copied to clipboard

Add a uniform coarse generation algorithm

Open pratikvn opened this issue 1 year ago • 12 comments

This PR is an updated version of #979 . The idea is to have a very cheap coarse grid generation algorithm that works well for matrices that are uniform, for example, matrices that arise from stencils on structured grids.

For example, for a 7 point stencil on a 3D grid, it is very competitive to PGM (with_deterministic=false) with much faster generation and faster apply for larger problems (on OMP executor with 8 cores):

unif_pgm

pratikvn avatar Jan 13 '24 01:01 pratikvn

Quality Gate Passed Quality Gate passed

The SonarCloud Quality Gate passed, but some issues were introduced.

44 New issues
1 Security Hotspot
66.4% Coverage on New Code
2.0% Duplication on New Code

See analysis details on SonarCloud

sonarqubecloud[bot] avatar Jan 13 '24 05:01 sonarqubecloud[bot]

Codecov Report

Attention: Patch coverage is 97.64310% with 7 lines in your changes are missing coverage. Please review.

Project coverage is 89.78%. Comparing base (fb70ec0) to head (0537b1e). Report is 232 commits behind head on develop.

:exclamation: Current head 0537b1e differs from pull request most recent head 915e227. Consider uploading reports for the commit 915e227 to get more accurate results

Files Patch % Lines
...ence/test/multigrid/uniform_coarsening_kernels.cpp 96.32% 5 Missing :warning:
core/device_hooks/common_kernels.inc.cpp 0.00% 2 Missing :warning:
Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #1526      +/-   ##
===========================================
- Coverage    91.04%   89.78%   -1.27%     
===========================================
  Files          700      707       +7     
  Lines        56996    57487     +491     
===========================================
- Hits         51894    51612     -282     
- Misses        5102     5875     +773     

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

codecov[bot] avatar Jan 13 '24 06:01 codecov[bot]

Especially focusing on distributed, I think if we include this, we should try to support at least 2D and maybe 3D coarsening (i + n * j and i + n * j + k * n * m).

upsj avatar Jan 19 '24 09:01 upsj

Maybe it makes sense to split the UniformCoarsening class up. The generated object essentially stores an array with coarse row indices, so it seems natural to allow users to pass in these indices. But I don't think we can add a parameter to the existing class, since then there would be two mutually exclusive parameters. I think Tobias' approach for the direct solvers, i.e. having multiple factories that generate the same class makes sense here.

MarcelKoch avatar Jan 19 '24 15:01 MarcelKoch

@upsj, After a bit of thought, I think this class should not represent Geometric/Structured coarsening. Uniform coarsening is just a cheap coarsening method that just uniformly discards rows and columns to construct the coarse matrix, and hence is not suitable for Geometric coarsening, which needs to create connections between the coarse nodes.

@MarcelKoch , we already provide the users with a way to specify custom indices for coarsening with the FixedCoarsening class

pratikvn avatar Jul 04 '24 12:07 pratikvn

@pratikvn If we discard variables for restriction, we still need to interpolate new values for prolongation, so I don't yet see how this makes multi-dimensional coarsening impossible if 1D coarsening is possible?

upsj avatar Jul 04 '24 12:07 upsj

In a similar fashion to PGM, the prolongation matrix will be a transpose of the restriction matrix. I think maybe I have given a wrong impression that this would be a 1D coarsening. The fine level vectors will not have extrapolated values, but just "mapped" values.

pratikvn avatar Jul 04 '24 12:07 pratikvn

Doesn't PGM do the same thing? And I believe we are mixing two things here - coarsening and interpolation. One is structural, one concerns the actual numerical values.

upsj avatar Jul 04 '24 12:07 upsj

Just adding more performance results on a 7pt stencil and some chosen matrices from Suitesparse, to show that this type of coarsening can help in certain cases.

Apply speedup for cage15 (v/s PGM) matrix and bcsstm39 matrix (v/s no preconditioning)

speedup_app_ss_bicgstab_cskip.pdf

Apply speedup for 7pt stencil (v/s PGM)

speedup_app_7pt_cg_cskip.pdf

Generate speedup for 7pt stencil (v/s PGM)

speedup_gen_7pt_cg_cskip.pdf

pratikvn avatar Jul 17 '24 14:07 pratikvn

I don't think these results matter, since even for simple stencils, the matrix loses all connectivity:

Take the poisson-solver example and plug in the following code:

    auto gen = gko::multigrid::UniformCoarsening<ValueType, IndexType>::build().on(app_exec)->generate(matrix->clone());
    gko::write(std::cout, matrix);
    gko::write(std::cout, gko::as<mtx>(gen->get_composition()->get_operators()[1]));

The fine matrix is tridiagonal, but the coarse matrix is just a diagonal matrix.

upsj avatar Jul 17 '24 15:07 upsj