Add a uniform coarsening algorithm - #2016
Conversation
yhmtsai
left a comment
There was a problem hiding this comment.
any reason to keep prolong/restrict as CSR not using SparsityCSR and RowGatherer?
| if (c > 0) A_data.nonzeros.emplace_back(i, i - 1, -1); | ||
| if (c < N - 1) A_data.nonzeros.emplace_back(i, i + 1, -1); | ||
| if (r > 0) A_data.nonzeros.emplace_back(i, i - N, -1); | ||
| if (r < N - 1) A_data.nonzeros.emplace_back(i, i + N, -1); |
There was a problem hiding this comment.
| if (c > 0) A_data.nonzeros.emplace_back(i, i - 1, -1); | |
| if (c < N - 1) A_data.nonzeros.emplace_back(i, i + 1, -1); | |
| if (r > 0) A_data.nonzeros.emplace_back(i, i - N, -1); | |
| if (r < N - 1) A_data.nonzeros.emplace_back(i, i + N, -1); | |
| if (c > 0) {A_data.nonzeros.emplace_back(i, i - 1, -1);} | |
| if (c < N - 1) {A_data.nonzeros.emplace_back(i, i + 1, -1);} | |
| if (r > 0) {A_data.nonzeros.emplace_back(i, i - N, -1);} | |
| if (r < N - 1) {A_data.nonzeros.emplace_back(i, i + N, -1);} |
There was a problem hiding this comment.
maybe you can reorder it a bit such that it is already sorted
| * UniformCoarsening is a simple coarse grid generation algorithm. It | ||
| * selects the coarse matrix from the fine matrix by constant jumps that can be | ||
| * specified by the user. |
There was a problem hiding this comment.
updated the wording now. Its not really geometric, but its not algebraic either. So, I just say index-based ordering now.
| * When set to `true` (the default), every fine row is mapped to | ||
| * its nearest coarse row (aggregation-style), so that the Galerkin |
There was a problem hiding this comment.
add more detail about the nearest coarse row? It is assigned to the floor(id/skip_coarse), right?
| using real_type = gko::remove_complex<value_type>; | ||
| UniformCoarsening() |
There was a problem hiding this comment.
| using real_type = gko::remove_complex<value_type>; | |
| UniformCoarsening() | |
| using real_type = gko::remove_complex<value_type>; | |
| UniformCoarsening() |
| SCOPED_TRACE("Using coarse skip:" + std::to_string(coarse_skip)); | ||
| gko::kernels::reference::uniform_coarsening::fill_incremental_indices( | ||
| ref, coarse_skip, &c_rows); | ||
| gko::kernels::GKO_DEVICE_NAMESPACE::uniform_coarsening:: | ||
| fill_incremental_indices(exec, coarse_skip, &d_c_rows); | ||
| GKO_ASSERT_ARRAY_EQ(c_rows, d_c_rows); |
There was a problem hiding this comment.
| SCOPED_TRACE("Using coarse skip:" + std::to_string(coarse_skip)); | |
| gko::kernels::reference::uniform_coarsening::fill_incremental_indices( | |
| ref, coarse_skip, &c_rows); | |
| gko::kernels::GKO_DEVICE_NAMESPACE::uniform_coarsening:: | |
| fill_incremental_indices(exec, coarse_skip, &d_c_rows); | |
| GKO_ASSERT_ARRAY_EQ(c_rows, d_c_rows); | |
| SCOPED_TRACE("Using coarse skip:" + std::to_string(coarse_skip)); | |
| c_rows.fill(-gko::one<index_type>()); | |
| d_c_rows.fill(-gko::one<index_type>()); | |
| gko::kernels::reference::uniform_coarsening::fill_incremental_indices( | |
| ref, coarse_skip, &c_rows); | |
| gko::kernels::GKO_DEVICE_NAMESPACE::uniform_coarsening:: | |
| fill_incremental_indices(exec, coarse_skip, &d_c_rows); | |
| GKO_ASSERT_ARRAY_EQ(c_rows, d_c_rows); |
There was a problem hiding this comment.
because it updates the value in each loop
| using VT = value_type; | ||
| UniformCoarseningAgg() |
There was a problem hiding this comment.
| using VT = value_type; | |
| UniformCoarseningAgg() | |
| using VT = value_type; | |
| UniformCoarseningAgg() |
| using SparsityCsr = gko::matrix::SparsityCsr<value_type, index_type>; | ||
| using MgLevel = gko::multigrid::UniformCoarsening<value_type, index_type>; | ||
| using RowGatherer = gko::matrix::RowGatherer<index_type>; |
There was a problem hiding this comment.
| using SparsityCsr = gko::matrix::SparsityCsr<value_type, index_type>; | |
| using MgLevel = gko::multigrid::UniformCoarsening<value_type, index_type>; | |
| using RowGatherer = gko::matrix::RowGatherer<index_type>; | |
| using MgLevel = gko::multigrid::UniformCoarsening<value_type, index_type>; |
| auto c_rows = gko::array<index_type>(this->exec, 10); | ||
| c_rows.fill(-gko::one<index_type>()); | ||
|
|
||
| gko::kernels::reference::uniform_coarsening::fill_incremental_indices( | ||
| this->exec, 2, &c_rows); | ||
| GKO_ASSERT_ARRAY_EQ(c_rows, c2_rows); |
There was a problem hiding this comment.
| auto c_rows = gko::array<index_type>(this->exec, 10); | |
| c_rows.fill(-gko::one<index_type>()); | |
| gko::kernels::reference::uniform_coarsening::fill_incremental_indices( | |
| this->exec, 2, &c_rows); | |
| GKO_ASSERT_ARRAY_EQ(c_rows, c2_rows); | |
| auto c_rows = gko::array<index_type>(this->exec, 10); | |
| c_rows.fill(-gko::one<index_type>()); | |
| gko::kernels::reference::uniform_coarsening::fill_incremental_indices( | |
| this->exec, 2, &c_rows); | |
| GKO_ASSERT_ARRAY_EQ(c_rows, c2_rows); |
There was a problem hiding this comment.
It is more to keep the consistent as the following.
| } | ||
|
|
||
|
|
||
| } // namespace |
There was a problem hiding this comment.
same here
| } // namespace |
| auto uc_factory = | ||
| uc::build().with_coarse_skip(2).with_aggregation(false).on(this->exec); |
There was a problem hiding this comment.
I think we need another test for the diag matrix size is not divisible by coarse_skip like coarse_skip = 3
| if (c > 0) A_data.nonzeros.emplace_back(i, i - 1, -1); | ||
| if (c < N - 1) A_data.nonzeros.emplace_back(i, i + 1, -1); | ||
| if (r > 0) A_data.nonzeros.emplace_back(i, i - N, -1); | ||
| if (r < N - 1) A_data.nonzeros.emplace_back(i, i + N, -1); |
| array<IndexType>* coarse_rows) | ||
| { | ||
| const size_type num_elems = coarse_rows->get_size(); | ||
| const size_type num_iters = (num_elems + coarse_skip - 1) / coarse_skip; |
|
|
||
|
|
||
| /** | ||
| * UniformCoarsening is a simple algebraic coarse grid generation algorithm. |
There was a problem hiding this comment.
| * UniformCoarsening is a simple algebraic coarse grid generation algorithm. | |
| * UniformCoarsening is a simple geometric coarse grid generation algorithm. |
To me it is more like geometric?
5f54885 to
ceef8f9
Compare
ceef8f9 to
7e13493
Compare
|
@pratikvn after rebase, you do not need EnableLinOp anymore, but you will need to change it to LinOp and corresponding constructor |
7e13493 to
cef6b44
Compare
|
Error: The following files need to be formatted: You can find a formatting patch under Artifacts here or run |
This PR adds a uniform coarsening algorithm, an improved version of #1526. The idea is the same as in there, but now there is an option to enforce connectedness that ensures that the graphs in the coarser levels remain connected and there are no disjoint vertices.
While still algebraic, this coarsening strategy is cheaper to generate than PGM, and might be beneficial for matrices with a uniform sparsity pattern.