<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body text="#000000" bgcolor="#FFFFFF">
On 2/21/19 1:48 PM, Smith, Barry F. wrote:<br>
<blockquote type="cite" cite="mid:92ED0683-B9A8-429D-9028-D88AD238894D@mcs.anl.gov">
<pre class="moz-quote-pre" wrap="">
</pre>
<blockquote type="cite">
<pre class="moz-quote-pre" wrap="">On Feb 20, 2019, at 12:50 PM, Mills, Richard Tran via petsc-dev <a class="moz-txt-link-rfc2396E" href="mailto:petsc-dev@mcs.anl.gov"><petsc-dev@mcs.anl.gov></a> wrote:
Folks,
I'm working with some PFLOTRAN examples, and I've been scratching my head for a while at errors that are being generated in MatSetValuesBlockedLocal(), related to new nonzeros requiring a malloc. E.g.,
[0]PETSC ERROR: Argument out of range
[0]PETSC ERROR: New nonzero at (2,0) caused a malloc
The strange thing is that all of these examples run fine when I use the PFLOTRAN default BAIJ matrix type (with blocks column-oriented) -- I only see the issue when I switch to using AIJ. If I set the matrix option MAT_NEW_NONZERO_ALLOCATION_ERR to PETSC_FALSE to allow things to run with AIJ, everything seems to work perfectly. (And once the Jacobian matrix is constructed the first time, the memory usage is not growing according to what I see from -malloc_log.)
I've spent some time poking around with a debugger in the variants of MatSetValues() and MatXAIJSetPreallocation(), and I haven't been able make much progress in determining why I'm seeing this in AIJ vs. BAIJ -- it's easy to get confused looking at this code, and it's going to take me more time to follow what is going on than I've had to spare so far. So, I've got a few questions. First, should it even be possible to see what I am seeing? That is, if the MatSetValuesBlocked() routine is not causing new allocations when using BAIJ, should this be possible with AIJ?
</pre>
</blockquote>
<pre class="moz-quote-pre" wrap="">
Sure, because the preallocation for BAIJ matrix is by block, while for AIJ it is by point (even if you provide a block size to AIJ). So long as the new entry is within an allocated block it will not trigger an error with BAIJ but may with AIJ.</pre>
</blockquote>
Hmm. It seems that I've misunderstood what MatXAIJSetPreallocation() is supposed to do. I thought that if I pass in a blocksize > 1, MatXAIJSetPreallocation() will turn the block-row preallocation into the equivalent scalar-row stuff. This seems to be what
is happening in the code, unless I'm reading this wrong:<br>
<br>
<tt>[...]</tt><br>
<tt>304: } else { /* Convert block-row precallocation to scalar-row */</tt><tt><br>
</tt><tt>305: PetscInt i,m,*sdnnz,*sonnz;</tt><tt><br>
</tt><tt>306: MatGetLocalSize(A,&m,NULL);</tt><tt><br>
</tt><tt>307: PetscMalloc2((!!dnnz)*m,&sdnnz,(!!onnz)*m,&sonnz);</tt><tt><br>
</tt><tt>308: for (i=0; i<m; i++) {</tt><tt><br>
</tt><tt>309: if (dnnz) sdnnz[i] = dnnz[i/bs] * bs;</tt><tt><br>
</tt><tt>310: if (onnz) sonnz[i] = onnz[i/bs] * bs;</tt><tt><br>
</tt><tt>311: }</tt><tt><br>
</tt><tt>312: MatSeqAIJSetPreallocation(A,0,dnnz ? sdnnz : NULL);</tt><tt><br>
</tt><tt>313: MatMPIAIJSetPreallocation(A,0,dnnz ? sdnnz : NULL,0,onnz ? sonnz : NULL);<br>
[...]<br>
</tt><br>
Though might something be happening later that reduces the amount of nonzeros allocated, since the "dense" blocks of the matrix actually will have zero entries that never get a value set?<br>
<br>
Something does appear to be screwy when I look at the "-snes_view" output for a time-dependent problem where I see these errors. When using BAIJ, at every time step I see<br>
<br>
<tt> Mat Object: Mat_0x84000000_0 (flow_) 1 MPI processes</tt><tt><br>
</tt><tt> type: seqbaij</tt><tt><br>
</tt><tt> rows=144, cols=144, bs=3</tt><tt><br>
</tt><tt> total: nonzeros=2304, allocated nonzeros=2304</tt><tt><br>
</tt><tt> total number of mallocs used during MatSetValues calls =0</tt><tt><br>
</tt><tt> block size is 3</tt><tt><br>
</tt><br>
but when I switch to AIJ, I initially see<br>
<br>
<tt> Mat Object: Mat_0x84000000_0 (flow_) 1 MPI processes</tt><tt><br>
</tt><tt> type: seqaij</tt><tt><br>
</tt><tt> rows=144, cols=144, bs=3</tt><tt><br>
</tt><tt> total: nonzeros=1584, allocated nonzeros=3324</tt><tt><br>
</tt><tt> total number of mallocs used during MatSetValues calls =68</tt><tt><br>
</tt><tt> using I-node routines: found 96 nodes, limit used is 5</tt><br>
<br>
but as things progress, the allocated nonzeros and mallocs count keeps growing; by step 43 I'm seeing<br>
<br>
<tt> total: nonzeros=1584, allocated nonzeros=115524</tt><tt><br>
</tt><tt> total number of mallocs used during MatSetValues calls =7548</tt><br>
<br>
If I dump the matrices and look at them in something like Octave, the matrices from the BAIJ and AIJ runs appear identical within round-off error, and we certainly aren't adding any entries at each step. Why should PETSc keep calling malloc() at each MatSetValues()
call, then? I suspect a bug somewhere in the AIJ case call sequence of MatSetValuesBlockedLocal() --> MatSetValuesBlocked() --> MatSetValues() --> MatSetValues_SeqAIJ(). I have trouble following all of the logic in matsetvaluesseqaij_(), though, so I guess
I'm going to have try harder to understand why MatSeqXAIJReallocateAIJ() is being hit there.<br>
<br>
Any educated guesses about what might be going wrong would be appreciated. There is a lot of PETSc code I'm not familiar with involved here.<br>
<br>
Cheers,<br>
Richard<br>
<br>
<br>
<blockquote type="cite" cite="mid:92ED0683-B9A8-429D-9028-D88AD238894D@mcs.anl.gov">
<pre class="moz-quote-pre" wrap="">
Barry
</pre>
<blockquote type="cite">
<pre class="moz-quote-pre" wrap="">(Clearly it *is* possible, but should it be?) I'm still trying to figure out if there is something wrong with what PFLOTRAN is doing, vs. something going wrong somewhere inside PETSc.
Any hints about what to look at from someone with more familiarity with this code would be appreciated.
--Richard
</pre>
</blockquote>
<pre class="moz-quote-pre" wrap="">
</pre>
</blockquote>
<br>
</body>
</html>