20#ifndef OPM_HYPRE_SETUP_HPP
21#define OPM_HYPRE_SETUP_HPP
23#include <opm/simulators/linalg/PropertyTree.hpp>
24#include <opm/simulators/linalg/gpuistl/detail/gpu_type_detection.hpp>
25#include <opm/simulators/linalg/gpuistl/hypreinterface/HypreDataStructures.hpp>
26#include <opm/simulators/linalg/gpuistl/hypreinterface/HypreErrorHandling.hpp>
28#include <dune/istl/owneroverlapcopy.hh>
29#include <dune/istl/paamg/graph.hh>
30#include <dune/istl/paamg/pinfo.hh>
31#include <dune/istl/repartition.hh>
35#include <opm/simulators/linalg/gpuistl_hip/GpuSparseMatrixWrapper.hpp>
37#include <opm/simulators/linalg/gpuistl/GpuSparseMatrixWrapper.hpp>
42#include <HYPRE_parcsr_ls.h>
43#include <_hypre_utilities.h>
60 const std::vector<int>& local_dune_to_local_hypre);
66template <
typename CommType,
typename MatrixType>
69template <
typename MatrixType>
73template <
typename MatrixType>
74std::vector<HYPRE_Int> computeRowIndexesWithMappingCpu(
const MatrixType& matrix,
75 const std::vector<HYPRE_Int>& ncols,
76 const std::vector<int>& local_dune_to_local_hypre,
79template <
typename MatrixType>
80std::vector<HYPRE_Int> computeRowIndexesWithMappingCpu(
const MatrixType& matrix,
81 const std::vector<int>& local_dune_to_local_hypre);
92#if HYPRE_USING_CUDA || HYPRE_USING_HIP
168template <
typename CommType>
174 if constexpr (std::is_same_v<CommType, Dune::Amg::SequentialInformation>) {
195template <
typename CommType>
201 if constexpr (std::is_same_v<CommType, Dune::Amg::SequentialInformation>) {
261template <
typename CommType,
typename MatrixType>
265 if constexpr (std::is_same_v<CommType, Dune::Amg::SequentialInformation>) {
361template <
typename CommType,
typename MatrixType>
373 if (!(matrix.N() == comm.indexSet().size())) {
377 Dune::Amg::MatrixGraph<MatrixType>
graph(
const_cast<MatrixType&
>(matrix));
379 assert(matrix.N() == comm.indexSet().size());
385 for (
const auto&
ind : comm.indexSet()) {
387 if (
ind.local().attribute() == Dune::OwnerOverlapCopyAttributeSet::owner) {
399 bool owner_first =
true;
401 std::size_t count = 0;
463template <
typename MatrixType>
467#if HYPRE_USING_CUDA || HYPRE_USING_HIP
469 return setupSparsityPatternFromGpuMatrix(matrix,
par_info, owner_first);
485template <
typename MatrixType>
495 for (
auto row = matrix.begin();
row != matrix.end(); ++
row) {
504 pattern.nnz = matrix.nonzeroes();
513 for (
auto row = matrix.begin();
row != matrix.end(); ++
row) {
541#if HYPRE_USING_CUDA || HYPRE_USING_HIP
632template <
typename MatrixType>
633std::vector<HYPRE_Int>
635 const std::vector<HYPRE_Int>& ncols,
636 const std::vector<int>& local_dune_to_local_hypre,
641 std::vector<HYPRE_Int> row_indexes(ncols.size());
643 for (std::size_t i = 1; i < ncols.size(); ++i) {
644 row_indexes[i] = row_indexes[i - 1] + ncols[i - 1];
649#if HYPRE_USING_CUDA || HYPRE_USING_HIP
651 return computeRowIndexesWithMappingGpu(matrix, local_dune_to_local_hypre);
655 return computeRowIndexesWithMappingCpu(matrix, local_dune_to_local_hypre);
679template <
typename MatrixType>
680std::vector<HYPRE_Int>
681computeRowIndexesWithMappingCpu(
const MatrixType& matrix,
const std::vector<int>& local_dune_to_local_hypre)
683 const int N = std::count_if(
684 local_dune_to_local_hypre.begin(), local_dune_to_local_hypre.end(), [](
int val) { return val >= 0; });
685 std::vector<HYPRE_Int> row_indexes(N);
688 for (
auto row = matrix.begin();
row != matrix.end(); ++
row) {
703#if HYPRE_USING_CUDA || HYPRE_USING_HIP
716std::vector<HYPRE_Int>
719 const int N = std::count_if(
720 local_dune_to_local_hypre.begin(), local_dune_to_local_hypre.end(), [](
int val) { return val >= 0; });
721 std::vector<HYPRE_Int> row_indexes(N);
Hierarchical collection of key/value pairs.
Definition PropertyTree.hpp:39
T get(const std::string &key) const
Retrieve property value given hierarchical property key.
Definition PropertyTree.cpp:59
The GpuSparseMatrixWrapper Checks CUDA/HIP version and dispatches a version either using the old or t...
Definition GpuSparseMatrixWrapper.hpp:61
Unified interface for Hypre operations with both CPU and GPU data structures.
Definition HypreInterface.hpp:61
void destroySolver(HYPRE_Solver solver)
Destroy Hypre solver.
Definition HypreSetup.hpp:219
SparsityPattern setupSparsityPatternFromCpuMatrix(const MatrixType &matrix, const ParallelInfo &par_info, bool owner_first)
Setup sparsity pattern from CPU matrix (BCRSMatrix)
Definition HypreSetup.hpp:487
ParallelInfo setupHypreParallelInfo(const CommType &comm, const MatrixType &matrix)
Setup parallel information for Hypre (automatically detects serial/parallel)
Definition HypreSetup.hpp:263
void destroyMatrix(HYPRE_IJMatrix matrix)
Destroy Hypre matrix.
Definition HypreSetup.hpp:233
HYPRE_Solver createAMGSolver()
Create Hypre solver (BoomerAMG)
Definition HypreSetup.hpp:117
std::vector< HYPRE_Int > computeRowIndexes(const MatrixType &matrix, const std::vector< HYPRE_Int > &ncols, const std::vector< int > &local_dune_to_local_hypre, bool owner_first)
Compute row indexes for HYPRE_IJMatrixSetValues2.
Definition HypreSetup.hpp:634
HYPRE_IJMatrix createMatrix(HYPRE_Int N, HYPRE_Int dof_offset, const CommType &comm)
Create Hypre matrix.
Definition HypreSetup.hpp:170
ParallelInfo setupHypreParallelInfoParallel(const CommType &comm, const MatrixType &matrix)
Create mappings between Dune and HYPRE indexing for parallel decomposition.
Definition HypreSetup.hpp:363
SparsityPattern setupSparsityPattern(const MatrixType &matrix, const ParallelInfo &par_info, bool owner_first)
Setup sparsity pattern from matrix (automatically detects CPU/GPU type)
Definition HypreSetup.hpp:465
void initialize(bool use_gpu_backend)
Initialize the Hypre library and set memory/execution policy.
Definition HypreSetup.hpp:89
HYPRE_IJVector createVector(HYPRE_Int N, HYPRE_Int dof_offset, const CommType &comm)
Create Hypre vector.
Definition HypreSetup.hpp:197
void destroyVector(HYPRE_IJVector vector)
Destroy Hypre vector.
Definition HypreSetup.hpp:247
void setSolverParameters(HYPRE_Solver solver, const PropertyTree &prm, bool use_gpu_backend)
Set solver parameters from property tree.
Definition HypreSetup.hpp:133
ParallelInfo setupHypreParallelInfoSerial(HYPRE_Int N)
Setup parallel information for Hypre in serial case.
Definition HypreSetup.hpp:279
constexpr auto getPropValue()
get the value data member of a property
Definition propertysystem.hh:240
Parallel domain decomposition information for HYPRE-Dune interface.
Definition HypreDataStructures.hpp:37
bool owner_first
Whether owned DOFs appear first in local Dune ordering.
Definition HypreDataStructures.hpp:77
std::vector< int > local_dune_to_global_hypre
Mapping from local Dune indices to global HYPRE indices.
Definition HypreDataStructures.hpp:51
std::vector< int > local_dune_to_local_hypre
Mapping from local Dune indices to local HYPRE indices.
Definition HypreDataStructures.hpp:44
std::vector< int > local_hypre_to_local_dune
Mapping from local HYPRE indices to local Dune indices.
Definition HypreDataStructures.hpp:59
HYPRE_Int dof_offset
Global index offset for this process's owned DOFs.
Definition HypreDataStructures.hpp:69
HYPRE_Int N_owned
Number of DOFs owned by this MPI process.
Definition HypreDataStructures.hpp:62
Compressed Sparse Row (CSR) sparsity pattern for HYPRE matrix assembly.
Definition HypreDataStructures.hpp:86
HYPRE_Int nnz
Number of non-zero entries in matrix.
Definition HypreDataStructures.hpp:97
Type trait to detect if a type is a GPU type.
Definition gpu_type_detection.hpp:40