-
Notifications
You must be signed in to change notification settings - Fork 88
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
Adds (S)SOR Preconditioner #1633
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
6d5a3f4
[fact] extract l/u initialization
MarcelKoch b59b1a4
[prec] implement SOR preconditioner reference kernels
MarcelKoch 60be08a
[prec] add SOR core + ref tests
MarcelKoch 47b7166
[prec] add sor parsing
MarcelKoch 23295d0
[prec] implement Gauß-Seidel preconditioner
MarcelKoch 17aaeda
[prec] add gauss seidel parsing
MarcelKoch 4b83873
[sor] review updates:
MarcelKoch 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
There are no files selected for viewing
This file contains 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 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,44 @@ | ||
// SPDX-FileCopyrightText: 2017 - 2024 The Ginkgo authors | ||
// | ||
// SPDX-License-Identifier: BSD-3-Clause | ||
|
||
#include "core/preconditioner/sor_kernels.hpp" | ||
|
||
#include <ginkgo/core/base/math.hpp> | ||
#include <ginkgo/core/matrix/csr.hpp> | ||
|
||
#include "common/unified/base/kernel_launch.hpp" | ||
|
||
|
||
namespace gko { | ||
namespace kernels { | ||
namespace GKO_DEVICE_NAMESPACE { | ||
namespace sor { | ||
|
||
|
||
template <typename ValueType, typename IndexType> | ||
void initialize_weighted_l( | ||
std::shared_ptr<const DefaultExecutor> exec, | ||
const matrix::Csr<ValueType, IndexType>* system_matrix, | ||
remove_complex<ValueType> weight, | ||
matrix::Csr<ValueType, IndexType>* l_mtx) GKO_NOT_IMPLEMENTED; | ||
|
||
GKO_INSTANTIATE_FOR_EACH_VALUE_AND_INDEX_TYPE( | ||
GKO_DECLARE_SOR_INITIALIZE_WEIGHTED_L); | ||
|
||
|
||
template <typename ValueType, typename IndexType> | ||
void initialize_weighted_l_u( | ||
std::shared_ptr<const DefaultExecutor> exec, | ||
const matrix::Csr<ValueType, IndexType>* system_matrix, | ||
remove_complex<ValueType> weight, matrix::Csr<ValueType, IndexType>* l_mtx, | ||
matrix::Csr<ValueType, IndexType>* u_mtx) GKO_NOT_IMPLEMENTED; | ||
|
||
GKO_INSTANTIATE_FOR_EACH_VALUE_AND_INDEX_TYPE( | ||
GKO_DECLARE_SOR_INITIALIZE_WEIGHTED_L_U); | ||
|
||
|
||
} // namespace sor | ||
} // namespace GKO_DEVICE_NAMESPACE | ||
} // namespace kernels | ||
} // namespace gko |
This file contains 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 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 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 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 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 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,56 @@ | ||
// SPDX-FileCopyrightText: 2017 - 2024 The Ginkgo authors | ||
// | ||
// SPDX-License-Identifier: BSD-3-Clause | ||
|
||
#ifndef GINKGO_CORE_FACTORIZATION_FACTORIZATION_HELPERS_HPP | ||
#define GINKGO_CORE_FACTORIZATION_FACTORIZATION_HELPERS_HPP | ||
|
||
|
||
#include <utility> | ||
|
||
|
||
namespace gko { | ||
namespace factorization { | ||
|
||
|
||
struct identity { | ||
template <typename T> | ||
constexpr T operator()(T value) | ||
{ | ||
return value; | ||
} | ||
}; | ||
|
||
|
||
template <typename DiagClosure, typename OffDiagClosure> | ||
class triangular_mtx_closure { | ||
public: | ||
constexpr triangular_mtx_closure(DiagClosure diag_closure, | ||
OffDiagClosure off_diag_closure) | ||
: diag_closure_(std::move(diag_closure)), | ||
off_diag_closure_(std::move(off_diag_closure)) | ||
{} | ||
|
||
template <typename T> | ||
constexpr T map_diag(T value) | ||
{ | ||
return diag_closure_(value); | ||
} | ||
|
||
template <typename T> | ||
constexpr T map_off_diag(T value) | ||
{ | ||
return off_diag_closure_(value); | ||
} | ||
|
||
private: | ||
DiagClosure diag_closure_; | ||
OffDiagClosure off_diag_closure_; | ||
}; | ||
|
||
|
||
} // namespace factorization | ||
} // namespace gko | ||
|
||
|
||
#endif // GINKGO_CORE_FACTORIZATION_FACTORIZATION_HELPERS_HPP |
This file contains 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,78 @@ | ||
// SPDX-FileCopyrightText: 2017 - 2024 The Ginkgo authors | ||
// | ||
// SPDX-License-Identifier: BSD-3-Clause | ||
|
||
#include <ginkgo/core/preconditioner/gauss_seidel.hpp> | ||
#include <ginkgo/core/preconditioner/sor.hpp> | ||
|
||
#include "core/config/config_helper.hpp" | ||
|
||
|
||
namespace gko { | ||
namespace preconditioner { | ||
|
||
|
||
template <typename ValueType, typename IndexType> | ||
typename GaussSeidel<ValueType, IndexType>::parameters_type | ||
GaussSeidel<ValueType, IndexType>::parse( | ||
const config::pnode& config, const config::registry& context, | ||
const config::type_descriptor& td_for_child) | ||
{ | ||
auto params = GaussSeidel::build(); | ||
|
||
if (auto& obj = config.get("skip_sorting")) { | ||
params.with_skip_sorting(config::get_value<bool>(obj)); | ||
} | ||
if (auto& obj = config.get("symmetric")) { | ||
params.with_symmetric(config::get_value<bool>(obj)); | ||
} | ||
if (auto& obj = config.get("l_solver")) { | ||
params.with_l_solver( | ||
gko::config::parse_or_get_factory<const LinOpFactory>( | ||
obj, context, td_for_child)); | ||
} | ||
if (auto& obj = config.get("u_solver")) { | ||
params.with_u_solver( | ||
gko::config::parse_or_get_factory<const LinOpFactory>( | ||
obj, context, td_for_child)); | ||
} | ||
|
||
return params; | ||
} | ||
|
||
|
||
template <typename ValueType, typename IndexType> | ||
std::unique_ptr<typename GaussSeidel<ValueType, IndexType>::composition_type> | ||
GaussSeidel<ValueType, IndexType>::generate( | ||
std::shared_ptr<const LinOp> system_matrix) const | ||
{ | ||
auto product = | ||
std::unique_ptr<composition_type>(static_cast<composition_type*>( | ||
this->LinOpFactory::generate(std::move(system_matrix)).release())); | ||
return product; | ||
} | ||
|
||
|
||
template <typename ValueType, typename IndexType> | ||
std::unique_ptr<LinOp> GaussSeidel<ValueType, IndexType>::generate_impl( | ||
std::shared_ptr<const LinOp> system_matrix) const | ||
{ | ||
return Sor<ValueType, IndexType>::build() | ||
.with_skip_sorting(parameters_.skip_sorting) | ||
.with_symmetric(parameters_.symmetric) | ||
.with_relaxation_factor(static_cast<remove_complex<ValueType>>(1.0)) | ||
.with_l_solver(parameters_.l_solver) | ||
.with_u_solver(parameters_.u_solver) | ||
.on(this->get_executor()) | ||
->generate(std::move(system_matrix)); | ||
} | ||
|
||
|
||
#define GKO_DECLARE_GAUSS_SEIDEL(ValueType, IndexType) \ | ||
class GaussSeidel<ValueType, IndexType> | ||
|
||
GKO_INSTANTIATE_FOR_EACH_VALUE_AND_INDEX_TYPE(GKO_DECLARE_GAUSS_SEIDEL); | ||
|
||
|
||
} // namespace preconditioner | ||
} // namespace gko |
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.
doesn't it work with the
make_unique
withoutstatic_cast
?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.
and use generate_impl directly?
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
static_cast
is necessary, becauseLinOpFactory::generate
returns aLinOp*
, which can't be used in the constructor of the unique_ptr. Themake_unique
also doesn't work, because thecomposition_type
constructor doesn't take aLinOp*
.generate_impl
is not used directly, because this could require to copy-paste the implementation ofLinOpFactory::generate
here, so that it can log correctly and copy to the right executor.