Skip to content

feat: add sparse matrix toolchain - generator, parser, vec library#30

Open
HamzaMateen wants to merge 6 commits into
merledu:mainfrom
HamzaMateen:main
Open

feat: add sparse matrix toolchain - generator, parser, vec library#30
HamzaMateen wants to merge 6 commits into
merledu:mainfrom
HamzaMateen:main

Conversation

@HamzaMateen

Copy link
Copy Markdown

New features

Add three new tools under tools/src and tools/include:

  • vec.h/vec.c: pure C11 growable array, replaces c-vector which required C23/gnu23
  • genmat.h/genmat.c: sparse CSR matrix generator, generates directly in memory, no file I/O
  • mtx_to_csr_formatter.h/.c: Matrix Market parser, COO intermediate, handles symmetric expansion

Reasons for changes/updates

  • c-vector used typeof (magic macro) which is not valid C11, broke builds under -std=c11
  • Initial implementation of parser built row_ptr on the fly assuming sorted row order, which the MM spec does not guarantee.
  • Generator previously only wrote Matrix Market files, now produces CSR directly for use in pipeline without file IO round-trip

Fixes

Parser fix: read all entries into flat COO arrays first (order-independent), then build row_ptr via prefix sum over per-row counts, then scatter into CSR.

Symmetric expansion: O(nnz) mirror pass, not O(L^2).

Tested

  • ash85.mtx: 85x85, 523 nnz after symmetric expansion
  • SpGEMM A×B produces 1836 nnz, diagonal values match vertex degrees (correctness signal)
  • Generator: 85x85 at density=0.05, 343 nnz, fed directly into SpGEMM

@Talha-Ahmed-1

Copy link
Copy Markdown
Member

@HamzaMateen could you update it by saving the matrix to a file? It would help in input matrix analysis.

@HamzaMateen

Copy link
Copy Markdown
Author

I will do so, thanks for the review.
One thing: should I save it in Dense format, Matrix Market, or CSR?

@Talha-Ahmed-1

Copy link
Copy Markdown
Member

.mtx would be fine

I will do so, thanks for the review. One thing: should I save it in Dense format, Matrix Market, or CSR?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants