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

TAY wee-beng zonexo at gmail.com
Mon Oct 1 09:36:37 CDT 2012


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/9e38ae66/attachment-0001.html>


More information about the petsc-users mailing list