[petsc-users] Using MatSetValues to add all matrix values in 1 run

Jed Brown jedbrown at mcs.anl.gov
Mon Oct 1 09:39:02 CDT 2012


MatSetValues() inserts logically dense blocks. You are thinking of it as
inserting a bunch of arbitrary (row,col,value) but that's not how it works.
Read the man page and look at any of the examples.

On Mon, Oct 1, 2012 at 10:36 AM, TAY wee-beng <zonexo at gmail.com> wrote:

>  Hi,
>
> I'm trying to insert values into my PETSc matrix using MatSetValues.
>
> I tried using:
>
> *do ijk=ijk_xyz_sta,ijk_xyz_end**
> **
> **    II = ijk - 1    !Fortran shift to 0-based**
> **    **
> **    call
> MatSetValues(A_semi_xyz,1,II,7,int_semi_xyz(ijk,1:7),semi_mat_xyz(ijk,1:7),INSERT_VALUES,ierr)
> **
> **
> **end do*
>
> where ijk_xyz_sta/ijk_xyz_end are the starting/end index
>
> int_semi_xyz(ijk,1:7) stores the 7 column global indices
>
> semi_mat_xyz has the corresponding values.
>
> This work well but I'm trying to call MatSetValues in 1 statement, it
> failed. I tried:
>
> *do ijk = 1,ijk_xyz_end-ijk_xyz_sta**
> **
> **    rows(ijk) = ijk_xyz_sta + ijk - 1**    !to get row's global indices
> **    **
> **end do**
> **
> **call
> MatSetValues(A_semi_xyz,ijk_xyz_end-ijk_xyz_sta,rows,7,int_semi_xyz(ijk_xyz_sta+1:ijk_xyz_end,1:7),semi_mat_xyz(ijk_xyz_sta+1:ijk_xyz_end,1:7),INSERT_VALUES,ierr)
> *
>
> but when I use MatView, the values are in the wrong locations.
>
> May I know what's wrong?
>
> Thanks
>
> --
> Yours sincerely,
>
> TAY wee-beng
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20121001/6c8c092b/attachment.html>


More information about the petsc-users mailing list