Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not write zero values for dense matrix #748

Merged
merged 1 commit into from
Dec 15, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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