From 3428d84c3dddc78c945d10016925b9f73f63566a Mon Sep 17 00:00:00 2001 From: Jan Eitzinger Date: Fri, 3 Jan 2025 21:27:36 +0100 Subject: [PATCH] Fix matrixRead routine --- src/matrix.c | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/src/matrix.c b/src/matrix.c index 2ae408a..393c5a4 100644 --- a/src/matrix.c +++ b/src/matrix.c @@ -29,6 +29,13 @@ static inline int compareRow(const void* a, const void* b) return (a_->row > b_->row) - (a_->row < b_->row); } +static void dumpMMMatrix(Entry* mm, int nz) +{ + for (int i = 0; i < nz; i++) { + printf("%d %d: %f\n", mm[i].row, mm[i].col, mm[i].val); + } +} + void matrixRead(Matrix* m, char* filename) { MM_typecode matcode; @@ -80,7 +87,7 @@ void matrixRead(Matrix* m, char* filename) exit(EXIT_FAILURE); } - printf("Read matrix %s with %d non zeroes and %d rows", filename, nz, M); + printf("Read matrix %s with %d non zeroes and %d rows\n", filename, nz, M); m->nr = M; m->nnz = nz; @@ -126,8 +133,10 @@ void matrixRead(Matrix* m, char* filename) // sort by column qsort(mm, mms, sizeof(Entry), compareColumn); + // dumpMMMatrix(mm, nz); // sort by row - qsort(mm, mms, sizeof(Entry), compareRow); + mergesort(mm, mms, sizeof(Entry), compareRow); + // dumpMMMatrix(mm, nz); m->rowPtr = (CG_UINT*)allocate(64, (m->nr + 1) * sizeof(CG_UINT)); m->colInd = (CG_UINT*)allocate(64, m->nnz * sizeof(CG_UINT)); @@ -143,7 +152,6 @@ void matrixRead(Matrix* m, char* filename) valsPerRow[mm[i].row]++; } - int* offsets = (int*)allocate(64, (m->nr + 1) * sizeof(int)); m->rowPtr[0] = 0; // convert to CRS format @@ -153,8 +161,8 @@ void matrixRead(Matrix* m, char* filename) // loop over all elements in Row for (int id = m->rowPtr[rowID]; id < m->rowPtr[rowID + 1]; id++) { - m->val[id] = (CG_UINT)mm[id].val; - m->colInd[id] = (CG_FLOAT)mm[id].col; + m->val[id] = (CG_FLOAT)mm[id].val; + m->colInd[id] = (CG_UINT)mm[id].col; } } } @@ -166,7 +174,7 @@ void matrixDump(Matrix* m) CG_UINT* colInd = m->colInd; CG_FLOAT* val = m->val; - printf("Matrix: %lld non zeroes, number of rows %lld\n", numRows, m->nnz); + printf("Matrix: %lld non zeroes, number of rows %lld\n", m->nnz, numRows); for (int rowID = 0; rowID < numRows; rowID++) { printf("Row [%d]: ", rowID);