1 /******************************************************************************
2  * Copyright 1998-2019 Lawrence Livermore National Security, LLC and other
3  * HYPRE Project Developers. See the top-level COPYRIGHT file for details.
4  *
5  * SPDX-License-Identifier: (Apache-2.0 OR MIT)
6  ******************************************************************************/
7 
8 /******************************************************************************
9  *
10  * Header info for Parallel CSR Matrix data structures
11  *
12  * Note: this matrix currently uses 0-based indexing.
13  *
14  *****************************************************************************/
15 
16 #ifndef hypre_PAR_CSR_MATRIX_HEADER
17 #define hypre_PAR_CSR_MATRIX_HEADER
18 
19 /*--------------------------------------------------------------------------
20  * Parallel CSR Matrix
21  *--------------------------------------------------------------------------*/
22 
23 #ifndef HYPRE_PAR_CSR_MATRIX_STRUCT
24 #define HYPRE_PAR_CSR_MATRIX_STRUCT
25 #endif
26 
27 typedef struct hypre_ParCSRMatrix_struct
28 {
29    MPI_Comm              comm;
30 
31    HYPRE_BigInt          global_num_rows;
32    HYPRE_BigInt          global_num_cols;
33    HYPRE_BigInt          global_num_rownnz;
34    HYPRE_BigInt          first_row_index;
35    HYPRE_BigInt          first_col_diag;
36    /* need to know entire local range in case row_starts and col_starts
37       are null  (i.e., bgl) AHB 6/05*/
38    HYPRE_BigInt          last_row_index;
39    HYPRE_BigInt          last_col_diag;
40 
41    hypre_CSRMatrix      *diag;
42    hypre_CSRMatrix      *offd;
43    hypre_CSRMatrix      *diagT, *offdT;
44    /* JSP: transposed matrices are created lazily and optional */
45    HYPRE_BigInt         *col_map_offd;
46    HYPRE_BigInt         *device_col_map_offd;
47    /* maps columns of offd to global columns */
48    HYPRE_BigInt          row_starts[2];
49    /* row_starts[0] is start of local rows
50       row_starts[1] is start of next processor's rows */
51    HYPRE_BigInt          col_starts[2];
52    /* col_starts[0] is start of local columns
53       col_starts[1] is start of next processor's columns */
54 
55    hypre_ParCSRCommPkg  *comm_pkg;
56    hypre_ParCSRCommPkg  *comm_pkgT;
57 
58    /* Does the ParCSRMatrix create/destroy `diag', `offd', `col_map_offd'? */
59    HYPRE_Int             owns_data;
60 
61    HYPRE_BigInt          num_nonzeros;
62    HYPRE_Real            d_num_nonzeros;
63 
64    /* Buffers used by GetRow to hold row currently being accessed. AJC, 4/99 */
65    HYPRE_BigInt         *rowindices;
66    HYPRE_Complex        *rowvalues;
67    HYPRE_Int             getrowactive;
68 
69    hypre_IJAssumedPart  *assumed_partition;
70    HYPRE_Int             owns_assumed_partition;
71    /* Array to store ordering of local diagonal block to relax. In particular,
72    used for triangulr matrices that are not ordered to be triangular. */
73    HYPRE_Int            *proc_ordering;
74 
75    /* Save block diagonal inverse */
76    HYPRE_Int             bdiag_size;
77    HYPRE_Complex        *bdiaginv;
78    hypre_ParCSRCommPkg  *bdiaginv_comm_pkg;
79 
80 #if defined(HYPRE_USING_CUDA) || defined(HYPRE_USING_HIP)
81    /* these two arrays are reserveed for SoC matrices on GPUs to help build interpolation */
82    HYPRE_Int            *soc_diag_j;
83    HYPRE_Int            *soc_offd_j;
84 #endif
85 
86 } hypre_ParCSRMatrix;
87 
88 /*--------------------------------------------------------------------------
89  * Accessor functions for the Parallel CSR Matrix structure
90  *--------------------------------------------------------------------------*/
91 
92 #define hypre_ParCSRMatrixComm(matrix)                   ((matrix) -> comm)
93 #define hypre_ParCSRMatrixGlobalNumRows(matrix)          ((matrix) -> global_num_rows)
94 #define hypre_ParCSRMatrixGlobalNumCols(matrix)          ((matrix) -> global_num_cols)
95 #define hypre_ParCSRMatrixGlobalNumRownnz(matrix)        ((matrix) -> global_num_rownnz)
96 #define hypre_ParCSRMatrixFirstRowIndex(matrix)          ((matrix) -> first_row_index)
97 #define hypre_ParCSRMatrixFirstColDiag(matrix)           ((matrix) -> first_col_diag)
98 #define hypre_ParCSRMatrixLastRowIndex(matrix)           ((matrix) -> last_row_index)
99 #define hypre_ParCSRMatrixLastColDiag(matrix)            ((matrix) -> last_col_diag)
100 #define hypre_ParCSRMatrixDiag(matrix)                   ((matrix) -> diag)
101 #define hypre_ParCSRMatrixOffd(matrix)                   ((matrix) -> offd)
102 #define hypre_ParCSRMatrixDiagT(matrix)                  ((matrix) -> diagT)
103 #define hypre_ParCSRMatrixOffdT(matrix)                  ((matrix) -> offdT)
104 #define hypre_ParCSRMatrixColMapOffd(matrix)             ((matrix) -> col_map_offd)
105 #define hypre_ParCSRMatrixDeviceColMapOffd(matrix)       ((matrix) -> device_col_map_offd)
106 #define hypre_ParCSRMatrixRowStarts(matrix)              ((matrix) -> row_starts)
107 #define hypre_ParCSRMatrixColStarts(matrix)              ((matrix) -> col_starts)
108 #define hypre_ParCSRMatrixCommPkg(matrix)                ((matrix) -> comm_pkg)
109 #define hypre_ParCSRMatrixCommPkgT(matrix)               ((matrix) -> comm_pkgT)
110 #define hypre_ParCSRMatrixOwnsData(matrix)               ((matrix) -> owns_data)
111 #define hypre_ParCSRMatrixNumNonzeros(matrix)            ((matrix) -> num_nonzeros)
112 #define hypre_ParCSRMatrixDNumNonzeros(matrix)           ((matrix) -> d_num_nonzeros)
113 #define hypre_ParCSRMatrixRowindices(matrix)             ((matrix) -> rowindices)
114 #define hypre_ParCSRMatrixRowvalues(matrix)              ((matrix) -> rowvalues)
115 #define hypre_ParCSRMatrixGetrowactive(matrix)           ((matrix) -> getrowactive)
116 #define hypre_ParCSRMatrixAssumedPartition(matrix)       ((matrix) -> assumed_partition)
117 #define hypre_ParCSRMatrixOwnsAssumedPartition(matrix)   ((matrix) -> owns_assumed_partition)
118 #define hypre_ParCSRMatrixProcOrdering(matrix)           ((matrix) -> proc_ordering)
119 #if defined(HYPRE_USING_CUDA) || defined(HYPRE_USING_HIP)
120 #define hypre_ParCSRMatrixSocDiagJ(matrix)               ((matrix) -> soc_diag_j)
121 #define hypre_ParCSRMatrixSocOffdJ(matrix)               ((matrix) -> soc_offd_j)
122 #endif
123 
124 #define hypre_ParCSRMatrixNumRows(matrix) hypre_CSRMatrixNumRows(hypre_ParCSRMatrixDiag(matrix))
125 #define hypre_ParCSRMatrixNumCols(matrix) hypre_CSRMatrixNumCols(hypre_ParCSRMatrixDiag(matrix))
126 
127 static inline HYPRE_MemoryLocation
hypre_ParCSRMatrixMemoryLocation(hypre_ParCSRMatrix * matrix)128 hypre_ParCSRMatrixMemoryLocation(hypre_ParCSRMatrix *matrix)
129 {
130    HYPRE_MemoryLocation memory_diag = hypre_CSRMatrixMemoryLocation(hypre_ParCSRMatrixDiag(matrix));
131    HYPRE_MemoryLocation memory_offd = hypre_CSRMatrixMemoryLocation(hypre_ParCSRMatrixOffd(matrix));
132 
133    if (memory_diag != memory_offd)
134    {
135       hypre_printf("Warning: ParCSRMatrix Memory Location Diag (%d) != Offd (%d)\n", memory_diag, memory_offd);
136       hypre_assert(0);
137    }
138    return memory_diag;
139 }
140 
141 /*--------------------------------------------------------------------------
142  * Parallel CSR Boolean Matrix
143  *--------------------------------------------------------------------------*/
144 
145 typedef struct
146 {
147    MPI_Comm                comm;
148    HYPRE_BigInt            global_num_rows;
149    HYPRE_BigInt            global_num_cols;
150    HYPRE_BigInt            first_row_index;
151    HYPRE_BigInt            first_col_diag;
152    HYPRE_BigInt            last_row_index;
153    HYPRE_BigInt            last_col_diag;
154    hypre_CSRBooleanMatrix *diag;
155    hypre_CSRBooleanMatrix *offd;
156    HYPRE_BigInt           *col_map_offd;
157    HYPRE_BigInt           *row_starts;
158    HYPRE_BigInt           *col_starts;
159    hypre_ParCSRCommPkg    *comm_pkg;
160    hypre_ParCSRCommPkg    *comm_pkgT;
161    HYPRE_Int               owns_data;
162    HYPRE_Int               owns_row_starts;
163    HYPRE_Int               owns_col_starts;
164    HYPRE_BigInt            num_nonzeros;
165    HYPRE_BigInt           *rowindices;
166    HYPRE_Int               getrowactive;
167 
168 } hypre_ParCSRBooleanMatrix;
169 
170 /*--------------------------------------------------------------------------
171  * Accessor functions for the Parallel CSR Boolean Matrix structure
172  *--------------------------------------------------------------------------*/
173 
174 #define hypre_ParCSRBooleanMatrix_Get_Comm(matrix)          ((matrix)->comm)
175 #define hypre_ParCSRBooleanMatrix_Get_GlobalNRows(matrix)   ((matrix)->global_num_rows)
176 #define hypre_ParCSRBooleanMatrix_Get_GlobalNCols(matrix)   ((matrix)->global_num_cols)
177 #define hypre_ParCSRBooleanMatrix_Get_StartRow(matrix)      ((matrix)->first_row_index)
178 #define hypre_ParCSRBooleanMatrix_Get_FirstRowIndex(matrix) ((matrix)->first_row_index)
179 #define hypre_ParCSRBooleanMatrix_Get_FirstColDiag(matrix)  ((matrix)->first_col_diag)
180 #define hypre_ParCSRBooleanMatrix_Get_LastRowIndex(matrix)  ((matrix)->last_row_index)
181 #define hypre_ParCSRBooleanMatrix_Get_LastColDiag(matrix)   ((matrix)->last_col_diag)
182 #define hypre_ParCSRBooleanMatrix_Get_Diag(matrix)          ((matrix)->diag)
183 #define hypre_ParCSRBooleanMatrix_Get_Offd(matrix)          ((matrix)->offd)
184 #define hypre_ParCSRBooleanMatrix_Get_ColMapOffd(matrix)    ((matrix)->col_map_offd)
185 #define hypre_ParCSRBooleanMatrix_Get_RowStarts(matrix)     ((matrix)->row_starts)
186 #define hypre_ParCSRBooleanMatrix_Get_ColStarts(matrix)     ((matrix)->col_starts)
187 #define hypre_ParCSRBooleanMatrix_Get_CommPkg(matrix)       ((matrix)->comm_pkg)
188 #define hypre_ParCSRBooleanMatrix_Get_CommPkgT(matrix)      ((matrix)->comm_pkgT)
189 #define hypre_ParCSRBooleanMatrix_Get_OwnsData(matrix)      ((matrix)->owns_data)
190 #define hypre_ParCSRBooleanMatrix_Get_OwnsRowStarts(matrix) ((matrix)->owns_row_starts)
191 #define hypre_ParCSRBooleanMatrix_Get_OwnsColStarts(matrix) ((matrix)->owns_col_starts)
192 #define hypre_ParCSRBooleanMatrix_Get_NRows(matrix)         ((matrix->diag->num_rows))
193 #define hypre_ParCSRBooleanMatrix_Get_NCols(matrix)         ((matrix->diag->num_cols))
194 #define hypre_ParCSRBooleanMatrix_Get_NNZ(matrix)           ((matrix)->num_nonzeros)
195 #define hypre_ParCSRBooleanMatrix_Get_Rowindices(matrix)    ((matrix)->rowindices)
196 #define hypre_ParCSRBooleanMatrix_Get_Getrowactive(matrix)  ((matrix)->getrowactive)
197 
198 #endif
199