<div dir="ltr"><div>Hi Junchao,</div><div><br></div><div>That's what I think is happening. We managed to get a stack trace from one of the slow running cases, and it was over 100k frames deep in recursive PetscSortIntWithArrayPair_Private calls (see below). So perhaps we are seeing worse case O(n) stack frame depth for quicksort on an already-sorted array, but I also am not sure where the big number, n=35241426, comes from, as the problem did not have nearly that many DOFs.</div><div><br></div>#104609 PetscSortIntWithArrayPair_Private (L=0x7ff6a413e650, J=0x7ff69bace650, K=0x7ff68277e650, right=33123131)<br>#104610 PetscSortIntWithArrayPair_Private (L=0x7ff6a413e650, J=0x7ff69bace650, K=0x7ff68277e650, right=35241425)<br>#104611 PetscSortIntWithArrayPair (n=35241426, L=0x7ff6a413e650, J=0x7ff69bace650, K=0x7ff68277e650)<br>#104612 MatStashSortCompress_Private (stash=0x555f7603b628, insertmode=ADD_VALUES)<br>#104613 MatStashScatterBegin_BTS (mat=0x555f7603aee0, stash=0x555f7603b628, owners=0x555f7623c9c0)<br>#104614 MatStashScatterBegin_Private (mat=0x555f7603aee0, stash=0x555f7603b628, owners=0x555f7623c9c0)<br>#104615 MatAssemblyBegin_MPIAIJ (mat=0x555f7603aee0, mode=MAT_FINAL_ASSEMBLY)<div><br></div><div>--</div><div>John</div><div><br></div><div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, Jul 2, 2019 at 1:23 PM Zhang, Junchao <<a href="mailto:jczhang@mcs.anl.gov" target="_blank">jczhang@mcs.anl.gov</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<div>
<div dir="ltr">Is it because the array is already sorted?<br clear="all">
<div>
<div dir="ltr" class="m_-5907787701542565224gmail-m_-92115124881532401gmail_signature">
<div dir="ltr">--Junchao Zhang</div>
</div>
</div>
<br>
</div>
<br>
<div class="gmail_quote">
<div dir="ltr" class="gmail_attr">On Tue, Jul 2, 2019 at 12:13 PM Fande Kong via petsc-dev <<a href="mailto:petsc-dev@mcs.anl.gov" target="_blank">petsc-dev@mcs.anl.gov</a>> wrote:<br>
</div>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<div dir="ltr">
<div dir="ltr">
<div dir="ltr">
<div dir="ltr">Hi Developers,<br>
<div><br>
</div>
<div>John just noticed that the matrix assembly was slow when having sufficient amount of off-diagonal entries. It was not a MPI issue since I was able to reproduce the issue using two cores on my desktop, that is, "mpirun -n 2".</div>
<div><br>
</div>
<div>I turned on a profiling, and 99.99% of the time was spent on PetscSortIntWithArrayPair (recursively calling). It took THREE MINUTES to get the assembly done. And then changed to use the option "-matstash_legacy" to restore </div>
<div>the code to the old assembly routine, and the same code took ONE SECOND to get the matrix assembly done. </div>
<div><br>
</div>
<div>Should write any better sorting algorithms?</div>
<div><br>
</div>
<div><br>
</div>
<div>Fande,</div>
</div>
</div>
</div>
</div>
</blockquote>
</div>
</div>
</blockquote></div><br clear="all"><div><br></div>-- <br><div dir="ltr" class="m_-5907787701542565224gmail_signature">John</div></div></div>