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