<br><br><div class="gmail_quote">On Wed, Apr 27, 2011 at 12:03 PM, Jed Brown <span dir="ltr"><<a href="mailto:jed@59a2.org">jed@59a2.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div class="gmail_quote"><div class="im">On Wed, Apr 27, 2011 at 17:57, Xiangdong Liang <span dir="ltr"><<a href="mailto:xdliang@gmail.com" target="_blank">xdliang@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div>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><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" target="_blank">http://www.mcs.anl.gov/petsc/petsc-as/snapshots/petsc-dev/docs/manualpages/Mat/MatDiagonalSet.html</a></div>
<div class="im">
<div> </div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><div>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></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></blockquote><div><br>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. <br>
<br> </div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><div></div><div><a href="http://www.mcs.anl.gov/petsc/petsc-as/snapshots/petsc-dev/docs/manualpages/Sys/CHKERRQ.html" target="_blank">http://www.mcs.anl.gov/petsc/petsc-as/snapshots/petsc-dev/docs/manualpages/Sys/CHKERRQ.html</a></div>
</blockquote></div><br>