20 #ifndef OPM_HYPRE_CPU_TRANSFERS_HPP 21 #define OPM_HYPRE_CPU_TRANSFERS_HPP 23 #include <opm/simulators/linalg/hypreinterface/HypreDataStructures.hpp> 24 #include <opm/simulators/linalg/hypreinterface/HypreErrorHandling.hpp> 27 #include <opm/simulators/linalg/gpuistl/hypreinterface/HypreCpuTransfers.hpp> 29 #include <opm/simulators/linalg/gpuistl_hip/hypreinterface/HypreCpuTransfers.hpp> 33 #include <_hypre_utilities.h> 41 template <
typename VectorType>
44 std::vector<HYPRE_Real>& continuous_vector_values,
45 const std::vector<int>& local_hypre_to_local_dune)
48 for (
size_t i = 0; i < local_hypre_to_local_dune.size(); ++i) {
49 continuous_vector_values[i] = v[local_hypre_to_local_dune[i]][0];
56 template <
typename VectorType>
59 const std::vector<HYPRE_Real>& continuous_vector_values,
60 const std::vector<int>& local_hypre_to_local_dune)
63 for (
size_t i = 0; i < local_hypre_to_local_dune.size(); ++i) {
64 v[local_hypre_to_local_dune[i]][0] = continuous_vector_values[i];
71 template <
typename VectorType>
74 HYPRE_IJVector hypre_vec,
80 const int N =
static_cast<int>(host_arrays.
indices.size());
81 using T =
typename VectorType::field_type;
83 if (use_gpu_backend) {
84 #if HYPRE_USING_CUDA || HYPRE_USING_HIP 85 gpuistl::HypreInterface::transferCpuVectorToHypre(cpu_vec, hypre_vec, host_arrays,
86 device_arrays, par_info);
87 #endif // HYPRE_USING_CUDA || HYPRE_USING_HIP 92 const T* values = &(cpu_vec[0][0]);
94 HYPRE_IJVectorSetValues(hypre_vec, N, const_cast<HYPRE_BigInt*>(host_arrays.
indices.data()), values));
99 OPM_HYPRE_SAFE_CALL(HYPRE_IJVectorSetValues(hypre_vec,
101 const_cast<HYPRE_BigInt*>(host_arrays.
indices.data()),
106 OPM_HYPRE_SAFE_CALL(HYPRE_IJVectorAssemble(hypre_vec));
112 template <
typename VectorType>
119 bool use_gpu_backend)
121 const int N =
static_cast<int>(host_arrays.
indices.size());
122 using T =
typename VectorType::field_type;
124 if (use_gpu_backend) {
125 #if HYPRE_USING_CUDA || HYPRE_USING_HIP 126 gpuistl::HypreInterface::transferHypreToCpuVector(hypre_vec, cpu_vec, host_arrays,
127 device_arrays, par_info);
128 #endif // HYPRE_USING_CUDA || HYPRE_USING_HIP 133 T* values = &(cpu_vec[0][0]);
135 HYPRE_IJVectorGetValues(hypre_vec, N, const_cast<HYPRE_BigInt*>(host_arrays.
indices.data()), values));
138 OPM_HYPRE_SAFE_CALL(HYPRE_IJVectorGetValues(hypre_vec,
140 const_cast<HYPRE_BigInt*>(host_arrays.
indices.data()),
153 template <
typename MatrixType>
156 HYPRE_IJMatrix hypre_matrix,
160 bool use_gpu_backend)
162 const auto N = sparsity_pattern.
rows.size();
164 using T =
typename MatrixType::field_type;
165 const T* values = &(cpu_matrix[0][0][0][0]);
167 if (use_gpu_backend) {
168 #if HYPRE_USING_CUDA || HYPRE_USING_HIP 169 gpuistl::HypreInterface::updateMatrixFromCpuMatrix(cpu_matrix, hypre_matrix, sparsity_pattern, device_arrays);
172 OPM_HYPRE_SAFE_CALL(HYPRE_IJMatrixSetValues2(hypre_matrix,
174 const_cast<HYPRE_Int*>(sparsity_pattern.
ncols.data()),
175 const_cast<HYPRE_BigInt*>(sparsity_pattern.
rows.data()),
176 const_cast<HYPRE_Int*>(host_arrays.
row_indexes.data()),
177 const_cast<HYPRE_BigInt*>(sparsity_pattern.
cols.data()),
181 OPM_HYPRE_SAFE_CALL(HYPRE_IJMatrixAssemble(hypre_matrix));
186 #endif // OPM_HYPRE_CPU_TRANSFERS_HPP std::vector< HYPRE_BigInt > rows
Global row indices for owned rows (size: N_owned)
Definition: HypreDataStructures.hpp:91
Parallel domain decomposition information for HYPRE-Dune interface.
Definition: HypreDataStructures.hpp:37
void transferHypreToCpuVector(HYPRE_IJVector hypre_vec, VectorType &cpu_vec, linalg::HypreInterface::HostDataArrays &host_arrays, [[maybe_unused]] const linalg::HypreInterface::DeviceDataArrays &device_arrays, const linalg::HypreInterface::ParallelInfo &par_info, bool use_gpu_backend)
Transfer Hypre vector to CPU vector.
Definition: HypreCpuTransfers.hpp:114
std::vector< HYPRE_BigInt > cols
Global column indices in CSR format (size: nnz)
Definition: HypreDataStructures.hpp:94
Compressed Sparse Row (CSR) sparsity pattern for HYPRE matrix assembly.
Definition: HypreDataStructures.hpp:86
std::vector< int > local_hypre_to_local_dune
Mapping from local HYPRE indices to local Dune indices.
Definition: HypreDataStructures.hpp:59
std::vector< HYPRE_Int > ncols
Non-zero entries per owned row (size: N_owned)
Definition: HypreDataStructures.hpp:88
Host arrays for HYPRE matrix and vector data transfers.
Definition: HypreDataStructures.hpp:106
void updateMatrixFromCpuMatrix(const MatrixType &cpu_matrix, HYPRE_IJMatrix hypre_matrix, const linalg::HypreInterface::SparsityPattern &sparsity_pattern, const linalg::HypreInterface::HostDataArrays &host_arrays, [[maybe_unused]] const linalg::HypreInterface::DeviceDataArrays &device_arrays, bool use_gpu_backend)
Update Hypre matrix from CPU matrix Uses HYPRE_IJMatrixSetValues2 with pre-computed row_indexes...
Definition: HypreCpuTransfers.hpp:155
void setContinuousVectorForHypre(const VectorType &v, std::vector< HYPRE_Real > &continuous_vector_values, const std::vector< int > &local_hypre_to_local_dune)
Extract owned vector values in the order expected by HYPRE.
Definition: HypreCpuTransfers.hpp:43
void transferCpuVectorToHypre(const VectorType &cpu_vec, HYPRE_IJVector hypre_vec, linalg::HypreInterface::HostDataArrays &host_arrays, [[maybe_unused]] const linalg::HypreInterface::DeviceDataArrays &device_arrays, const linalg::HypreInterface::ParallelInfo &par_info, bool use_gpu_backend)
Transfer CPU vector to Hypre vector.
Definition: HypreCpuTransfers.hpp:73
void setDuneVectorFromContinuousVector(VectorType &v, const std::vector< HYPRE_Real > &continuous_vector_values, const std::vector< int > &local_hypre_to_local_dune)
Distribute HYPRE vector values back to original vector positions.
Definition: HypreCpuTransfers.hpp:58
Unified interface for Hypre operations with both CPU and GPU data structures.
Definition: HypreCpuTransfers.hpp:35
bool owner_first
Whether owned DOFs appear first in local Dune ordering.
Definition: HypreDataStructures.hpp:77
GPU device memory arrays for HYPRE operations with GPU backend.
Definition: HypreDataStructures.hpp:137
std::vector< HYPRE_Real > continuous_vector_values
Temporary buffer for vector values in non-owner-first ordering.
Definition: HypreDataStructures.hpp:128
std::vector< HYPRE_Int > row_indexes
Pre-computed row start indexes for HYPRE_IJMatrixSetValues2.
Definition: HypreDataStructures.hpp:113
std::vector< HYPRE_BigInt > indices
Global DOF indices for owned degrees of freedom.
Definition: HypreDataStructures.hpp:120