20 #ifndef GEOS_LINEARALGEBRA_INTERFACES_HYPREUTILS_HPP_ 
   21 #define GEOS_LINEARALGEBRA_INTERFACES_HYPREUTILS_HPP_ 
   24 #include "common/GEOS_RAJA_Interface.hpp" 
   26 #include "codingUtilities/Utilities.hpp" 
   29 #include <HYPRE_krylov.h> 
   30 #include <HYPRE_parcsr_ls.h> 
   32 #if GEOS_USE_HYPRE_DEVICE == GEOS_USE_HYPRE_CUDA || GEOS_USE_HYPRE_DEVICE == GEOS_USE_HYPRE_HIP 
   34 #define GEOS_HYPRE_DEVICE GEOS_DEVICE 
   37 #define GEOS_HYPRE_DEVICE 
   52   using SetupFunc = HYPRE_Int (*)( HYPRE_Solver, HYPRE_ParCSRMatrix, HYPRE_ParVector, HYPRE_ParVector );
 
   55   using SolveFunc = HYPRE_Int (*)( HYPRE_Solver, HYPRE_ParCSRMatrix, HYPRE_ParVector, HYPRE_ParVector );
 
   80     case hostMemorySpace: 
return HYPRE_MEMORY_HOST;
 
   81 #if GEOS_USE_HYPRE_DEVICE == GEOS_USE_HYPRE_CUDA 
   82     case LvArray::MemorySpace::cuda: 
return HYPRE_MEMORY_DEVICE;
 
   84 #if GEOS_USE_HYPRE_DEVICE == GEOS_USE_HYPRE_HIP 
   85     case  LvArray::MemorySpace::hip: 
return HYPRE_MEMORY_DEVICE;
 
   87     default: 
return HYPRE_MEMORY_HOST;
 
   99     case HYPRE_MEMORY_HOST: 
return hostMemorySpace;
 
  100 #if GEOS_USE_HYPRE_DEVICE == GEOS_USE_HYPRE_CUDA 
  101     case HYPRE_MEMORY_DEVICE: 
return parallelDeviceMemorySpace;
 
  103 #if GEOS_USE_HYPRE_DEVICE == GEOS_USE_HYPRE_HIP 
  104     case HYPRE_MEMORY_DEVICE: 
return parallelDeviceMemorySpace;
 
  106     default: 
return hostMemorySpace;
 
  110 #if GEOS_USE_HYPRE_DEVICE == GEOS_USE_HYPRE_CUDA || GEOS_USE_HYPRE_DEVICE == GEOS_USE_HYPRE_HIP 
  115 constexpr LvArray::MemorySpace 
memorySpace = parallelDeviceMemorySpace;
 
  124 constexpr LvArray::MemorySpace 
memorySpace = hostMemorySpace;
 
  126 constexpr HYPRE_MemoryLocation 
memoryLocation = HYPRE_MEMORY_HOST;
 
  137 #if GEOS_USE_HYPRE_DEVICE == GEOS_USE_HYPRE_CUDA || GEOS_USE_HYPRE_DEVICE == GEOS_USE_HYPRE_HIP 
  139                "HYPRE_Int and geos::localIndex must have the same size" );
 
  140 static_assert( std::is_signed< HYPRE_Int >::value == std::is_signed< geos::localIndex >::value,
 
  141                "HYPRE_Int and geos::localIndex must both be signed or unsigned" );
 
  152 #if GEOS_USE_HYPRE_DEVICE == GEOS_USE_HYPRE_CUDA 
  153   cudaError_t 
const err = cudaGetLastError();
 
  154   GEOS_ERROR_IF( err != cudaSuccess, GEOS_FMT( 
"Previous CUDA errors found: {} ({} at {}:{})", msg, cudaGetErrorString( err ), file, line ) );
 
  155 #elif GEOS_USE_HYPRE_DEVICE == GEOS_USE_HYPRE_HIP 
  156   hipError_t 
const err = hipGetLastError();
 
  159   GEOS_ERROR_IF( err != hipSuccess, GEOS_FMT( 
"Previous HIP errors found: {} ({} at {}:{})", msg, hipGetErrorString( err ), file, line ) );
 
  169 #define GEOS_HYPRE_CHECK_DEVICE_ERRORS( msg ) ::geos::hypre::checkDeviceErrors( msg, __FILE__, __LINE__ ) 
  172                "HYPRE_BigInt and geos::globalIndex must have the same size" );
 
  174 static_assert( std::is_signed< HYPRE_BigInt >::value == std::is_signed< geos::globalIndex >::value,
 
  175                "HYPRE_BigInt and geos::globalIndex must both be signed or unsigned" );
 
  177 static_assert( std::is_same< HYPRE_Real, geos::real64 >::value,
 
  178                "HYPRE_Real and geos::real64 must be the same type" );
 
  187   return reinterpret_cast< HYPRE_BigInt * 
>(index);
 
  197   return reinterpret_cast< HYPRE_BigInt 
const * 
>(index);
 
  240                             HYPRE_ParCSRMatrix A,
 
  258                             HYPRE_Int 
const type );
 
  269                            HYPRE_ParCSRMatrix A,
 
  282                            HYPRE_ParCSRMatrix A,
 
  301                            HYPRE_Int 
const order,
 
  302                            HYPRE_Int 
const eigNumIter );
 
  313                           HYPRE_ParCSRMatrix A,
 
  326                           HYPRE_ParCSRMatrix A,
 
  349   return findOption( typeMap, type, 
"multigrid cycle", 
"HyprePreconditioner" );
 
  370   return findOption( typeMap, type, 
"multigrid relaxation", 
"HyprePreconditioner" );
 
  394   return findOption( typeMap, type, 
"multigrid interpolation", 
"HyprePreconditioner" );
 
  416   return findOption( typeMap, type, 
"multigrid aggressive interpolation", 
"HyprePreconditioner" );
 
  431   return findOption( typeMap, type, 
"ILU", 
"HyprePreconditioner" );
 
  455   return findOption( typeMap, type, 
"multigrid coarse solver", 
"HyprePreconditioner" );
 
  474   return findOption( typeMap, type, 
"multigrid coarsening", 
"HyprePreconditioner" );
 
  494   return findOption( typeMap, type, 
"relaxation", 
"HyprePreconditioner" );
 
  509   return findOption( typeMap, type, 
"ILU", 
"HyprePreconditioner" );
 
#define GEOS_UNUSED_VAR(...)
Mark an unused variable and silence compiler warnings.
 
#define GEOS_ERROR_IF(EXP, msg)
Conditionally raise a hard error and terminate the program.
 
Base template for ordered and unordered maps.
 
HYPRE_Int getAMGInterpolationType(LinearSolverParameters::AMG::InterpType const &type)
Returns hypre's identifier of the AMG interpolation type.
 
MGRCoarseGridMethod
This enum class specifies the strategy for level coarse grid computation in MGR.
 
@ galerkin
Galerkin coarse grid computation using RAP.
 
MGRRestrictionType
This enum class specifies the strategy for computing the level restriction operator in MGR.
 
@ jacobi
Diagonal scaling.
 
@ blockColLumped
Block column-lumped approximation.
 
@ blockJacobi
Block-Jacobi.
 
@ approximateInverse
Approximate inverse.
 
@ cprLike
CPR-like restriction.
 
HYPRE_Int chebyshevSetup(HYPRE_Solver solver, HYPRE_ParCSRMatrix A, HYPRE_ParVector b, HYPRE_ParVector x)
Setup a Chebyshev smoother.
 
HYPRE_Int getAMGAggressiveInterpolationType(LinearSolverParameters::AMG::AggInterpType const &type)
Returns hypre's identifier of the AMG aggressive interpolation type.
 
HYPRE_Vector parVectorToVectorAll(HYPRE_ParVector const vec)
Gather a parallel vector on every rank.
 
HYPRE_Int getRelaxationType(LinearSolverParameters::PreconditionerType const type)
Returns hypre's identifier of the relaxation preconditioner type.
 
HYPRE_BigInt * toHypreBigInt(geos::globalIndex *const index)
Converts a non-const array from GEOS globalIndex type to HYPRE_BigInt.
 
HYPRE_Int relaxationSolve(HYPRE_Solver solver, HYPRE_ParCSRMatrix A, HYPRE_ParVector b, HYPRE_ParVector x)
Solve with a relaxation-based smoother.
 
constexpr HYPRE_MemoryLocation memoryLocation
Memory location used by hypre matrix/vector objects.
 
HYPRE_Int getILUType(LinearSolverParameters::AMG::SmootherType const type)
Returns hypre's identifier of the AMG ILU smoother type.
 
MGRFRelaxationType
This enum class specifies the F-relaxation type.
 
@ amgVCycle
Full AMG VCycle solver.
 
@ none
no F-relaxation if performed
 
@ l1forwardGaussSeidel
Gauss-Seidel, forward solve
 
@ forwardHybridGaussSeidel
hybrid Gauss-Seidel or SOR, forward solve
 
@ gsElimWInverse
Direct Inversion with Gaussian Elimination (OK for larger systems)
 
@ backwardHybridGaussSeidel
hybrid Gauss-Seidel or SOR, backward solve
 
@ hybridSymmetricGaussSeidel
hybrid symmetric Gauss-Seidel or SSOR
 
@ l1hybridSymmetricGaussSeidel
-scaled hybrid symmetric Gauss-Seidel
 
@ l1backwardGaussSeidel
Gauss-Seidel, backward solve
 
@ singleVCycleSmoother
V(1,0) cycle smoother.
 
@ gsElimWPivoting
Gaussian Elimination with pivoting direct solver (for small systems)
 
@ gsElim
Gaussian Elimination direct solver (for small systems)
 
HYPRE_Int getAMGRelaxationType(LinearSolverParameters::AMG::SmootherType const &type)
Returns hypre's identifier of the AMG smoother type.
 
HYPRE_Int dummySetup(HYPRE_Solver, HYPRE_ParCSRMatrix, HYPRE_ParVector, HYPRE_ParVector)
Dummy function that does nothing but conform to hypre's signature for preconditioner setup/apply func...
 
AMGCoarseningType
This enum class specifies the AMG parallel coarsening algorithm.
 
@ CLJP
Parallel coarsening algorithm using independent sets.
 
@ Falgout
Uses Ruge_Stueben first, followed by CLJP.
 
@ Ruge_Stueben
Classical Ruge-Stueben coarsening on each processor.
 
@ PMIS
Parallel coarsening algorithm using independent sets.
 
@ CGC_E
Coarsening by M. Griebel, B. Metsch and A. Schweitzer.
 
@ HMIS
Uses one pass Ruge-Stueben on each processor independently, followed by PMIS.
 
@ CLJPDebug
Using a fixed random vector, for debugging purposes only.
 
@ PMISDebug
Using a fixed random vector, for debugging purposes only.
 
@ CGC
Coarsening by M. Griebel, B. Metsch and A. Schweitzer.
 
HYPRE_Int relaxationSetup(HYPRE_Solver solver, HYPRE_ParCSRMatrix A, HYPRE_ParVector b, HYPRE_ParVector x)
Setup a relaxation-based smoother.
 
HYPRE_Int relaxationCreate(HYPRE_Solver &solver, HYPRE_Int const type)
Create a relaxation-based smoother.
 
constexpr HYPRE_MemoryLocation getMemoryLocation(LvArray::MemorySpace const space)
 
HYPRE_Int getAMGCoarseType(LinearSolverParameters::AMG::CoarseType const &type)
Returns hypre's identifier of the AMG coarse solver type.
 
constexpr LvArray::MemorySpace getLvArrayMemorySpace(HYPRE_MemoryLocation const location)
 
HYPRE_Int chebyshevDestroy(HYPRE_Solver solver)
Destroy a Chebyshev smoother.
 
HYPRE_Int getAMGCycleType(LinearSolverParameters::AMG::CycleType const &type)
Returns hypre's identifier of the AMG cycle type.
 
HYPRE_Vector parVectorToVector(HYPRE_ParVector const vec, int const targetRank)
Gather a parallel vector onto a single rank.
 
HYPRE_Int relaxationDestroy(HYPRE_Solver solver)
Destroy a relaxation-based smoother.
 
HYPRE_Int getAMGCoarseningType(LinearSolverParameters::AMG::CoarseningType const &type)
Returns hypre's identifier of the AMG coarsening type.
 
HYPRE_Int SuperLUDistSolve(HYPRE_Solver solver, HYPRE_ParCSRMatrix A, HYPRE_ParVector b, HYPRE_ParVector x)
The missing wrapper compatible with hypre solver solve signature.
 
HYPRE_Int SuperLUDistDestroy(HYPRE_Solver solver)
The missing wrapper compatible with hypre solver destroy signature.
 
void checkDeviceErrors(char const *msg, char const *file, int const line)
 
HYPRE_Int chebyshevSolve(HYPRE_Solver solver, HYPRE_ParCSRMatrix A, HYPRE_ParVector b, HYPRE_ParVector x)
Solve with a Chebyshev smoother.
 
HYPRE_Int chebyshevCreate(HYPRE_Solver &solver, HYPRE_Int const order, HYPRE_Int const eigNumIter)
Create a Chebyshev smoother.
 
MGRInterpolationType
This enum class specifies the strategy for computing the level intepolation operator in MGR.
 
@ jacobi
Diagonal scaling.
 
@ classicalModifiedInterpolation
Classical modified interpolation.
 
@ blockJacobi
Block-Jacobi.
 
@ approximateInverse
Approximate inverse.
 
constexpr LvArray::MemorySpace memorySpace
Memory space used by hypre matrix/vector objects.
 
MGRGlobalSmootherType
This enum class specifies the global smoother type.
 
@ none
no global smoothing is performed (default)
 
@ ilu0
incomplete LU factorization
 
@ blockJacobi
block Jacobi
 
@ blockGaussSeidel
block Jacobi
 
parallelDevicePolicy<> execPolicy
Execution policy for operations on hypre data.
 
GEOS_GLOBALINDEX_TYPE globalIndex
Global index type (for indexing objects across MPI partitions).
 
GEOS_LOCALINDEX_TYPE localIndex
Local index type (for indexing objects within an MPI partition).
 
Container for hypre preconditioner function pointers.
 
HYPRE_Int(*)(HYPRE_Solver) DestroyFunc
Alias for destroy function type.
 
HYPRE_Int(*)(HYPRE_Solver, HYPRE_ParCSRMatrix, HYPRE_ParVector, HYPRE_ParVector) SolveFunc
Alias for apply function type.
 
HYPRE_Int(*)(HYPRE_Solver, HYPRE_ParCSRMatrix, HYPRE_ParVector, HYPRE_ParVector) SetupFunc
Alias for setup function type.
 
HYPRE_Solver ptr
pointer to preconditioner
 
SetupFunc setup
pointer to setup function
 
DestroyFunc destroy
pointer to destroy function
 
SolveFunc solve
pointer to apply function
 
InterpType
AMG interpolation type (HYPRE only)
 
@ modifiedExtendedI
Modularized extended+i (GPU support)
 
@ multipass
Multipass (GPU support)
 
@ default_
Use LAI's default option.
 
@ extendedI
Extended+i (GPU support)
 
@ modifiedExtendedE
Modularized extended+e (GPU support)
 
@ modifiedExtended
Modularized extended classical (GPU support)
 
@ direct
Direct (GPU support)
 
@ directBAMG
Direct with separation of weights (GPU support)
 
@ modifiedClassical
Modified classical.
 
@ extended
Extended classical (GPU support)
 
SmootherType
AMG smoother type.
 
@ jacobi
Jacobi smoothing.
 
@ default_
Use LAI's default option.
 
@ chebyshev
Chebyshev polynomial smoothing.
 
@ iluk
Incomplete LU with k-level of fill.
 
@ l1jacobi
l1-Jacobi smoothing
 
@ l1sgs
l1-Symmetric Gauss-Seidel smoothing
 
@ ilut
Incomplete LU with thresholding.
 
@ sgs
Symmetric Gauss-Seidel smoothing.
 
@ bgs
Gauss-Seidel smoothing (backward sweep)
 
@ fgs
Gauss-Seidel smoothing (forward sweep)
 
CoarseningType
AMG coarsening types (HYPRE only)
 
@ CLJP
A parallel coarsening algorithm using independent sets.
 
@ default_
Use LAI's default option.
 
@ Falgout
Ruge-Stueben followed by CLJP.
 
@ RugeStueben
Classical Ruge-Stueben on each processor, followed by a third pass.
 
@ PMIS
Parallel coarsening as CLJP but with lower complexities (GPU support)
 
@ HMIS
Hybrid PMIS coarsening.
 
AggInterpType
AMG interpolation type for aggressive coarsening levels (HYPRE only)
 
@ modifiedExtendedI
Modularized Extended+i (GPU support)
 
@ multipass
Multipass (GPU support)
 
@ default_
Use LAI's default option.
 
@ extendedIStage2
Extended+i 2-stage (GPU support)
 
@ modifiedExtendedE
Modularized Extended+e (GPU support)
 
@ modifiedExtended
Modularized Extended (GPU support)
 
@ modifiedMultipass
Modularized Multipass (GPU support)
 
@ extendedStage2
Extended 2-stage (GPU support)
 
@ standardStage2
Standard 2-stage.
 
CoarseType
AMG coarse solver type.
 
@ jacobi
Jacobi (GPU support in hypre)
 
@ default_
Use LAI's default option.
 
@ chebyshev
Chebyshev polynomial (GPU support in hypre)
 
@ l1jacobi
l1-Jacobi (GPU support in hypre)
 
@ gsElimWInverse
Direct inverse with Gaussian Elimination.
 
@ direct
Direct solver as preconditioner.
 
@ l1sgs
l1-Symmetric Gauss-Seidel
 
@ sgs
Symmetric Gauss-Seidel.
 
@ gsElimWPivoting
Gaussian Elimination with pivoting direct solver.
 
@ bgs
Gauss-Seidel smoothing (backward sweep)
 
@ fgs
Gauss-Seidel (forward sweep)
 
PreconditionerType
Preconditioner type.
 
@ jacobi
Jacobi smoothing.
 
@ chebyshev
Chebyshev polynomial smoothing.
 
@ iluk
Incomplete LU with k-level of fill.
 
@ l1jacobi
l1-Jacobi smoothing
 
@ l1sgs
l1-Symmetric Gauss-Seidel smoothing
 
@ ilut
Incomplete LU with thresholding.
 
@ sgs
Symmetric Gauss-Seidel smoothing.
 
@ bgs
Gauss-Seidel smoothing (backward sweep)
 
@ fgs
Gauss-Seidel smoothing (forward sweep)