C/C++ How can I implement BCRS 2x2 format for sparse matrices in C++?

AI Thread Summary
The discussion centers on the challenges of implementing Block Compressed Row Storage (BCRS) for 2x2 sub-blocks in sparse matrices, particularly in C++. The user initially seeks guidance on algorithms or code for converting a standard 2-D floating-point matrix to the BCRS format and performing Matrix-Vector multiplication. After resolving the programming issues, the user notes that BCRS appears to perform worse than the standard Compressed Row Storage (CRS) format, raising questions about the expected performance differences. Responses clarify that BCRS can be slower due to the complexity of accessing specific matrix elements, emphasizing that sparse matrix storage formats primarily save space rather than time. Additional resources for understanding the algorithms are suggested, including links to older versions of relevant literature.
dinaharchery
Messages
22
Reaction score
0
Hello All,

I am trying to learn matrix compression algorithms for sparse matrices. I understand the Compressed Row Storage (CRS) format but I am having difficulty with the Block Compressed Row Storage (BCRS) format - where the size of the sub-block(s) are 2x2.

Can anyone please point me to an algorithm/code for implementing BCRS 2x2? I am looking to take a standard 2-D floating-point matrix in C++ and converting it to the BCRS 2x2 format as well as Matrix-Vector multiplication using the BCRS 2x2 format.

I know there are a lot of programs for this out there but I really would like know the algorithm myself, so that I can learn this rather than re-implement someone elses code - although at this point I will take what I can get.

Thanks.
 
Technology news on Phys.org
Well, I seemed to have figured-out the issue of programming a Matrix-Vector multiplication on sparse matrices using both Compressed Row Storage and Block Compressed Row Storage formats. I have a bigger question now though.

Regardless of the size of my sparse matrix (randomly generated values), Block Compressed Row Storage (with 2x2 sub-blocks) seems to perform worse than the standard Compressed Row Storage format. Is this something that I should expect or is something else going on? If it is to be expected, does this increase in computational time occur because of the potential for increased floating-point operations? If not, why?

Thanks again.
 
How do you define 'performance'. If you mean the computational time, then yes BCRS is worse then CRS because it is 'harder' to find a specific matrix element.

Remember: sparse matrix storage modes are SPACE-savers, not TIME-savers

Have you tried http://www.nr.com/oldverswitcher.html" , you can freely access the obsolete versions and read about the algorithm to code specific storage formats.

Also http://www.cs.utk.edu/~dongarra/etemplates/node372.html" might be helpful
 
Last edited by a moderator:
Dear Peeps I have posted a few questions about programing on this sectio of the PF forum. I want to ask you veterans how you folks learn program in assembly and about computer architecture for the x86 family. In addition to finish learning C, I am also reading the book From bits to Gates to C and Beyond. In the book, it uses the mini LC3 assembly language. I also have books on assembly programming and computer architecture. The few famous ones i have are Computer Organization and...
I have a quick questions. I am going through a book on C programming on my own. Afterwards, I plan to go through something call data structures and algorithms on my own also in C. I also need to learn C++, Matlab and for personal interest Haskell. For the two topic of data structures and algorithms, I understand there are standard ones across all programming languages. After learning it through C, what would be the biggest issue when trying to implement the same data...
Back
Top