Skip to content

Commit

Permalink
Code changes to support artbitrary sparse matrix structure for random…
Browse files Browse the repository at this point in the history
… matrices.

* Minor edits to function for creating random sparse matrices.
* Bug fixes and updates to ellblock format to support new random sparse data.
  • Loading branch information
oseikuffuor1 committed Sep 29, 2023
1 parent 3224e05 commit 9e9e482
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 11 deletions.
9 changes: 7 additions & 2 deletions src/C-interface/csr/bml_allocate_csr_typed.c
Original file line number Diff line number Diff line change
Expand Up @@ -326,8 +326,9 @@ bml_matrix_csr_t *TYPED_FUNC(
/* mark column index position */
col_marker[col] = 1;
nnz_row++;
}
col = rand() % (N + 1);
}
/* generate random column index 0 >= col < N */
col = rand() % N;
}
/* update nnz of row */
row->NNZ_ = nnz_row;
Expand All @@ -348,6 +349,10 @@ bml_matrix_csr_t *TYPED_FUNC(
A->table_ = NULL;
}

/* free memory */
bml_free_memory(col_marker);
bml_free_memory(col_marker_pos);

return A;
}

Expand Down
3 changes: 2 additions & 1 deletion src/C-interface/ellblock/bml_allocate_ellblock_typed.c
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,8 @@ bml_matrix_ellblock_t *TYPED_FUNC(
bcol_marker[bcol] = 1;
bnnz_row++;
}
bcol = rand() % (NB + 1);
/* generate random column index 0 >= bcol < NB */
bcol = rand() % NB;
}
A_nnzb[ib] = bnnz_row;
/* reset col_marker */
Expand Down
18 changes: 11 additions & 7 deletions src/C-interface/ellblock/bml_multiply_ellblock_typed.c
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,9 @@ void TYPED_FUNC(
*
* \f$ X^{2} \leftarrow X \, X \f$
*
* Note: the matrix X2 is overwritten with the result.
* Since X2 and X may have different non-zero patterns, we need to clear X2 before overwriting.
*
* \ingroup multiply_group
*
* \param X Matrix X
Expand All @@ -252,12 +255,14 @@ void *TYPED_FUNC(
int *X_nnzb = X->nnzb;
int *bsize = X->bsize;

REAL_T traceX = 0.0;
REAL_T **X_ptr_value = (REAL_T **) X->ptr_value;

/* clear X2 and set pointers to data */
TYPED_FUNC(bml_clear_ellblock) (X2);
int *X2_indexb = X2->indexb;
int *X2_nnzb = X2->nnzb;

REAL_T traceX = 0.0;
REAL_T traceX2 = 0.0;
REAL_T **X_ptr_value = (REAL_T **) X->ptr_value;
REAL_T **X2_ptr_value = (REAL_T **) X2->ptr_value;

double *trace = bml_allocate_memory(sizeof(double) * 2);
Expand Down Expand Up @@ -411,10 +416,9 @@ void *TYPED_FUNC(
int nelements = bsize[ib] * bsize[jp];
int ind = ROWMAJOR(ib, ll, NB, MB);
assert(ind < NB * MB);
if (X2_ptr_value[ind] == NULL)
X2_ptr_value[ind] =
TYPED_FUNC(bml_allocate_block_ellblock) (X2, ib,
nelements);
/* Allocate memory to hold block */
X2_ptr_value[ind] =
TYPED_FUNC(bml_allocate_block_ellblock) (X2, ib, nelements);
REAL_T *X2_value = X2_ptr_value[ind];
assert(X2_value != NULL);
memcpy(X2_value, xtmp, nelements * sizeof(REAL_T));
Expand Down
3 changes: 2 additions & 1 deletion src/C-interface/ellpack/bml_allocate_ellpack_typed.c
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,8 @@ bml_matrix_ellpack_t *TYPED_FUNC(
col_marker[col] = 1;
nnz_row++;
}
col = rand() % (N + 1);
/* generate random column index 0 >= col < N */
col = rand() % N;
}
/* update nnz of row */
A_nnz[i] = nnz_row;
Expand Down

0 comments on commit 9e9e482

Please sign in to comment.