MFEM v4.9.0
Finite element discretization library
Loading...
Searching...
No Matches
hypre_parcsr.hpp
Go to the documentation of this file.
1// Copyright (c) 2010-2025, Lawrence Livermore National Security, LLC. Produced
2// at the Lawrence Livermore National Laboratory. All Rights reserved. See files
3// LICENSE and NOTICE for details. LLNL-CODE-806117.
4//
5// This file is part of the MFEM library. For more information and source code
6// availability visit https://mfem.org.
7//
8// MFEM is free software; you can redistribute it and/or modify it under the
9// terms of the BSD-3 license. We welcome feedback and contributions, see file
10// CONTRIBUTING.md for details.
11
12#ifndef MFEM_HYPRE_PARCSR_HPP
13#define MFEM_HYPRE_PARCSR_HPP
14
15#include "../config/config.hpp"
16
17#ifdef MFEM_USE_MPI
18
20
21// hypre header files
22#include <_hypre_parcsr_mv.h>
23
24#if MFEM_HYPRE_VERSION < 30000
25#define hypre_GenerateDiagAndOffd GenerateDiagAndOffd
26#endif
27
28// Older hypre versions do not define HYPRE_BigInt and HYPRE_MPI_BIG_INT, so we
29// define them here for backward compatibility.
30#if MFEM_HYPRE_VERSION < 21600
31typedef HYPRE_Int HYPRE_BigInt;
32#define HYPRE_MPI_BIG_INT HYPRE_MPI_INT
33#endif
34
35// Define macro wrappers for hypre_TAlloc, hypre_CTAlloc and hypre_TFree:
36// mfem_hypre_TAlloc, mfem_hypre_CTAlloc, and mfem_hypre_TFree, respectively.
37// Note: these macros are used in hypre.cpp, hypre_parcsr.cpp, and perhaps
38// other locations in the future.
39#if MFEM_HYPRE_VERSION < 21400
40
41#define mfem_hypre_TAlloc(type, size) hypre_TAlloc(type, size)
42#define mfem_hypre_CTAlloc(type, size) hypre_CTAlloc(type, size)
43#define mfem_hypre_TFree(ptr) hypre_TFree(ptr)
44
45#define mfem_hypre_TAlloc_host(type, size) hypre_TAlloc(type, size)
46#define mfem_hypre_CTAlloc_host(type, size) hypre_CTAlloc(type, size)
47#define mfem_hypre_TFree_host(ptr) hypre_TFree(ptr)
48
49#else // MFEM_HYPRE_VERSION >= 21400
50
51#define mfem_hypre_TAlloc(type, size) \
52 hypre_TAlloc(type, size, mfem::GetHypreMemoryLocation())
53#define mfem_hypre_CTAlloc(type, size) \
54 hypre_CTAlloc(type, size, mfem::GetHypreMemoryLocation())
55#define mfem_hypre_TFree(ptr) hypre_TFree(ptr, mfem::GetHypreMemoryLocation())
56
57#define mfem_hypre_TAlloc_host(type, size) \
58 hypre_TAlloc(type, size, HYPRE_MEMORY_HOST)
59#define mfem_hypre_CTAlloc_host(type, size) \
60 hypre_CTAlloc(type, size, HYPRE_MEMORY_HOST)
61#define mfem_hypre_TFree_host(ptr) hypre_TFree(ptr, HYPRE_MEMORY_HOST)
62
63// Notes regarding allocation and deallocation of hypre objects in 2.14.0
64//-----------------------------------------------------------------------
65//
66// 1. hypre_CSRMatrix: i, j, data, and rownnz use HYPRE_MEMORY_SHARED while the
67// hypre_CSRMatrix structure uses HYPRE_MEMORY_HOST.
68//
69// Note: the function HYPRE_CSRMatrixCreate creates the i array using
70// HYPRE_MEMORY_HOST!
71// Note: the functions hypre_CSRMatrixAdd and hypre_CSRMatrixMultiply create
72// C_i using HYPRE_MEMORY_HOST!
73//
74// 2. hypre_Vector: data uses HYPRE_MEMORY_SHARED while the hypre_Vector
75// structure uses HYPRE_MEMORY_HOST.
76//
77// 3. hypre_ParVector: the structure hypre_ParVector uses HYPRE_MEMORY_HOST;
78// partitioning uses HYPRE_MEMORY_HOST.
79//
80// 4. hypre_ParCSRMatrix: the structure hypre_ParCSRMatrix uses
81// HYPRE_MEMORY_HOST; col_map_offd, row_starts, col_starts, rowindices,
82// rowvalues also use HYPRE_MEMORY_HOST.
83//
84// Note: the function hypre_ParCSRMatrixToCSRMatrixAll allocates matrix_i
85// using HYPRE_MEMORY_HOST!
86//
87// 5. The goal for the MFEM wrappers of hypre objects is to support only the
88// standard hypre build case, i.e. when hypre is build without device support
89// and all memory types correspond to host memory. In this case memory
90// allocated with operator new can be used by hypre but (as usual) it must
91// not be owned by hypre.
92
93#endif // #if MFEM_HYPRE_VERSION < 21400
94
95namespace mfem
96{
97
98// This module contains functions that are logically part of HYPRE, and might
99// become part of HYPRE at some point. In the meantime the module can be
100// thought of as an extension of HYPRE.
101
107
108namespace internal
109{
110
111/** Parallel essential BC elimination from the system A*X = B.
112 (Adapted from hypre_ParCSRMatrixEliminateRowsCols.) */
113void hypre_ParCSRMatrixEliminateAXB(hypre_ParCSRMatrix *A,
114 HYPRE_Int num_rowscols_to_elim,
115 HYPRE_Int *rowscols_to_elim,
116 hypre_ParVector *X,
117 hypre_ParVector *B);
118
119/** Parallel essential BC elimination from matrix A only. The eliminated
120 elements are stored in a new matrix Ae, so that (A + Ae) equals the original
121 matrix A. */
122void hypre_ParCSRMatrixEliminateAAe(hypre_ParCSRMatrix *A,
123 hypre_ParCSRMatrix **Ae,
124 HYPRE_Int num_rowscols_to_elim,
125 HYPRE_Int *rowscols_to_elim,
126 int ignore_rows = 0);
127
128/** Eliminate rows from a hypre ParCSRMatrix, setting all entries in the listed
129 rows of the matrix to zero. */
130void hypre_ParCSRMatrixEliminateRows(hypre_ParCSRMatrix *A,
131 HYPRE_Int num_rows_to_elim,
132 const HYPRE_Int *rows_to_elim);
133
134/** Split matrix 'A' into nr x nc blocks, return nr x nc pointers to
135 new parallel matrices. The array 'blocks' needs to be preallocated to hold
136 nr x nc pointers. If 'interleaved' == 0 the matrix is split into contiguous
137 blocks (AAABBBCCC) otherwise the blocks are interleaved (ABCABCABC).
138 The local number of rows of A must be divisible by nr. The local number of
139 columns of A must be divisible by nc. */
140void hypre_ParCSRMatrixSplit(hypre_ParCSRMatrix *A,
141 HYPRE_Int nr, HYPRE_Int nc,
142 hypre_ParCSRMatrix **blocks,
143 int interleaved_rows, int interleaved_cols);
144
145typedef int HYPRE_Bool;
146#define HYPRE_MPI_BOOL MPI_INT
147
148/// Computes y = alpha * |A| * x + beta * y, using entry-wise absolute values of matrix A
149void hypre_CSRMatrixAbsMatvec(hypre_CSRMatrix *A,
150 HYPRE_Real alpha,
151 HYPRE_Real *x,
152 HYPRE_Real beta,
153 HYPRE_Real *y);
154
155/// Computes y = alpha * |At| * x + beta * y, using entry-wise absolute values of the transpose of matrix A
156void hypre_CSRMatrixAbsMatvecT(hypre_CSRMatrix *A,
157 HYPRE_Real alpha,
158 HYPRE_Real *x,
159 HYPRE_Real beta,
160 HYPRE_Real *y);
161
162/// Computes y = alpha * |A| * x + beta * y, using entry-wise absolute values of matrix A
163void hypre_ParCSRMatrixAbsMatvec(hypre_ParCSRMatrix *A,
164 HYPRE_Real alpha,
165 HYPRE_Real *x,
166 HYPRE_Real beta,
167 HYPRE_Real *y);
168
169/// Computes y = alpha * |At| * x + beta * y, using entry-wise absolute values of the transpose of matrix A
170void hypre_ParCSRMatrixAbsMatvecT(hypre_ParCSRMatrix *A,
171 HYPRE_Real alpha,
172 HYPRE_Real *x,
173 HYPRE_Real beta,
174 HYPRE_Real *y);
175
176/** The "Boolean" analog of y = alpha * A * x + beta * y, where elements in the
177 sparsity pattern of the CSR matrix A are treated as "true". */
178void hypre_CSRMatrixBooleanMatvec(hypre_CSRMatrix *A,
179 HYPRE_Bool alpha,
180 HYPRE_Bool *x,
181 HYPRE_Bool beta,
182 HYPRE_Bool *y);
183
184/** The "Boolean" analog of y = alpha * A^T * x + beta * y, where elements in
185 the sparsity pattern of the CSR matrix A are treated as "true". */
186void hypre_CSRMatrixBooleanMatvecT(hypre_CSRMatrix *A,
187 HYPRE_Bool alpha,
188 HYPRE_Bool *x,
189 HYPRE_Bool beta,
190 HYPRE_Bool *y);
191
192hypre_ParCSRCommHandle *
193hypre_ParCSRCommHandleCreate_bool(HYPRE_Int job,
194 hypre_ParCSRCommPkg *comm_pkg,
195 HYPRE_Bool *send_data,
196 HYPRE_Bool *recv_data);
197
198/** The "Boolean" analog of y = alpha * A * x + beta * y, where elements in the
199 sparsity pattern of the ParCSR matrix A are treated as "true". */
200void hypre_ParCSRMatrixBooleanMatvec(hypre_ParCSRMatrix *A,
201 HYPRE_Bool alpha,
202 HYPRE_Bool *x,
203 HYPRE_Bool beta,
204 HYPRE_Bool *y);
205
206/** The "Boolean" analog of y = alpha * A^T * x + beta * y, where elements in
207 the sparsity pattern of the ParCSR matrix A are treated as "true". */
208void hypre_ParCSRMatrixBooleanMatvecT(hypre_ParCSRMatrix *A,
209 HYPRE_Bool alpha,
210 HYPRE_Bool *x,
211 HYPRE_Bool beta,
212 HYPRE_Bool *y);
213
214/** Perform the operation A += beta*B, assuming that the sparsity pattern of A
215 contains that of B. */
216HYPRE_Int
217hypre_CSRMatrixSum(hypre_CSRMatrix *A,
218 HYPRE_Complex beta,
219 hypre_CSRMatrix *B);
220
221#if MFEM_HYPRE_VERSION >= 22200
222/** Provide an overloaded function for code consistency between HYPRE API
223 versions. */
224inline hypre_CSRMatrix *hypre_CSRMatrixAdd(hypre_CSRMatrix *A,
225 hypre_CSRMatrix *B)
226{
227 return ::hypre_CSRMatrixAdd(1.0, A, 1.0, B);
228}
229#endif
230
231/** Return a new matrix containing the sum of A and B, assuming that both
232 matrices use the same row and column partitions. The col_map_offd do not
233 need to be the same, but a more efficient algorithm is used if that's the
234 case. */
235hypre_ParCSRMatrix *
236hypre_ParCSRMatrixAdd(hypre_ParCSRMatrix *A,
237 hypre_ParCSRMatrix *B);
238
239/** Perform the operation A += beta*B, assuming that both matrices use the same
240 row and column partitions and the same col_map_offd arrays, or B has an empty
241 off-diagonal block. We also assume that the sparsity pattern of A contains
242 that of B. */
243HYPRE_Int
244hypre_ParCSRMatrixSum(hypre_ParCSRMatrix *A,
245 HYPRE_Complex beta,
246 hypre_ParCSRMatrix *B);
247
248/** Initialize all entries of A with value. */
249HYPRE_Int
250hypre_CSRMatrixSetConstantValues(hypre_CSRMatrix *A,
251 HYPRE_Complex value);
252
253/** Initialize all entries of A with value. */
254HYPRE_Int
255hypre_ParCSRMatrixSetConstantValues(hypre_ParCSRMatrix *A,
256 HYPRE_Complex value);
257
258} // namespace mfem::internal
259
260} // namespace mfem
261
262#endif // MFEM_USE_MPI
263
264#endif
Class used by MFEM to store pointers to host and/or device memory.
const real_t alpha
Definition ex15.cpp:369
HYPRE_Int HYPRE_BigInt
Memory< HYPRE_Int > J
Memory< real_t > data
Memory< HYPRE_Int > I