On Tue, Dec 6, 2011 at 11:39 PM, Xiangdong Liang <span dir="ltr"><<a href="mailto:xdliang@gmail.com">xdliang@gmail.com</a>></span> wrote:<br><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<div class="im">On Wed, Dec 7, 2011 at 12:11 AM, Barry Smith <<a href="mailto:bsmith@mcs.anl.gov">bsmith@mcs.anl.gov</a>> wrote:<br>
><br>
> On Dec 6, 2011, at 10:26 PM, Xiangdong Liang wrote:<br>
><br>
>> Hello everyone,<br>
>><br>
>> Can anyone help on the usage of MAT_IGNORE_ZERO_ENTRIES? Suppose I<br>
>> want to have a 10-by-10 sparse matrix, where each row has maximum two<br>
>> nonzeros. I would like to have petsc ignore the 0.0 values by not<br>
>> allocating space for 0.0 values. In my problem, the nonzero pattern of<br>
>> sparse matrix will never change. I hope the ignore of zero entries<br>
>> will save lots of operations when I am doing matrix-vector product or<br>
>> spare-direct decomposition .<br>
>><br>
>> Below is my script. When I check the mat_view_info, I have<br>
>><br>
>> Matrix Object:<br>
>> type=mpiaij, rows=10, cols=10<br>
>> total: nonzeros=20, allocated nonzeros=40<br>
>> not using I-node (on process 0) routines<br>
>><br>
>> Is there a way to have nonzeros=10, and allocated nonzeros=10, since<br>
>> the number of real nonzeros=10? Thanks.<br>
><br>
> Those "extra" nonzeros are not actually in the sparse matrix so they do not cause extra multiples. You can safely ignore them.<br>
<br>
</div>I am sorry I am still not clear. Do "extra" nonzeros refer to<br>
“nonzeros=20” or "allocated nonzeros=40"? With or without<br>
MatSetOption(A,MAT_IGNORE_ZERO_ENTRIES,PETSC_TRUE), I see the same<br>
mat_view_info. How can I see the differences in the spare matrix<br>
generated With/Without this option? Thanks.</blockquote><div><br></div><div>If there are 2 nonzeros per row, there are 20 nonzeros not 10 in the matrix. According to</div><div>the output, you allocated 40 nonzeros for the matrix.</div>
<div><br></div><div>When you call MatAssemblyEnd(), we compress the matrix so that the 20 extra allocated nonzeros</div><div>are not present.</div><div><br></div><div> Matt</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<font color="#888888"><br>
Xiangdong<br>
</font><div><div></div><div class="h5"><br>
<br>
><br>
> Barry<br>
><br>
>><br>
>> Xiangdong<br>
>><br>
>> -----------------------------------------------------------<br>
>> Mat A; int N=10, i, ns,ne;<br>
>> ierr=MatCreateMPIAIJ(PETSC_COMM_WORLD,PETSC_DECIDE,PETSC_DECIDE,N,N,2,NULL,2,NULL,&A);CHKERRQ(ierr);<br>
>> ierr = MatGetOwnershipRange(A, &ns, &ne); CHKERRQ(ierr);<br>
>> for (i=ns;i<ne;i++) { ierr=MatSetValue(A,i, i, 1.0,<br>
>> ADD_VALUES); CHKERRQ(ierr); ierr=MatSetValue(A,i, (i+1)%N, 0.0,<br>
>> ADD_VALUES); CHKERRQ(ierr); }<br>
>> MatSetOption(A,MAT_IGNORE_ZERO_ENTRIES,PETSC_TRUE); ierr =<br>
>> MatAssemblyBegin(A, MAT_FINAL_ASSEMBLY); CHKERRQ(ierr); ierr =<br>
>> MatAssemblyEnd(A, MAT_FINAL_ASSEMBLY); CHKERRQ(ierr);<br>
>><br>
>> --------------------------------------------------------<br>
>><br>
>><br>
>> On Thu, Dec 1, 2011 at 10:01 PM, Barry Smith <<a href="mailto:bsmith@mcs.anl.gov">bsmith@mcs.anl.gov</a>> wrote:<br>
>>><br>
>>> The checks in the code are lines like<br>
>>><br>
>>> if (value == 0.0 && ignorezeroentries && (is == ADD_VALUES)) continue;<br>
>>><br>
>>> hence changing the source code to ignore small values is not difficult. But I think this is a terribly cheesy hack and would hope people would not do this.<br>
>>><br>
>>> Barry<br>
>>><br>
>>><br>
>>><br>
>>> On Dec 1, 2011, at 8:42 PM, Mohamad M. Nasr-Azadani wrote:<br>
>>><br>
>>>> I was always wondering how difficult it would be to define a constant say, ZERO_DROP_TOLERANCE so that when the matrix is setup, MatAssemblyBegin()/End(), it automatically ignores the values below this threshold?<br>
>>>> I understand the for the matrices that might change in successive iterations, that might not be a good idea since the memory reallocation could be very slow, but for a lot of cases which a constant matrix, that could be simply helpful.<br>
>>>><br>
>>>> Best,<br>
>>>> Mohamad<br>
>>>><br>
>>>><br>
>>>><br>
>>>><br>
>>>><br>
>>>> On Thu, Dec 1, 2011 at 5:00 PM, Barry Smith <<a href="mailto:bsmith@mcs.anl.gov">bsmith@mcs.anl.gov</a>> wrote:<br>
>>>><br>
>>>> On Dec 1, 2011, at 6:44 PM, Xiangdong Liang wrote:<br>
>>>><br>
>>>>> Hello everyone,<br>
>>>>><br>
>>>>> I have a question about whether zeros will change the sparse pattern.<br>
>>>>> Suppose I am generating two sparse matrices A and B. A is generated<br>
>>>>> with exactly number of nonzeros, say 10 nnz per row. When I generate<br>
>>>>> matrix B, I specify 12 nonzeros, but two of them are given zero values<br>
>>>>> by MatSetValue. Will A and B have same sparsity patterns and<br>
>>>>> performance ? In other words, will PETSc simply ignore these zeros<br>
>>>>> entries? I output these A and B in matlab, and it seems that these<br>
>>>>> zeros entries are ignored. I just want to double check on this.<br>
>>>>><br>
>>>>> Is the option MAT_IGNORE_ZERO_ENTRIES on by default?<br>
>>>><br>
>>>> No, by default PETSc will insert the zero values thus increasing the nonzero pattern. If you set that option to the matrix then inserting values it will not introduce an increase in the pattern.<br>
>>>><br>
>>>><br>
>>>> BTW: if you then load the matrix via a binary file to MATLAB it may be that MATLAB silently removes those locations so you don't see them.<br>
>>>> Barry<br>
>>>><br>
>>>>> Thanks.<br>
>>>>><br>
>>>>> Best,<br>
>>>>> Xiangdong<br>
>>>><br>
>>>><br>
>>><br>
><br>
</div></div></blockquote></div><br><br clear="all"><div><br></div>-- <br>What most experimenters take for granted before they begin their experiments is infinitely more interesting than any results to which their experiments lead.<br>
-- Norbert Wiener<br>