-
Notifications
You must be signed in to change notification settings - Fork 14
Refactor preconditioner implementation #167
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
Open
greole
wants to merge
18
commits into
enh/repart_comm
Choose a base branch
from
refact/precond
base: enh/repart_comm
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
f84472e
add get_ranks_per_gpu
greole 87f4807
add basic implementation of gatherv instead off alltoallv for repart …
greole 6fdc34f
use forceHostBuffer for vector updates
greole eb7b9b3
wip performance tuning
greole b37b31e
format files
greole 8ca5a5c
use optimizer as default
greole 155f0ac
WIP, avoid symmetric MPI_Igatherv
greole e24d915
wip move preconditioner to separate implementation files
greole 1686221
move LU implementation
greole ddf0c86
format
greole 2bb56de
add ISAI
greole fb2a9c3
clean-up
greole a894907
move to CoarseSolver.cpp
greole dfa28f4
extract num rows in ml schwarz
greole 9b37b59
use schwarz dispatch function
greole 47eac9e
Apply suggestions from code review
greole dc72d76
clean-up some unneeded gko::share
greole 56e82a4
Merge branch 'enh/repart_comm' into refact/precond
greole File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,103 @@ | ||
| // SPDX-FileCopyrightText: 2025 OGL authors | ||
| // | ||
| // SPDX-License-Identifier: GPL-3.0-or-later | ||
| #pragma once | ||
|
|
||
| #include "OGL/Preconditioner/Schwarz.hpp" | ||
|
|
||
| class Cholesky // : public PreconditionerWrapper | ||
| { | ||
| using dic = gko::preconditioner::Jacobi<double, label>; | ||
| using fic = gko::preconditioner::Jacobi<float, label>; | ||
|
|
||
| std::shared_ptr<gko::Executor> exec_; | ||
| std::shared_ptr<const gko::LinOp> mtx_; | ||
| const dictionary &d_; | ||
| const label verbose_; | ||
| bool skip_sorting_; | ||
| bool multi_level_schwarz_; | ||
| word precision_; | ||
| word factorization_; | ||
|
|
||
|
|
||
| public: | ||
| Cholesky(std::shared_ptr<gko::Executor> exec, | ||
| std::shared_ptr<const gko::LinOp> mtx, const dictionary &d, | ||
| label verbose) | ||
| : exec_(exec), | ||
| mtx_(mtx), | ||
| d_(d), | ||
| verbose_(verbose), | ||
| skip_sorting_(d.lookupOrDefault<Switch>("skipSorting", true)), | ||
| multi_level_schwarz_( | ||
| d.lookupOrDefault<Switch>("multiLevelSchwarz", false)), | ||
| precision_(d.lookupOrDefault("precision", word("double"))), | ||
| factorization_(d.lookupOrDefault("factorization", word("IC"))) | ||
| { | ||
| word msg = "Generate " + factorization_ + | ||
| " preconditioner:\n\tprecision: " + precision_; | ||
| MLOG_0(verbose_, msg) | ||
| } | ||
|
|
||
|
|
||
| std::shared_ptr<gko::LinOp> generate_factorization() const | ||
| { | ||
| if (factorization_ == "IC") { | ||
| auto factorization_factory = | ||
| gko::factorization::Ic<scalar, label>::build() | ||
| .with_skip_sorting(skip_sorting_) | ||
| .on(exec_); | ||
|
|
||
| auto gkodistmatrix = | ||
| gko::as<RepartDistMatrix>(mtx_)->get_dist_matrix(); | ||
| return factorization_factory->generate( | ||
| gko::as<gko::experimental::distributed::Matrix<scalar, label, | ||
| label>>( | ||
| gkodistmatrix) | ||
| ->get_local_matrix()); | ||
| } | ||
| if (factorization_ == "ParIC") { | ||
| label iterations = d_.lookupOrDefault("iterations", label(5)); | ||
| auto factorization_factory = | ||
| gko::factorization::ParIct<scalar, label>::build() | ||
| .with_skip_sorting(skip_sorting_) | ||
| .with_iterations(iterations) | ||
| .on(exec_); | ||
|
|
||
| auto gkodistmatrix = | ||
| gko::as<RepartDistMatrix>(mtx_)->get_dist_matrix(); | ||
| return factorization_factory->generate( | ||
| gko::as<gko::experimental::distributed::Matrix<scalar, label, | ||
| label>>( | ||
| gkodistmatrix) | ||
| ->get_local_matrix()); | ||
| } | ||
| if (factorization_ == "ParICT") { | ||
| label iterations = d_.lookupOrDefault("iterations", label(5)); | ||
| label fillInLimit = d_.lookupOrDefault("fillInLimit", label(2)); | ||
| auto factorization_factory = | ||
| gko::factorization::ParIct<scalar, label>::build() | ||
| .with_skip_sorting(skip_sorting_) | ||
| .with_fill_in_limit(fillInLimit) | ||
| .with_iterations(iterations) | ||
| .on(exec_); | ||
|
|
||
| auto gkodistmatrix = | ||
| gko::as<RepartDistMatrix>(mtx_)->get_dist_matrix(); | ||
| return factorization_factory->generate( | ||
| gko::as<gko::experimental::distributed::Matrix<scalar, label, | ||
| label>>( | ||
| gkodistmatrix) | ||
| ->get_local_matrix()); | ||
| } | ||
| } | ||
|
|
||
| virtual std::shared_ptr<gko::LinOp> create() | ||
| { | ||
| auto precond_factory = gko::preconditioner::Ic<>::build().on(exec_); | ||
| return dispatch_schwarz( | ||
| mtx_, exec_, | ||
| gko::share(precond_factory->generate(generate_factorization())), d_, | ||
| verbose_); | ||
| } | ||
| }; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| // SPDX-FileCopyrightText: 2024 OGL authors | ||
| // | ||
| // SPDX-License-Identifier: GPL-3.0-or-later | ||
| #pragma once | ||
|
|
||
| #include <ginkgo/ginkgo.hpp> | ||
|
|
||
| #include "fvCFD.H" | ||
|
|
||
| std::shared_ptr<const gko::LinOpFactory> generate_coarse_solver( | ||
| std::shared_ptr<gko::Executor> exec, const dictionary &d, label verbose); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,81 @@ | ||
| // SPDX-FileCopyrightText: 2025 OGL authors | ||
| // | ||
| // SPDX-License-Identifier: GPL-3.0-or-later | ||
| #pragma once | ||
|
|
||
| #include "OGL/Preconditioner/Schwarz.hpp" | ||
|
|
||
| class ISAI // : public PreconditionerWrapper | ||
| { | ||
| using dic = gko::preconditioner::Jacobi<double, label>; | ||
| using fic = gko::preconditioner::Jacobi<float, label>; | ||
|
|
||
| std::shared_ptr<gko::Executor> exec_; | ||
| std::shared_ptr<const gko::LinOp> mtx_; | ||
| const dictionary &d_; | ||
| const label verbose_; | ||
| bool skip_sorting_; | ||
| bool multi_level_schwarz_; | ||
| word type_; | ||
| label sparsityPower_; | ||
|
|
||
|
|
||
| public: | ||
| ISAI(std::shared_ptr<gko::Executor> exec, | ||
| std::shared_ptr<const gko::LinOp> mtx, const dictionary &d, | ||
| label verbose) | ||
| : exec_(exec), | ||
| mtx_(mtx), | ||
| d_(d), | ||
| verbose_(verbose), | ||
| skip_sorting_(d.lookupOrDefault<Switch>("skipSorting", true)), | ||
| multi_level_schwarz_( | ||
| d.lookupOrDefault<Switch>("multiLevelSchwarz", false)), | ||
| type_(d.lookupOrDefault("type", word("general"))), | ||
| sparsityPower_(d.lookupOrDefault("sparsityPower", label(1))) | ||
| { | ||
| word msg = "Generate " + type_ + "ISAI" + | ||
| " preconditioner:\n\tsparsityPower: " + | ||
| std::to_string(sparsityPower_); | ||
| MLOG_0(verbose_, msg) | ||
| } | ||
|
|
||
| auto generate_precond_factory_spd() | ||
| { | ||
| return gko::preconditioner::Isai<gko::preconditioner::isai_type::spd, | ||
| scalar, label>::build() | ||
| .with_skip_sorting(skip_sorting_) | ||
| .with_sparsity_power(sparsityPower_) | ||
| .on(exec_); | ||
| } | ||
|
|
||
| auto generate_precond_factory_general() | ||
| { | ||
| return gko::preconditioner::Isai< | ||
| gko::preconditioner::isai_type::general, scalar, | ||
| label>::build() | ||
| .with_skip_sorting(skip_sorting_) | ||
| .with_sparsity_power(sparsityPower_) | ||
| .on(exec_); | ||
| } | ||
|
|
||
| virtual std::shared_ptr<gko::LinOp> create() | ||
| { | ||
| if (type_ == "SPD") { | ||
| auto b = generate_precond_factory_spd(); | ||
| return dispatch_schwarz( | ||
| mtx_, exec_, | ||
| gko::share( | ||
| b->generate(gko::as<RepartDistMatrix>(mtx_)->get_local())), | ||
| d_, verbose_); | ||
| } | ||
| if (type_ == "General") { | ||
| auto b = generate_precond_factory_general(); | ||
| return dispatch_schwarz( | ||
| mtx_, exec_, | ||
| gko::share( | ||
| b->generate(gko::as<RepartDistMatrix>(mtx_)->get_local())), | ||
| d_, verbose_); | ||
| } | ||
| } | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| // SPDX-FileCopyrightText: 2025 OGL authors | ||
| // | ||
| // SPDX-License-Identifier: GPL-3.0-or-later | ||
| #pragma once | ||
|
|
||
| #include "OGL/Preconditioner/Schwarz.hpp" | ||
|
|
||
| class BlockJacobi // : public PreconditionerWrapper | ||
| { | ||
| using dbj = gko::preconditioner::Jacobi<double, label>; | ||
| using fbj = gko::preconditioner::Jacobi<float, label>; | ||
|
|
||
| std::shared_ptr<gko::Executor> exec_; | ||
| std::shared_ptr<const gko::LinOp> mtx_; | ||
| const dictionary &d_; | ||
| const label verbose_; | ||
| bool skip_sorting_; | ||
| bool multi_level_schwarz_; | ||
| label max_block_size_; | ||
| word precision_; | ||
|
|
||
|
|
||
| public: | ||
| BlockJacobi(std::shared_ptr<gko::Executor> exec, | ||
| std::shared_ptr<const gko::LinOp> mtx, const dictionary &d, | ||
| label verbose) | ||
| : exec_(exec), | ||
| mtx_(mtx), | ||
| d_(d), | ||
| verbose_(verbose), | ||
| skip_sorting_(d.lookupOrDefault<Switch>("skipSorting", true)), | ||
| multi_level_schwarz_( | ||
| d.lookupOrDefault<Switch>("multiLevelSchwarz", false)), | ||
| max_block_size_(d.lookupOrDefault("maxBlockSize", label(1))), | ||
| precision_(d.lookupOrDefault("precision", word("double"))) | ||
| { | ||
| word msg = "Generate (Block)-Jacobi preconditioner:\n\tprecision: " + | ||
| precision_ + "\n\tmaxBlockSize " + | ||
| std::to_string(max_block_size_); | ||
| MLOG_0(verbose_, msg) | ||
| } | ||
|
|
||
| virtual std::shared_ptr<gko::LinOp> create() | ||
| { | ||
| auto builder = [this](auto b) { | ||
| return b.with_skip_sorting(skip_sorting_) | ||
| .with_max_block_size(static_cast<gko::uint32>(max_block_size_)) | ||
| .on(exec_); | ||
| }; | ||
|
|
||
| if (precision_ == "double") { | ||
| auto b = builder(dbj::build()); | ||
| return dispatch_schwarz( | ||
| mtx_, exec_, | ||
| gko::share( | ||
| b->generate(gko::as<RepartDistMatrix>(mtx_)->get_local())), | ||
| d_, verbose_); | ||
| } | ||
| if (precision_ == "float") { | ||
| auto b = builder(fbj::build()); | ||
| return dispatch_schwarz( | ||
| mtx_, exec_, | ||
| gko::share( | ||
| b->generate(gko::as<RepartDistMatrix>(mtx_)->get_local())), | ||
| d_, verbose_); | ||
| } | ||
|
|
||
| return {}; | ||
| } | ||
| }; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The function
generate_factorization()has multiple return paths through if statements but no return statement at the end, which could lead to undefined behavior if none of the conditions are met.