Add a routine for allocating a CSR matrix with known number of rows

and non-zeros.  Note that this routine is for allocation only.
  Caller must create and manage sparsity structure if this is being
  used in a global assembly process.

  This routine finds utility in MsMFEM BF construction.
This commit is contained in:
Bård Skaflestad 2010-09-30 21:37:14 +00:00
parent 1e2e18bda2
commit 284683b00d
2 changed files with 35 additions and 0 deletions

View File

@ -37,6 +37,38 @@ csrmatrix_new_count_nnz(size_t m)
}
/* Allocate CSR matrix, known nnz. Allocation only. Caller must
* build sparsity structure before using in global assembly.
*
* Returns fully allocated structure if successful and NULL otherwise. */
/* ---------------------------------------------------------------------- */
struct CSRMatrix *
csrmatrix_new_known_nnz(size_t m, size_t nnz)
/* ---------------------------------------------------------------------- */
{
struct CSRMatrix *new;
new = malloc(1 * sizeof *new);
if (new != NULL) {
new->ia = malloc((m + 1) * sizeof *new->ia);
new->ja = malloc(nnz * sizeof *new->ja);
new->sa = malloc(nnz * sizeof *new->sa);
if ((new->ia == NULL) || (new->ja == NULL) || (new->sa == NULL)) {
csrmatrix_delete(new);
new = NULL;
} else {
new->m = m;
new->n = 0;
new->nnz = nnz;
}
}
return new;
}
/* ---------------------------------------------------------------------- */
size_t
csrmatrix_new_elms_pushback(struct CSRMatrix *A)

View File

@ -35,6 +35,9 @@ struct CSRMatrix
struct CSRMatrix *
csrmatrix_new_count_nnz(size_t m);
struct CSRMatrix *
csrmatrix_new_known_nnz(size_t m, size_t nnz);
size_t
csrmatrix_new_elms_pushback(struct CSRMatrix *A);