20#ifndef OPM_HYPRE_MATRIX_UTILS_HPP
21#define OPM_HYPRE_MATRIX_UTILS_HPP
25#ifdef MM_MAX_LINE_LENGTH
26#undef MM_MAX_LINE_LENGTH
32#include <_hypre_utilities.h>
53inline std::vector<HYPRE_Real>
55 const std::vector<HYPRE_Int>& ncols,
56 const std::vector<HYPRE_BigInt>& rows,
57 const std::vector<HYPRE_BigInt>& cols,
58 bool use_gpu_backend =
false)
60 const auto N = rows.size();
61 std::vector<HYPRE_Real> values(cols.size());
63 if (use_gpu_backend) {
67 auto par_csr_matrix =
static_cast<HYPRE_ParCSRMatrix
>(object);
68 HYPRE_Int max_row_size = *std::max_element(ncols.begin(), ncols.end());
69 HYPRE_Complex* row_values_host = hypre_CTAlloc(HYPRE_Complex, max_row_size, HYPRE_MEMORY_HOST);
72 for (
size_t row_idx = 0; row_idx < N; ++row_idx) {
74 HYPRE_BigInt* row_cols_device;
75 HYPRE_Complex* row_values_device;
77 par_csr_matrix, rows[row_idx], &row_ncols, &row_cols_device, &row_values_device));
79 hypre_TMemcpy(row_values_host,
85 for (HYPRE_Int j = 0; j < row_ncols; ++j, ++value_idx) {
86 values[value_idx] =
static_cast<HYPRE_Real
>(row_values_host[j]);
90 par_csr_matrix, rows[row_idx], &row_ncols, &row_cols_device, &row_values_device));
92 hypre_TFree(row_values_host, HYPRE_MEMORY_HOST);
96 const_cast<HYPRE_Int*
>(ncols.data()),
97 const_cast<HYPRE_BigInt*
>(rows.data()),
98 const_cast<HYPRE_BigInt*
>(cols.data()),
#define OPM_HYPRE_SAFE_CALL(expr)
Macro to wrap Hypre function calls with error checking.
Definition: HypreErrorHandling.hpp:96
Unified interface for Hypre operations with both CPU and GPU data structures.
Definition: HypreInterface.hpp:61
std::vector< HYPRE_Real > getMatrixValues(HYPRE_IJMatrix hypre_matrix, const std::vector< HYPRE_Int > &ncols, const std::vector< HYPRE_BigInt > &rows, const std::vector< HYPRE_BigInt > &cols, bool use_gpu_backend=false)
Get matrix values from Hypre matrix.
Definition: HypreUtils.hpp:54