[petsc-users] Symmetric matrix: Setting entries below diagonal
Barry Smith
bsmith at mcs.anl.gov
Fri Apr 7 11:27:35 CDT 2017
If you want to set all values in the matrix and have the SBAIJ matrix ignore those below the diagonal you can
use
MatSetOption(mat,MAT_IGNORE_LOWER_TRIANGULAR,PETSC_TRUE);
or the options database -mat_ignore_lower_triangular
This is useful when you have a symmetric matrix but you want to switch between using AIJ and SBAIJ format without changing anything in the code.
Barry
> On Apr 7, 2017, at 10:19 AM, Barry Smith <bsmith at mcs.anl.gov> wrote:
>
>
>> On Apr 7, 2017, at 6:40 AM, Florian Lindner <mailinglists at xgm.de> wrote:
>>
>> Hello,
>>
>> two questions about symmetric (MATSBAIJ) matrices.
>>
>> + Entries set with MatSetValue below the main diagonal are ignored. Is that by design?
>
> Yes
>
>> I rather expected setting A_ij to
>> have the same effect as setting A_ji.
>
> You need to check the relationship between i and j and swap them if needed before the call.
>
>>
>> + Has MatSetOption to MAT_SYMMETRIC and MAT_SYMMETRIC_ETERNAL any gain on MATSBAIJ matrices?
>
> No
>
>>
>> Thanks,
>> Florian
>>
>> Test programm:
>>
>>
>> #include "petscmat.h"
>> #include "petscviewer.h"
>>
>> int main(int argc, char **argv)
>> {
>> PetscInitialize(&argc, &argv, "", NULL);
>> PetscErrorCode ierr = 0;
>>
>> Mat A;
>> ierr = MatCreate(PETSC_COMM_WORLD, &A); CHKERRQ(ierr);
>> MatSetType(A, MATSBAIJ); CHKERRQ(ierr);
>> ierr = MatSetSizes(A, 4, 4, PETSC_DECIDE, PETSC_DECIDE); CHKERRQ(ierr);
>> ierr = MatSetUp(A); CHKERRQ(ierr);
>> ierr = MatSetOption(A, MAT_SYMMETRIC, PETSC_TRUE); CHKERRQ(ierr);
>> ierr = MatSetOption(A, MAT_SYMMETRY_ETERNAL, PETSC_TRUE); CHKERRQ(ierr);
>>
>> // Stored
>> ierr = MatSetValue(A, 1, 2, 21, INSERT_VALUES); CHKERRQ(ierr);
>> ierr = MatSetValue(A, 1, 1, 11, INSERT_VALUES); CHKERRQ(ierr);
>>
>> // Ignored
>> ierr = MatSetValue(A, 2, 1, 22, INSERT_VALUES); CHKERRQ(ierr);
>> ierr = MatSetValue(A, 3, 2, 32, INSERT_VALUES); CHKERRQ(ierr);
>> ierr = MatSetValue(A, 3, 1, 31, INSERT_VALUES); CHKERRQ(ierr);
>>
>> ierr = MatAssemblyBegin(A, MAT_FINAL_ASSEMBLY); CHKERRQ(ierr);
>> ierr = MatAssemblyEnd(A, MAT_FINAL_ASSEMBLY); CHKERRQ(ierr);
>>
>> PetscViewer viewer;
>> ierr = PetscViewerCreate(PETSC_COMM_WORLD, &viewer); CHKERRQ(ierr);
>> ierr = PetscViewerSetType(viewer, PETSCVIEWERASCII); CHKERRQ(ierr);
>> ierr = PetscViewerPushFormat(viewer, PETSC_VIEWER_ASCII_DENSE); CHKERRQ(ierr);
>> ierr = MatView(A, viewer); CHKERRQ(ierr);
>> ierr = PetscViewerPopFormat(viewer); CHKERRQ(ierr);
>> ierr = PetscViewerDestroy(&viewer); CHKERRQ(ierr);
>>
>> PetscFinalize();
>> return 0;
>> }
>
More information about the petsc-users
mailing list