Algorithm to matrix product MSR format

In summary, the conversation discusses the implementation of a modified sparse row matrix in C++ and the challenges in efficiently computing the product of two such matrices. The code for the matrix constructor is also provided, along with a link for further reading. The conversation ends with a clarification that the link may not work for everyone and a reminder to provide an attempt or thoughts before seeking help on a homework forum.
  • #1
drudox
2
0
Hi everybody,
I'm writing some algebra classes in C++ , Now I'm implementing the modified sparse row matrix , I wrote all most all of the class, but I didn't find the way saving computing time to perform the product of two Modified sparse row matrix .. if you don't know it you can read in the link : http://www.iue.tuwien.ac.at/phd/wagner/node83.html

by the way .. the matrix constructor is written as follow :
Code:
template <typename T>
constexpr MCSRmatrix<T>::MCSRmatrix( std::initializer_list<std::initializer_list<T>> rows)
{
      this->dim  = rows.size();
      auto _rows = *(rows.begin());

      aa_.resize(dim+1);
      ja_.resize(dim+1);

      if(dim != _rows.size())
      {
          throw std::runtime_error("Error in costructor! MCSR format require square matrix!");
      }

      itype w = 0 ;
      ja_.at(w) = dim+2 ;
      for(auto ii = rows.begin(), i=1; ii != rows.end() ; ++ii, i++)
      {
          for(auto ij = ii->begin(), j=1, elemCount = 0 ; ij != ii->end() ; ++ij, j++ )  
          {
              if(i==j)
                 aa_[i-1] = *ij ;
              else if( i != j && *ij != 0 )
              {  
                 ja_.push_back(j);
                 aa_.push_back(*ij);
                 elemCount++ ;
              }
              ja_[i] = ja_[i-1] + elemCount;          
          }
      }    
      printMCSR();
}
if you know C++ you got the way the matrix works .. if this question is not well explained please let me know !
 
Last edited:
Physics news on Phys.org
  • #4
This being a homework forum, you need to post an attempt, or at the least, some thoughts on approaches.
 

Related to Algorithm to matrix product MSR format

1. What is an algorithm to matrix product MSR format?

An algorithm to matrix product MSR format refers to the process of multiplying two matrices in the Modified Sparse Row (MSR) format, which is a storage format for sparse matrices. This format is commonly used in scientific computing, where matrices with mostly zero elements are encountered.

2. How does the MSR format differ from other matrix storage formats?

The MSR format differs from other storage formats, such as the Compressed Sparse Row (CSR) format, in that it stores the matrix in a row-wise manner rather than column-wise. This allows for more efficient operations on sparse matrices, as the non-zero elements are stored sequentially in each row.

3. What are the advantages of using the MSR format for matrix multiplication?

The MSR format has several advantages for matrix multiplication, including reduced storage requirements for sparse matrices, faster access to non-zero elements, and improved performance in parallel computing environments. It also allows for efficient matrix-vector multiplication, which is a common operation in scientific computing.

4. Are there any limitations to using the MSR format for matrix multiplication?

While the MSR format has many advantages, it does have some limitations. It is not suitable for matrices with a high density of non-zero elements, as the storage requirements may become larger than other formats. Additionally, the efficiency of the algorithm depends on the sparsity pattern of the matrix, so it may not perform as well for matrices with a non-uniform distribution of non-zero elements.

5. How can I implement an algorithm to matrix product in MSR format?

There are several existing libraries and packages that implement algorithms for matrix multiplication in MSR format, such as the SuiteSparse library and the PETSc toolkit. These libraries provide efficient and optimized implementations of the algorithm, making it easy to use in scientific computing applications. Alternatively, one can also implement the algorithm from scratch using a programming language such as C or Fortran.

Similar threads

  • Calculus and Beyond Homework Help
Replies
5
Views
10K
Replies
1
Views
3K
Back
Top