From d555be7e8ced855a67ed035da3818ed83f771935 Mon Sep 17 00:00:00 2001 From: Ilker Topcuoglu Date: Tue, 7 Jan 2025 13:57:39 -0700 Subject: [PATCH 1/2] ILU as preconditioner and solver options --- src/HypreSystem.cpp | 48 +++++++++++++++++++++++++++++++++++++++++++++ src/HypreSystem.h | 5 +++++ 2 files changed, 53 insertions(+) diff --git a/src/HypreSystem.cpp b/src/HypreSystem.cpp index adaea71..aeda5b3 100644 --- a/src/HypreSystem.cpp +++ b/src/HypreSystem.cpp @@ -57,6 +57,9 @@ void HypreSystem::setup_precon_and_solver() { if (preconditioner == "boomeramg") { setup_boomeramg_precond(); + } + else if (preconditioner == "ilu"){ + setup_ilu_precond(); } else if (preconditioner == "none") { usePrecond_ = false; } else { @@ -75,6 +78,8 @@ void HypreSystem::setup_precon_and_solver() { setup_boomeramg_solver(); } else if (!method.compare("cogmres")) { setup_cogmres(); + } else if (!method.compare("ilu")) { + setup_ilu(); } else { throw std::runtime_error("Invalid option for solver method provided: " + method); @@ -286,6 +291,28 @@ void HypreSystem::setup_boomeramg_precond() { precondDestroyPtr_ = &HYPRE_BoomerAMGDestroy; } +void HypreSystem::setup_ilu_precond() { + YAML::Node node = inpfile_["ilu_preconditioner_settings"]; + + HYPRE_ILUCreate(&precond_); + HYPRE_ILUSetType(precond_, get_optional(node, "ilu_type", 0)); + HYPRE_ILUSetMaxIter(precond_, get_optional(node, "max_iterations", 1)); + HYPRE_ILUSetPrintLevel(precond_, get_optional(node, "print_level", 1)); + HYPRE_ILUSetTol(precond_, get_optional(node, "tolerance", 0.0)); + + HYPRE_ILUSetIterativeSetupType(precond_, + get_optional(node, "algorithm_type", 0)); + HYPRE_ILUSetIterativeSetupMaxIter( + precond_, get_optional(node, "max_ilu_iterations", 1)); + HYPRE_ILUSetIterativeSetupTolerance( + precond_, get_optional(node, "iterative_ilu_tolerance", 1e-5)); + HYPRE_ILUSetTriSolve(precond_, get_optional(node, "trisolve", 1)); + + precondSetupPtr_ = &HYPRE_ILUSetup; + precondSolvePtr_ = &HYPRE_ILUSolve; + precondDestroyPtr_ = &HYPRE_ILUDestroy; +} + void HypreSystem::setup_cogmres() { YAML::Node node = inpfile_["solver_settings"]; @@ -371,6 +398,27 @@ void HypreSystem::setup_cg() { solverSolvePtr_ = &HYPRE_ParCSRPCGSolve; } +void HypreSystem::setup_ilu() { + YAML::Node node = inpfile_["solver_settings"]; + HYPRE_ILUCreate(&solver_); + HYPRE_ILUSetType(solver_, get_optional(node, "ilu_type", 0)); + HYPRE_ILUSetMaxIter(solver_, get_optional(node, "max_iterations", 20)); + HYPRE_ILUSetPrintLevel(solver_, get_optional(node, "print_level", 4)); + + HYPRE_ILUSetIterativeSetupType(solver_, + get_optional(node, "algorithm_type", 0)); + HYPRE_ILUSetIterativeSetupMaxIter( + solver_, get_optional(node, "max_ilu_iterations", 1)); + HYPRE_ILUSetIterativeSetupTolerance( + solver_, get_optional(node, "iterative_ilu_tolerance", 1e-5)); + HYPRE_ILUSetTriSolve(solver_, get_optional(node, "trisolve", 1)); + + solverDestroyPtr_ = &HYPRE_ILUDestroy; + solverSetupPtr_ = &HYPRE_ILUSetup; + solverPrecondPtr_ = nullptr; + solverSolvePtr_ = &HYPRE_ILUSolve; +} + void HypreSystem::destroy_system() { if (mat_) HYPRE_IJMatrixDestroy(mat_); diff --git a/src/HypreSystem.h b/src/HypreSystem.h index 8aa3c3e..f0052fc 100644 --- a/src/HypreSystem.h +++ b/src/HypreSystem.h @@ -157,6 +157,11 @@ class HypreSystem { void setup_bicg(); void setup_cg(); + //! Setup ILU + void setup_ilu_precond(); + + void setup_ilu(); + //! MPI Communicator object MPI_Comm comm_; From a9c8b1ad6fc65d53346cb646a729e6fb1406f399 Mon Sep 17 00:00:00 2001 From: Ilker Topcuoglu Date: Tue, 7 Jan 2025 15:35:40 -0700 Subject: [PATCH 2/2] More ILU options for the preconditioner and for the stand-alone solver --- src/HypreSystem.cpp | 43 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-) diff --git a/src/HypreSystem.cpp b/src/HypreSystem.cpp index aeda5b3..d24dd60 100644 --- a/src/HypreSystem.cpp +++ b/src/HypreSystem.cpp @@ -297,17 +297,38 @@ void HypreSystem::setup_ilu_precond() { HYPRE_ILUCreate(&precond_); HYPRE_ILUSetType(precond_, get_optional(node, "ilu_type", 0)); HYPRE_ILUSetMaxIter(precond_, get_optional(node, "max_iterations", 1)); - HYPRE_ILUSetPrintLevel(precond_, get_optional(node, "print_level", 1)); HYPRE_ILUSetTol(precond_, get_optional(node, "tolerance", 0.0)); + HYPRE_ILUSetLocalReordering(precond_, get_optional(node, "local_reordering", 0)); + HYPRE_ILUSetPrintLevel(precond_, get_optional(node, "print_level", 1)); + + // ILUK parameters + HYPRE_ILUSetLevelOfFill(precond_, get_optional(node, "fill", 0)); + + // ILUT parameters + HYPRE_ILUSetMaxNnzPerRow(precond_,get_optional(node, "max_nnz_per_row", 1000)); + HYPRE_ILUSetDropThreshold(precond_,get_optional(node, "drop_threshold", 1.0e-2)); + // 0 : Non-iterative algorithm (default) + // 1 : Asynchronous with in-place storage + // 2 : Asynchronous with explicit storage splitting + // 3 : Synchronous with explicit storage splitting + // 4 : Semi-synchronous with explicit storage splitting + // Iterative ILU is available only for zero fill-in and it depends on rocSparse HYPRE_ILUSetIterativeSetupType(precond_, get_optional(node, "algorithm_type", 0)); HYPRE_ILUSetIterativeSetupMaxIter( precond_, get_optional(node, "max_ilu_iterations", 1)); HYPRE_ILUSetIterativeSetupTolerance( precond_, get_optional(node, "iterative_ilu_tolerance", 1e-5)); + + // 0: iterative + // 1: direct (default) HYPRE_ILUSetTriSolve(precond_, get_optional(node, "trisolve", 1)); + // Jacobi iterations for lower and upper triangular solves + HYPRE_ILUSetLowerJacobiIters(precond_,get_optional(node, "lower_jacobi_iters", 5)); + HYPRE_ILUSetUpperJacobiIters(precond_,get_optional(node, "upper_jacobi_iters", 5)); + precondSetupPtr_ = &HYPRE_ILUSetup; precondSolvePtr_ = &HYPRE_ILUSolve; precondDestroyPtr_ = &HYPRE_ILUDestroy; @@ -403,15 +424,35 @@ void HypreSystem::setup_ilu() { HYPRE_ILUCreate(&solver_); HYPRE_ILUSetType(solver_, get_optional(node, "ilu_type", 0)); HYPRE_ILUSetMaxIter(solver_, get_optional(node, "max_iterations", 20)); + HYPRE_ILUSetTol(solver_, get_optional(node, "tolerance", 0.0)); + HYPRE_ILUSetLocalReordering(solver_, get_optional(node,"local_reordering", 0)); HYPRE_ILUSetPrintLevel(solver_, get_optional(node, "print_level", 4)); + // ILUK parameters + HYPRE_ILUSetLevelOfFill(solver_, get_optional(node, "fill", 0)); + + // ILUT parameters + HYPRE_ILUSetMaxNnzPerRow(solver_,get_optional(node, "max_nnz_per_row", 1000)); + HYPRE_ILUSetDropThreshold(solver_,get_optional(node, "drop_threshold", 1.0e-2)); + + // 0 : Non-iterative algorithm (default) + // 1 : Asynchronous with in-place storage + // 2 : Asynchronous with explicit storage splitting + // 3 : Synchronous with explicit storage splitting + // 4 : Semi-synchronous with explicit storage splitting + // Iterative ILU is available only for zero fill-in and it depends on rocSparse HYPRE_ILUSetIterativeSetupType(solver_, get_optional(node, "algorithm_type", 0)); HYPRE_ILUSetIterativeSetupMaxIter( solver_, get_optional(node, "max_ilu_iterations", 1)); HYPRE_ILUSetIterativeSetupTolerance( solver_, get_optional(node, "iterative_ilu_tolerance", 1e-5)); + // 0: iterative + // 1: direct (default) HYPRE_ILUSetTriSolve(solver_, get_optional(node, "trisolve", 1)); + // Jacobi iterations for lower and upper triangular solves + HYPRE_ILUSetLowerJacobiIters(solver_, get_optional(node, "lower_jacobi_iters", 5)); + HYPRE_ILUSetUpperJacobiIters(solver_, get_optional(node, "upper_jacobi_iters", 5)); solverDestroyPtr_ = &HYPRE_ILUDestroy; solverSetupPtr_ = &HYPRE_ILUSetup;