Discussion:
[petsc-users] question about setting elements to a matrix
Michael Povolotskyi
2015-10-29 20:43:12 UTC
Permalink
Dear PETSc developers,
I need to set many elements into a sparse Hermitian matrix.
I'd like to do this effectively.
Your documentation says that one should use MatSetValues and set as many
elements at one call as possible. MatSetValues expects a 2D array of values.
However, my matrix elements are computed row by row. Since the matrix is
Hermitian I compute only a half of them and apply complex conjugation
for the rest.
Will the following procedure be effective:
1. Compute a part of the row that correspond to the lower part of the matrix
2. Set this part of the row to the matrix with MatSetValues
3. Apply complex conjugation and compute a part of the column that
corresponds to upper part of the matrix
4. Set this part of the column to the matrix with MatSetValues
5. move to the next row

Thank you,
Michael.
--
Michael Povolotskyi, PhD
Research Assistant Professor
Network for Computational Nanotechnology
Hall for Discover and Learning Research, Room 441
West Lafayette, IN 47907
Phone (765) 4949396
Barry Smith
2015-10-29 20:50:03 UTC
Permalink
Post by Michael Povolotskyi
Dear PETSc developers,
I need to set many elements into a sparse Hermitian matrix.
I'd like to do this effectively.
Your documentation says that one should use MatSetValues and set as many elements at one call as possible. MatSetValues expects a 2D array of values.
However, my matrix elements are computed row by row. Since the matrix is Hermitian I compute only a half of them and apply complex conjugation for the rest.
1. Compute a part of the row that correspond to the lower part of the matrix
2. Set this part of the row to the matrix with MatSetValues
3. Apply complex conjugation and compute a part of the column that corresponds to upper part of the matrix
4. Set this part of the column to the matrix with MatSetValues
5. move to the next row
This is ok. But you should also be able to us the SBAIJ matrix which only stores the upper half and then you would create the diagonal and right portion of the matrix row and set that a row at a time.

Barry
Post by Michael Povolotskyi
Thank you,
Michael.
--
Michael Povolotskyi, PhD
Research Assistant Professor
Network for Computational Nanotechnology
Hall for Discover and Learning Research, Room 441
West Lafayette, IN 47907
Phone (765) 4949396
Michael Povolotskyi
2015-10-29 20:53:47 UTC
Permalink
Post by Barry Smith
Post by Michael Povolotskyi
Dear PETSc developers,
I need to set many elements into a sparse Hermitian matrix.
I'd like to do this effectively.
Your documentation says that one should use MatSetValues and set as many elements at one call as possible. MatSetValues expects a 2D array of values.
However, my matrix elements are computed row by row. Since the matrix is Hermitian I compute only a half of them and apply complex conjugation for the rest.
1. Compute a part of the row that correspond to the lower part of the matrix
2. Set this part of the row to the matrix with MatSetValues
3. Apply complex conjugation and compute a part of the column that corresponds to upper part of the matrix
4. Set this part of the column to the matrix with MatSetValues
5. move to the next row
This is ok. But you should also be able to us the SBAIJ matrix which only stores the upper half and then you would create the diagonal and right portion of the matrix row and set that a row at a time.
Barry
Thank you.
My matrix is not blocked. Actually there are blocks, but of different size.
Do you I understand correctly that the only format for this is the
general sparse format?
Michael.
Barry Smith
2015-10-29 20:58:24 UTC
Permalink
Post by Michael Povolotskyi
Post by Barry Smith
Post by Michael Povolotskyi
Dear PETSc developers,
I need to set many elements into a sparse Hermitian matrix.
I'd like to do this effectively.
Your documentation says that one should use MatSetValues and set as many elements at one call as possible. MatSetValues expects a 2D array of values.
However, my matrix elements are computed row by row. Since the matrix is Hermitian I compute only a half of them and apply complex conjugation for the rest.
1. Compute a part of the row that correspond to the lower part of the matrix
2. Set this part of the row to the matrix with MatSetValues
3. Apply complex conjugation and compute a part of the column that corresponds to upper part of the matrix
4. Set this part of the column to the matrix with MatSetValues
5. move to the next row
This is ok. But you should also be able to us the SBAIJ matrix which only stores the upper half and then you would create the diagonal and right portion of the matrix row and set that a row at a time.
Barry
Thank you.
My matrix is not blocked. Actually there are blocks, but of different size.
Do you I understand correctly that the only format for this is the general sparse format?
Sorry for the confusion but you should us SBAIJ with a block size of 1. We just don't have a SAIJ format since that would be completely duplicative code with SBAIJ with a block size of 1.

Barry
Post by Michael Povolotskyi
Michael.
Loading...