diff --git a/src/C-interface/csr/bml_allocate_csr_typed.c b/src/C-interface/csr/bml_allocate_csr_typed.c index 055137be..fb6c8c79 100644 --- a/src/C-interface/csr/bml_allocate_csr_typed.c +++ b/src/C-interface/csr/bml_allocate_csr_typed.c @@ -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; @@ -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; } diff --git a/src/C-interface/ellblock/bml_allocate_ellblock_typed.c b/src/C-interface/ellblock/bml_allocate_ellblock_typed.c index 376bb42c..43fc3718 100644 --- a/src/C-interface/ellblock/bml_allocate_ellblock_typed.c +++ b/src/C-interface/ellblock/bml_allocate_ellblock_typed.c @@ -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 */ diff --git a/src/C-interface/ellblock/bml_multiply_ellblock_typed.c b/src/C-interface/ellblock/bml_multiply_ellblock_typed.c index 094b620e..aefab749 100644 --- a/src/C-interface/ellblock/bml_multiply_ellblock_typed.c +++ b/src/C-interface/ellblock/bml_multiply_ellblock_typed.c @@ -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 @@ -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); @@ -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)); diff --git a/src/C-interface/ellpack/bml_allocate_ellpack_typed.c b/src/C-interface/ellpack/bml_allocate_ellpack_typed.c index 4fdad064..0992f8e6 100644 --- a/src/C-interface/ellpack/bml_allocate_ellpack_typed.c +++ b/src/C-interface/ellpack/bml_allocate_ellpack_typed.c @@ -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;