Skip to content

Commit

Permalink
Do not write zero values for dense matrix (#748)
Browse files Browse the repository at this point in the history
  • Loading branch information
jeanlucf22 authored Dec 15, 2023
1 parent 4915807 commit 8953ff3
Showing 1 changed file with 22 additions and 16 deletions.
38 changes: 22 additions & 16 deletions src/C-interface/dense/bml_utilities_dense_typed.c
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ void TYPED_FUNC(
FILE *matrix_file;

int N = A->N;
int msum = N * N;
int msum = 0;

#ifdef BML_USE_MAGMA
REAL_T *A_matrix = bml_noinit_allocate_memory(N * N * sizeof(REAL_T));
Expand All @@ -164,6 +164,17 @@ void TYPED_FUNC(
"%%%%%%MatrixMarket matrix coordinate complex general\n");
#endif

// count number of non-zero elements
for (int i = 0; i < N; i++)
{
for (int j = 0; j < N; j++)
{
REAL_T value = A_matrix[ROWMAJOR(i, j, N, N)];
if (ABS(value) > 0.)
msum++;
}
}

// Write out matrix size as dense and number of non-zero elements
fprintf(matrix_file, "%d %d %d\n", N, N, msum);

Expand All @@ -172,23 +183,18 @@ void TYPED_FUNC(
{
for (int j = 0; j < N; j++)
{
#if defined(SINGLE_REAL)
fprintf(matrix_file, "%d %d %20.15g\n", i + 1, j + 1,
REAL_PART(A_matrix[ROWMAJOR(i, j, N, N)]));
#elif defined(DOUBLE_REAL)
fprintf(matrix_file, "%d %d %20.15lg\n", i + 1, j + 1,
REAL_PART(A_matrix[ROWMAJOR(i, j, N, N)]));
#elif defined(SINGLE_COMPLEX)
fprintf(matrix_file, "%d %d %20.15g %20.15g\n", i + 1, j + 1,
REAL_PART(A_matrix[ROWMAJOR(i, j, N, N)]),
IMAGINARY_PART(A_matrix[ROWMAJOR(i, j, N, N)]));
#elif defined(DOUBLE_COMPLEX)
fprintf(matrix_file, "%d %d %20.15lg %20.15lg\n", i + 1, j + 1,
REAL_PART(A_matrix[ROWMAJOR(i, j, N, N)]),
IMAGINARY_PART(A_matrix[ROWMAJOR(i, j, N, N)]));
REAL_T value = A_matrix[ROWMAJOR(i, j, N, N)];
if (ABS(value) > 0.)
{
#if defined(SINGLE_REAL) || defined(DOUBLE_REAL)
fprintf(matrix_file, "%d %d %20.15g\n", i + 1, j + 1, value);
#elif defined(SINGLE_COMPLEX) || defined(DOUBLE_COMPLEX)
fprintf(matrix_file, "%d %d %20.15g %20.15g\n", i + 1, j + 1,
REAL_PART(value), IMAGINARY_PART(value));
#else
LOG_ERROR("unknown precision\n");
LOG_ERROR("unknown precision\n");
#endif
}
}
}

Expand Down

0 comments on commit 8953ff3

Please sign in to comment.