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

Symmetric example program gives a wrong solution #118

Open
joons86 opened this issue Apr 2, 2024 · 6 comments
Open

Symmetric example program gives a wrong solution #118

joons86 opened this issue Apr 2, 2024 · 6 comments

Comments

@joons86
Copy link

joons86 commented Apr 2, 2024

Hi, I'm trying to solve a problem with simple real valued symmetric matrix and rhs as below
image

I wrote my code as follows.
image

but gives a wrong answer
image

I'm sure that I made some mistake in some part in the code but cannot find a bug.
Would you please correct the code to give right solution or provide example code with row, col and value of a symmetric matrix to try?

Thank you.

@pghysels
Copy link
Owner

pghysels commented Apr 3, 2024

The matrix seems wrong.
It looks like you are either trying to specify only the lower triangular part? Or setting it as a compressed sparse column matrix?

If we for now ignore the fact that the matrix is symmetric, then it can be specified as follows:

 std::vector<integer_t> row_ptr = {0, 3, 5, 8, 11, 13};
 std::vector<integer_t> col_ind = {0, 1, 3,
                                   0, 1,
                                   2, 3, 4,
                                   0, 2, 3,
                                   2, 4};
 std::vector<scalar_t> val = {1, -1, -3,
                              -1, 5,
                              4, 6, 4,
                              -3, 6, 7,
                              4, -5};

Note that row_ptr[i] has the start index of row i in col_ind and val, and that row_ptr[N] should be equal to the total number of nonzeros (13).
See also here:
https://portal.nersc.gov/project/sparse/strumpack/v7.1.3/sparse_example_usage.html#autotoc_md7

@joons86
Copy link
Author

joons86 commented Apr 6, 2024

Thank you for your reply.

I've been using the Intel cluster sparse solver in the OneAPI MKL package for my program and used to us the complex(or real) symmetry which requires the upper triangular matrix in CSR format as an input as below and works fine.

[source code for Intel Cluster Sparse Solver]
image

[output]
image

I trying to reuse my existing code as much as possible by just replacing the corresponding functions in the STRUMPACK and Is it possible to reuse the matrix structure or should I modify the code to define full matrix?

As far as I understand, symmetric matrix option enables the users to reduce the memory usage for both input and factorization(and reordering as well).

If not, I understand that an input matrix size is not a big deal compared to the memory usage of the factorization, but would you please let me know that if the symmetric option reduce the factorization memory usage as much as half of that of the full matrix?

@pghysels
Copy link
Owner

pghysels commented Apr 6, 2024

Symmetric support was added recently, see for instance:
https://github.com/pghysels/STRUMPACK/blob/master/examples/sparse/testSymmetricPositiveDefinite.cpp
Perhaps @GitHubbeer can help

@GitHubbeer
Copy link
Contributor

I will check this in this week.

@GitHubbeer
Copy link
Contributor

  1. I tried to reproduce your case and I found that your matrix for symmetric version is as follows
    image
  2. Yes, when I was implementing the symmetric version, the upper part (i.e. F21) is not stored. However, we still have to save the whole frontal matrix (F22). But the computation should be faster because only the lower part is filled (by functions like SYRK instead of GEMM).

@joons86
Copy link
Author

joons86 commented Apr 15, 2024

I understand. Thank you both for helps.

I have another question that does the 'solve' function also allow right hand side in CSR matrix format rather than the dense matrix as an input?

If not, I suggest strongly STRUMPACK to allow to use both 1)sparse upper triangular matrix input for setting solver and 2)sparse right hand side for solving in the near future for higher functionalities to save memory usage.

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

No branches or pull requests

3 participants