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

Jed Brown jedbrown at mcs.anl.gov
Tue Oct 2 06:07:27 CDT 2012


On Tue, Oct 2, 2012 at 5:25 AM, TAY wee-beng <zonexo at gmail.com> wrote:

>  On 1/10/2012 4:39 PM, Jed Brown wrote:
>
> 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.
>
>
> If that's the case, is the 1st method I used the best way to insert the
> matrix?
>

Yes, inserting one row at a time is typical.


>
> In other words, I already have the A matrix and b vector in Fortran
> matrix, used for solving Ax = b.
>
> Is there a better or more efficient way of inserting the Fortran matrix
> into PETSC's matrix?
>
> Thanks
>
>
>  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/20121002/fc7b9e25/attachment.html>


More information about the petsc-users mailing list