<div class="gmail_quote">On Wed, Apr 27, 2011 at 17:57, Xiangdong Liang <span dir="ltr"><<a href="mailto:xdliang@gmail.com">xdliang@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<div id=":a">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.<br>
</div></blockquote><div><br></div><div>MatDiagonalSet(A,b,ADD_VALUES)</div><div><br></div><div><a href="http://www.mcs.anl.gov/petsc/petsc-as/snapshots/petsc-dev/docs/manualpages/Mat/MatDiagonalSet.html">http://www.mcs.anl.gov/petsc/petsc-as/snapshots/petsc-dev/docs/manualpages/Mat/MatDiagonalSet.html</a></div>
<div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;"><div id=":a">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: <br>
<br>ierr = VecCreate(PETSC_COMM_WORLD,&x);CHKERRQ(ierr);<br>
ierr = VecDestroy(x); CHKERRQ(ierr);<br><br>How can I get rid of these warnings? </div></blockquote></div><br><div>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).</div>
<div><br></div><div><a href="http://www.mcs.anl.gov/petsc/petsc-as/snapshots/petsc-dev/docs/manualpages/Sys/CHKERRQ.html">http://www.mcs.anl.gov/petsc/petsc-as/snapshots/petsc-dev/docs/manualpages/Sys/CHKERRQ.html</a></div>