For some finite element codes I've written in the past I have wanted to leave the constraints in the matrix. Since the global FE stiffness is assembled from element (local) contributions, a masking matrix used to zero out entries can also be applied on the element level as well. I would assemble the full matrix, then apply the mask. I found this approach efficient enough (provided you used MAT_FLUSH_ASSEMBLY when switching from ADD_VALUES to INSERT_VALUES) as you are not generating any new non entires within the matrix sparsity pattern. 
<br><br>Cheers,<br>&nbsp;&nbsp;&nbsp; Dave.<br><br><div class="gmail_quote">
On Jan 18, 2008 9:32 PM, Toby D. Young &lt;<a href="mailto:tyoung@ippt.gov.pl" target="_blank">tyoung@ippt.gov.pl</a>&gt; wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">

<br><br><br>Hello users,<br><br>The procedure I wish to program with petsc requires setting a series of<br>matrix elements to zero, and for a given number of rows and columns.<br>The operation is intended to run for large parallel sparse matrices.
<br><br>Using MatZeroRowsIS() I can easily achieve zeroing out the rows I want<br>and now I am wondering how to zero out the columns. I imagine there are<br>a few other ways of doing this, I&#39;ve come up with two:<br><br>

<br>Method 1<br>MatGetColumnIJ() &nbsp; &nbsp; // get a specified column<br>VecSetValues() &nbsp; &nbsp; &nbsp; // set wanted indices to zero<br>MatRestoreColumnIJ() // restore vector to the matrix<br><br>The Petsc manual warns &quot;Since PETSc matrices are usually stored in
<br>compressed row format, this routine will generally be<br>slow.&quot; (of MatGetColumnIJ).<br><br>Method 2<br>MatTranspose() &nbsp; &nbsp; &nbsp; // Take the transpose of the matrix<br>MatZeroRowsIS() &nbsp; &nbsp; &nbsp;// Zeroi out the row which was the target column
<br><br>This requires creating a new matrix, i.e. the transpose and then<br>releasing memory from the old matrix. The advantage is that it is<br>relatively straightforward to code up.<br><br>The rather obvious third way is to simply force the column elements to
<br>be zero with MatSetValues() which, I am guessing, is not likely to be<br>efficient and I am not really considering this.<br><br>I am wondering if anyone has a clue as to which of the methods above is<br>likely to be more efficient for large parallel sparse matrices. Perhaps
<br>someone may have a suggesttion for an alternative approach.<br><br>Thanks in advance.<br><br>Best,<br> &nbsp; &nbsp; &nbsp; &nbsp;Toby<br><font color="#888888"><br><br><br><br>--<br><br>Toby D. Young - Adiunkt (Assistant Professor)<br>Department of Computational Science
<br>Institute of Fundamental Technological Research<br>Polish Academy of Sciences<br>Room 206, Swietokrzyska 21<br>00-049 Warsaw, POLAND<br><br></font></blockquote></div><br>