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