| 1 | /*BHEADER**********************************************************************
|
|---|
| 2 | * Copyright (c) 2008, Lawrence Livermore National Security, LLC.
|
|---|
| 3 | * Produced at the Lawrence Livermore National Laboratory.
|
|---|
| 4 | * This file is part of HYPRE. See file COPYRIGHT for details.
|
|---|
| 5 | *
|
|---|
| 6 | * HYPRE is free software; you can redistribute it and/or modify it under the
|
|---|
| 7 | * terms of the GNU Lesser General Public License (as published by the Free
|
|---|
| 8 | * Software Foundation) version 2.1 dated February 1999.
|
|---|
| 9 | *
|
|---|
| 10 | * $Revision: 2.4 $
|
|---|
| 11 | ***********************************************************************EHEADER*/
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 | #ifndef HYPRE_IJ_MV_HEADER
|
|---|
| 17 | #define HYPRE_IJ_MV_HEADER
|
|---|
| 18 |
|
|---|
| 19 | #include "HYPRE_utilities.h"
|
|---|
| 20 |
|
|---|
| 21 | #ifdef __cplusplus
|
|---|
| 22 | extern "C" {
|
|---|
| 23 | #endif
|
|---|
| 24 |
|
|---|
| 25 | /*--------------------------------------------------------------------------
|
|---|
| 26 | *--------------------------------------------------------------------------*/
|
|---|
| 27 |
|
|---|
| 28 | /**
|
|---|
| 29 | * @name IJ System Interface
|
|---|
| 30 | *
|
|---|
| 31 | * This interface represents a linear-algebraic conceptual view of a
|
|---|
| 32 | * linear system. The 'I' and 'J' in the name are meant to be
|
|---|
| 33 | * mnemonic for the traditional matrix notation A(I,J).
|
|---|
| 34 | *
|
|---|
| 35 | * @memo A linear-algebraic conceptual interface
|
|---|
| 36 | **/
|
|---|
| 37 | /*@{*/
|
|---|
| 38 |
|
|---|
| 39 | /*--------------------------------------------------------------------------
|
|---|
| 40 | *--------------------------------------------------------------------------*/
|
|---|
| 41 |
|
|---|
| 42 | /**
|
|---|
| 43 | * @name IJ Matrices
|
|---|
| 44 | **/
|
|---|
| 45 | /*@{*/
|
|---|
| 46 |
|
|---|
| 47 | struct hypre_IJMatrix_struct;
|
|---|
| 48 | /**
|
|---|
| 49 | * The matrix object.
|
|---|
| 50 | **/
|
|---|
| 51 | typedef struct hypre_IJMatrix_struct *HYPRE_IJMatrix;
|
|---|
| 52 |
|
|---|
| 53 | /**
|
|---|
| 54 | * Create a matrix object. Each process owns some unique consecutive
|
|---|
| 55 | * range of rows, indicated by the global row indices {\tt ilower} and
|
|---|
| 56 | * {\tt iupper}. The row data is required to be such that the value
|
|---|
| 57 | * of {\tt ilower} on any process $p$ be exactly one more than the
|
|---|
| 58 | * value of {\tt iupper} on process $p-1$. Note that the first row of
|
|---|
| 59 | * the global matrix may start with any integer value. In particular,
|
|---|
| 60 | * one may use zero- or one-based indexing.
|
|---|
| 61 | *
|
|---|
| 62 | * For square matrices, {\tt jlower} and {\tt jupper} typically should
|
|---|
| 63 | * match {\tt ilower} and {\tt iupper}, respectively. For rectangular
|
|---|
| 64 | * matrices, {\tt jlower} and {\tt jupper} should define a
|
|---|
| 65 | * partitioning of the columns. This partitioning must be used for
|
|---|
| 66 | * any vector $v$ that will be used in matrix-vector products with the
|
|---|
| 67 | * rectangular matrix. The matrix data structure may use {\tt jlower}
|
|---|
| 68 | * and {\tt jupper} to store the diagonal blocks (rectangular in
|
|---|
| 69 | * general) of the matrix separately from the rest of the matrix.
|
|---|
| 70 | *
|
|---|
| 71 | * Collective.
|
|---|
| 72 | **/
|
|---|
| 73 | int HYPRE_IJMatrixCreate(MPI_Comm comm,
|
|---|
| 74 | HYPRE_BigInt ilower,
|
|---|
| 75 | HYPRE_BigInt iupper,
|
|---|
| 76 | HYPRE_BigInt jlower,
|
|---|
| 77 | HYPRE_BigInt jupper,
|
|---|
| 78 | HYPRE_IJMatrix *matrix);
|
|---|
| 79 |
|
|---|
| 80 | /**
|
|---|
| 81 | * Destroy a matrix object. An object should be explicitly destroyed
|
|---|
| 82 | * using this destructor when the user's code no longer needs direct
|
|---|
| 83 | * access to it. Once destroyed, the object must not be referenced
|
|---|
| 84 | * again. Note that the object may not be deallocated at the
|
|---|
| 85 | * completion of this call, since there may be internal package
|
|---|
| 86 | * references to the object. The object will then be destroyed when
|
|---|
| 87 | * all internal reference counts go to zero.
|
|---|
| 88 | **/
|
|---|
| 89 | int HYPRE_IJMatrixDestroy(HYPRE_IJMatrix matrix);
|
|---|
| 90 |
|
|---|
| 91 | /**
|
|---|
| 92 | * Prepare a matrix object for setting coefficient values. This
|
|---|
| 93 | * routine will also re-initialize an already assembled matrix,
|
|---|
| 94 | * allowing users to modify coefficient values.
|
|---|
| 95 | **/
|
|---|
| 96 | int HYPRE_IJMatrixInitialize(HYPRE_IJMatrix matrix);
|
|---|
| 97 |
|
|---|
| 98 | /**
|
|---|
| 99 | * Sets values for {\tt nrows} rows or partial rows of the matrix.
|
|---|
| 100 | * The arrays {\tt ncols}
|
|---|
| 101 | * and {\tt rows} are of dimension {\tt nrows} and contain the number
|
|---|
| 102 | * of columns in each row and the row indices, respectively. The
|
|---|
| 103 | * array {\tt cols} contains the column indices for each of the {\tt
|
|---|
| 104 | * rows}, and is ordered by rows. The data in the {\tt values} array
|
|---|
| 105 | * corresponds directly to the column entries in {\tt cols}. Erases
|
|---|
| 106 | * any previous values at the specified locations and replaces them
|
|---|
| 107 | * with new ones, or, if there was no value there before, inserts a
|
|---|
| 108 | * new one.
|
|---|
| 109 | *
|
|---|
| 110 | * Not collective.
|
|---|
| 111 | **/
|
|---|
| 112 | int HYPRE_IJMatrixSetValues(HYPRE_IJMatrix matrix,
|
|---|
| 113 | int nrows,
|
|---|
| 114 | int *ncols,
|
|---|
| 115 | const HYPRE_BigInt *rows,
|
|---|
| 116 | const HYPRE_BigInt *cols,
|
|---|
| 117 | const double *values);
|
|---|
| 118 |
|
|---|
| 119 | /**
|
|---|
| 120 | * Adds to values for {\tt nrows} rows or partial rows of the matrix.
|
|---|
| 121 | * Usage details are
|
|---|
| 122 | * analogous to \Ref{HYPRE_IJMatrixSetValues}. Adds to any previous
|
|---|
| 123 | * values at the specified locations, or, if there was no value there
|
|---|
| 124 | * before, inserts a new one.
|
|---|
| 125 | *
|
|---|
| 126 | * Not collective.
|
|---|
| 127 | **/
|
|---|
| 128 | int HYPRE_IJMatrixAddToValues(HYPRE_IJMatrix matrix,
|
|---|
| 129 | int nrows,
|
|---|
| 130 | int *ncols,
|
|---|
| 131 | const HYPRE_BigInt *rows,
|
|---|
| 132 | const HYPRE_BigInt *cols,
|
|---|
| 133 | const double *values);
|
|---|
| 134 |
|
|---|
| 135 | /**
|
|---|
| 136 | * Finalize the construction of the matrix before using.
|
|---|
| 137 | **/
|
|---|
| 138 | int HYPRE_IJMatrixAssemble(HYPRE_IJMatrix matrix);
|
|---|
| 139 |
|
|---|
| 140 | /**
|
|---|
| 141 | * Gets number of nonzeros elements for {\tt nrows} rows specified in {\tt rows}
|
|---|
| 142 | * and returns them in {\tt ncols}, which needs to be allocated by the
|
|---|
| 143 | * user.
|
|---|
| 144 | **/
|
|---|
| 145 | int HYPRE_IJMatrixGetRowCounts(HYPRE_IJMatrix matrix,
|
|---|
| 146 | int nrows,
|
|---|
| 147 | HYPRE_BigInt *rows,
|
|---|
| 148 | int *ncols);
|
|---|
| 149 |
|
|---|
| 150 | /**
|
|---|
| 151 | * Gets values for {\tt nrows} rows or partial rows of the matrix.
|
|---|
| 152 | * Usage details are
|
|---|
| 153 | * analogous to \Ref{HYPRE_IJMatrixSetValues}.
|
|---|
| 154 | **/
|
|---|
| 155 | int HYPRE_IJMatrixGetValues(HYPRE_IJMatrix matrix,
|
|---|
| 156 | int nrows,
|
|---|
| 157 | int *ncols,
|
|---|
| 158 | HYPRE_BigInt *rows,
|
|---|
| 159 | HYPRE_BigInt *cols,
|
|---|
| 160 | double *values);
|
|---|
| 161 |
|
|---|
| 162 | /**
|
|---|
| 163 | * Set the storage type of the matrix object to be constructed.
|
|---|
| 164 | * Currently, {\tt type} can only be {\tt HYPRE\_PARCSR}.
|
|---|
| 165 | *
|
|---|
| 166 | * Not collective, but must be the same on all processes.
|
|---|
| 167 | *
|
|---|
| 168 | * @see HYPRE_IJMatrixGetObject
|
|---|
| 169 | **/
|
|---|
| 170 | int HYPRE_IJMatrixSetObjectType(HYPRE_IJMatrix matrix,
|
|---|
| 171 | int type);
|
|---|
| 172 |
|
|---|
| 173 | /**
|
|---|
| 174 | * Get the storage type of the constructed matrix object.
|
|---|
| 175 | **/
|
|---|
| 176 | int HYPRE_IJMatrixGetObjectType(HYPRE_IJMatrix matrix,
|
|---|
| 177 | int *type);
|
|---|
| 178 |
|
|---|
| 179 | /**
|
|---|
| 180 | * Gets range of rows owned by this processor and range
|
|---|
| 181 | * of column partitioning for this processor.
|
|---|
| 182 | **/
|
|---|
| 183 | int HYPRE_IJMatrixGetLocalRange(HYPRE_IJMatrix matrix,
|
|---|
| 184 | HYPRE_BigInt *ilower,
|
|---|
| 185 | HYPRE_BigInt *iupper,
|
|---|
| 186 | HYPRE_BigInt *jlower,
|
|---|
| 187 | HYPRE_BigInt *jupper);
|
|---|
| 188 |
|
|---|
| 189 | /**
|
|---|
| 190 | * Get a reference to the constructed matrix object.
|
|---|
| 191 | *
|
|---|
| 192 | * @see HYPRE_IJMatrixSetObjectType
|
|---|
| 193 | **/
|
|---|
| 194 | int HYPRE_IJMatrixGetObject(HYPRE_IJMatrix matrix,
|
|---|
| 195 | void **object);
|
|---|
| 196 |
|
|---|
| 197 | /**
|
|---|
| 198 | * (Optional) Set the max number of nonzeros to expect in each row.
|
|---|
| 199 | * The array {\tt sizes} contains estimated sizes for each row on this
|
|---|
| 200 | * process. This call can significantly improve the efficiency of
|
|---|
| 201 | * matrix construction, and should always be utilized if possible.
|
|---|
| 202 | *
|
|---|
| 203 | * Not collective.
|
|---|
| 204 | **/
|
|---|
| 205 | int HYPRE_IJMatrixSetRowSizes(HYPRE_IJMatrix matrix,
|
|---|
| 206 | const int *sizes);
|
|---|
| 207 |
|
|---|
| 208 | /**
|
|---|
| 209 | * (Optional) Set the max number of nonzeros to expect in each row of
|
|---|
| 210 | * the diagonal and off-diagonal blocks. The diagonal block is the
|
|---|
| 211 | * submatrix whose column numbers correspond to rows owned by this
|
|---|
| 212 | * process, and the off-diagonal block is everything else. The arrays
|
|---|
| 213 | * {\tt diag\_sizes} and {\tt offdiag\_sizes} contain estimated sizes
|
|---|
| 214 | * for each row of the diagonal and off-diagonal blocks, respectively.
|
|---|
| 215 | * This routine can significantly improve the efficiency of matrix
|
|---|
| 216 | * construction, and should always be utilized if possible.
|
|---|
| 217 | *
|
|---|
| 218 | * Not collective.
|
|---|
| 219 | **/
|
|---|
| 220 | int HYPRE_IJMatrixSetDiagOffdSizes(HYPRE_IJMatrix matrix,
|
|---|
| 221 | const int *diag_sizes,
|
|---|
| 222 | const int *offdiag_sizes);
|
|---|
| 223 |
|
|---|
| 224 | /**
|
|---|
| 225 | * (Optional) Sets the maximum number of elements that are expected to be set
|
|---|
| 226 | * (or added) on other processors from this processor
|
|---|
| 227 | * This routine can significantly improve the efficiency of matrix
|
|---|
| 228 | * construction, and should always be utilized if possible.
|
|---|
| 229 | *
|
|---|
| 230 | * Not collective.
|
|---|
| 231 | **/
|
|---|
| 232 | int HYPRE_IJMatrixSetMaxOffProcElmts(HYPRE_IJMatrix matrix,
|
|---|
| 233 | int max_off_proc_elmts);
|
|---|
| 234 |
|
|---|
| 235 | /**
|
|---|
| 236 | * Read the matrix from file. This is mainly for debugging purposes.
|
|---|
| 237 | **/
|
|---|
| 238 | int HYPRE_IJMatrixRead(const char *filename,
|
|---|
| 239 | MPI_Comm comm,
|
|---|
| 240 | int type,
|
|---|
| 241 | HYPRE_IJMatrix *matrix);
|
|---|
| 242 |
|
|---|
| 243 | /**
|
|---|
| 244 | * Print the matrix to file. This is mainly for debugging purposes.
|
|---|
| 245 | **/
|
|---|
| 246 | int HYPRE_IJMatrixPrint(HYPRE_IJMatrix matrix,
|
|---|
| 247 | const char *filename);
|
|---|
| 248 |
|
|---|
| 249 | /*@}*/
|
|---|
| 250 |
|
|---|
| 251 | /*--------------------------------------------------------------------------
|
|---|
| 252 | *--------------------------------------------------------------------------*/
|
|---|
| 253 |
|
|---|
| 254 | /**
|
|---|
| 255 | * @name IJ Vectors
|
|---|
| 256 | **/
|
|---|
| 257 | /*@{*/
|
|---|
| 258 |
|
|---|
| 259 | struct hypre_IJVector_struct;
|
|---|
| 260 | /**
|
|---|
| 261 | * The vector object.
|
|---|
| 262 | **/
|
|---|
| 263 | typedef struct hypre_IJVector_struct *HYPRE_IJVector;
|
|---|
| 264 |
|
|---|
| 265 | /**
|
|---|
| 266 | * Create a vector object. Each process owns some unique consecutive
|
|---|
| 267 | * range of vector unknowns, indicated by the global indices {\tt
|
|---|
| 268 | * jlower} and {\tt jupper}. The data is required to be such that the
|
|---|
| 269 | * value of {\tt jlower} on any process $p$ be exactly one more than
|
|---|
| 270 | * the value of {\tt jupper} on process $p-1$. Note that the first
|
|---|
| 271 | * index of the global vector may start with any integer value. In
|
|---|
| 272 | * particular, one may use zero- or one-based indexing.
|
|---|
| 273 | *
|
|---|
| 274 | * Collective.
|
|---|
| 275 | **/
|
|---|
| 276 | int HYPRE_IJVectorCreate(MPI_Comm comm,
|
|---|
| 277 | HYPRE_BigInt jlower,
|
|---|
| 278 | HYPRE_BigInt jupper,
|
|---|
| 279 | HYPRE_IJVector *vector);
|
|---|
| 280 |
|
|---|
| 281 | /**
|
|---|
| 282 | * Destroy a vector object. An object should be explicitly destroyed
|
|---|
| 283 | * using this destructor when the user's code no longer needs direct
|
|---|
| 284 | * access to it. Once destroyed, the object must not be referenced
|
|---|
| 285 | * again. Note that the object may not be deallocated at the
|
|---|
| 286 | * completion of this call, since there may be internal package
|
|---|
| 287 | * references to the object. The object will then be destroyed when
|
|---|
| 288 | * all internal reference counts go to zero.
|
|---|
| 289 | **/
|
|---|
| 290 | int HYPRE_IJVectorDestroy(HYPRE_IJVector vector);
|
|---|
| 291 |
|
|---|
| 292 | /**
|
|---|
| 293 | * Prepare a vector object for setting coefficient values. This
|
|---|
| 294 | * routine will also re-initialize an already assembled vector,
|
|---|
| 295 | * allowing users to modify coefficient values.
|
|---|
| 296 | **/
|
|---|
| 297 | int HYPRE_IJVectorInitialize(HYPRE_IJVector vector);
|
|---|
| 298 |
|
|---|
| 299 | /**
|
|---|
| 300 | * (Optional) Sets the maximum number of elements that are expected to be set
|
|---|
| 301 | * (or added) on other processors from this processor
|
|---|
| 302 | * This routine can significantly improve the efficiency of matrix
|
|---|
| 303 | * construction, and should always be utilized if possible.
|
|---|
| 304 | *
|
|---|
| 305 | * Not collective.
|
|---|
| 306 | **/
|
|---|
| 307 | int HYPRE_IJVectorSetMaxOffProcElmts(HYPRE_IJVector vector,
|
|---|
| 308 | int max_off_proc_elmts);
|
|---|
| 309 |
|
|---|
| 310 | /**
|
|---|
| 311 | * Sets values in vector. The arrays {\tt values} and {\tt indices}
|
|---|
| 312 | * are of dimension {\tt nvalues} and contain the vector values to be
|
|---|
| 313 | * set and the corresponding global vector indices, respectively.
|
|---|
| 314 | * Erases any previous values at the specified locations and replaces
|
|---|
| 315 | * them with new ones.
|
|---|
| 316 | *
|
|---|
| 317 | * Not collective.
|
|---|
| 318 | **/
|
|---|
| 319 | int HYPRE_IJVectorSetValues(HYPRE_IJVector vector,
|
|---|
| 320 | int nvalues,
|
|---|
| 321 | const HYPRE_BigInt *indices,
|
|---|
| 322 | const double *values);
|
|---|
| 323 |
|
|---|
| 324 | /**
|
|---|
| 325 | * Adds to values in vector. Usage details are analogous to
|
|---|
| 326 | * \Ref{HYPRE_IJVectorSetValues}.
|
|---|
| 327 | *
|
|---|
| 328 | * Not collective.
|
|---|
| 329 | **/
|
|---|
| 330 | int HYPRE_IJVectorAddToValues(HYPRE_IJVector vector,
|
|---|
| 331 | int nvalues,
|
|---|
| 332 | const HYPRE_BigInt *indices,
|
|---|
| 333 | const double *values);
|
|---|
| 334 |
|
|---|
| 335 | /**
|
|---|
| 336 | * Finalize the construction of the vector before using.
|
|---|
| 337 | **/
|
|---|
| 338 | int HYPRE_IJVectorAssemble(HYPRE_IJVector vector);
|
|---|
| 339 |
|
|---|
| 340 | /**
|
|---|
| 341 | * Gets values in vector. Usage details are analogous to
|
|---|
| 342 | * \Ref{HYPRE_IJVectorSetValues}.
|
|---|
| 343 | *
|
|---|
| 344 | * Not collective.
|
|---|
| 345 | **/
|
|---|
| 346 | int HYPRE_IJVectorGetValues(HYPRE_IJVector vector,
|
|---|
| 347 | int nvalues,
|
|---|
| 348 | const HYPRE_BigInt *indices,
|
|---|
| 349 | double *values);
|
|---|
| 350 |
|
|---|
| 351 | /**
|
|---|
| 352 | * Set the storage type of the vector object to be constructed.
|
|---|
| 353 | * Currently, {\tt type} can only be {\tt HYPRE\_PARCSR}.
|
|---|
| 354 | *
|
|---|
| 355 | * Not collective, but must be the same on all processes.
|
|---|
| 356 | *
|
|---|
| 357 | * @see HYPRE_IJVectorGetObject
|
|---|
| 358 | **/
|
|---|
| 359 | int HYPRE_IJVectorSetObjectType(HYPRE_IJVector vector,
|
|---|
| 360 | int type);
|
|---|
| 361 |
|
|---|
| 362 | /**
|
|---|
| 363 | * Get the storage type of the constructed vector object.
|
|---|
| 364 | **/
|
|---|
| 365 | int HYPRE_IJVectorGetObjectType(HYPRE_IJVector vector,
|
|---|
| 366 | int *type);
|
|---|
| 367 |
|
|---|
| 368 | /**
|
|---|
| 369 | * Returns range of the part of the vector owned by this processor.
|
|---|
| 370 | **/
|
|---|
| 371 | int HYPRE_IJVectorGetLocalRange(HYPRE_IJVector vector,
|
|---|
| 372 | HYPRE_BigInt *jlower,
|
|---|
| 373 | HYPRE_BigInt *jupper);
|
|---|
| 374 |
|
|---|
| 375 | /**
|
|---|
| 376 | * Get a reference to the constructed vector object.
|
|---|
| 377 | *
|
|---|
| 378 | * @see HYPRE_IJVectorSetObjectType
|
|---|
| 379 | **/
|
|---|
| 380 | int HYPRE_IJVectorGetObject(HYPRE_IJVector vector,
|
|---|
| 381 | void **object);
|
|---|
| 382 |
|
|---|
| 383 | /**
|
|---|
| 384 | * Read the vector from file. This is mainly for debugging purposes.
|
|---|
| 385 | **/
|
|---|
| 386 | int HYPRE_IJVectorRead(const char *filename,
|
|---|
| 387 | MPI_Comm comm,
|
|---|
| 388 | int type,
|
|---|
| 389 | HYPRE_IJVector *vector);
|
|---|
| 390 |
|
|---|
| 391 | /**
|
|---|
| 392 | * Print the vector to file. This is mainly for debugging purposes.
|
|---|
| 393 | **/
|
|---|
| 394 | int HYPRE_IJVectorPrint(HYPRE_IJVector vector,
|
|---|
| 395 | const char *filename);
|
|---|
| 396 |
|
|---|
| 397 | /*@}*/
|
|---|
| 398 | /*@}*/
|
|---|
| 399 |
|
|---|
| 400 | #ifdef __cplusplus
|
|---|
| 401 | }
|
|---|
| 402 | #endif
|
|---|
| 403 |
|
|---|
| 404 | #endif
|
|---|