[petsc-users] Changing the diagonal of a matrix via a vector

Xiangdong Liang xdliang at gmail.com
Wed Apr 27 11:41:22 CDT 2011


On Wed, Apr 27, 2011 at 12:03 PM, Jed Brown <jed at 59a2.org> wrote:

> On Wed, Apr 27, 2011 at 17:57, Xiangdong Liang <xdliang at gmail.com> wrote:
>
>> I am a novice to Petsc and parallel computing. I have created a mpi sparse
>> matrix A (size n-by-n) and a parallel vector b (size n-by-1). Now I want to
>> modify the diagonal of A by adding the values of vector b. Namely, A(i,i) =
>> A(i,i) + b(i) and all the off-diagonal elements remains the same. I am
>> worrying that when I use MatSetValue or MatSetValues, b(i) may not be
>> accessed by some particular processor since VecGetValues can only get values
>> on the same processor. One possible solution I am thinking  is converting
>> vector b to a diagonal matrix B and then do the MatAXPY operation. However,
>> using MatSetValue to set diagonal elements of B,  B(i,i) = b(i),  still
>> faces the similar problem. Can anyone give me some suggestion? Thanks.
>>
>
> MatDiagonalSet(A,b,ADD_VALUES)
>
>
> http://www.mcs.anl.gov/petsc/petsc-as/snapshots/petsc-dev/docs/manualpages/Mat/MatDiagonalSet.html
>
>
>> P.S. When I compiled my program, I get warnings like that: warning: return
>> makes pointer from integer without a cast. Actually, these lines are
>> standard Petsc functions like that:
>>
>> ierr = VecCreate(PETSC_COMM_WORLD,&x);CHKERRQ(ierr);
>> ierr = VecDestroy(x); CHKERRQ(ierr);
>>
>> How can I get rid of these warnings?
>>
>
> Either make your function return int (or PetscErrorCode), passing "return
> values" back through arguments or use CHKERRV (worse because errors won't
> propagate up correctly).
>
>
Thanks a lot, Jed. I am using Petsc's built-in function, VecCreate and
MatCreate. they are supposed to return PetscErrorCode. However, I still get
"warning: return makes pointer from integer without a cast" for these
built-in functions.



>
> http://www.mcs.anl.gov/petsc/petsc-as/snapshots/petsc-dev/docs/manualpages/Sys/CHKERRQ.html
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20110427/595b387c/attachment.htm>


More information about the petsc-users mailing list