<div dir="ltr">Hi Barry,<div><br></div><div>yes, I am inserting new locations. I was actually copying matrix </div><div>C to a new matrix D, and then I was inserting the "thresholded" </div><div>values -E*(B\E) in this matrix D.</div><div><br></div><div>I was pretty much sure that the missing pre-allocation was the </div><div>reason for the slow code -- when I commented out the MatSetValues()</div><div>part (i.e. I approximated the Schur complement only by matrix C), </div><div>this part was much much faster.</div><div><br></div><div>I will definitely follow your suggestion -- Thanks!!!</div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Jan 25, 2016 at 1:07 PM, Barry Smith <span dir="ltr"><<a href="mailto:bsmith@mcs.anl.gov" target="_blank">bsmith@mcs.anl.gov</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class=""><br>
> On Jan 25, 2016, at 12:15 PM, Vasileios Kalantzis <<a href="mailto:kalan019@umn.edu">kalan019@umn.edu</a>> wrote:<br>
><br>
> Dear all,<br>
><br>
> I am trying to form an approximation of the<br>
> Schur complement S = C-E'*(B\E) of a matrix<br>
> A = [B, E ; E', C]. Matrix C is stored as a<br>
> distributed Mat object while matrices B and E<br>
> are locally distributed to each processor (the<br>
> block partitioning comes from a Domain<br>
> Decomposition point-of-view). All matrices B, E,<br>
> and C are sparse.<br>
><br>
> I already have a sparse version of -E'*(B\E)<br>
> computed. Moreover, -E'*(B\E) is block-diagonal.<br>
> The only issue now is how to merge (add) C and<br>
> -E'*(B\E). The way i do the addition right now is<br>
> based on checking every entry of -E'*(B\E) and,<br>
> if larger than a threshold value, add it to C using<br>
> the MatSetValue routine. The above is being done<br>
> in parallel for each diagonal block of -E'*(B\E).<br>
><br>
> The code works fine numerically but my approach<br>
> is too slow if -E'*(B\E) is not highly sparse.<br>
<br>
</span> This is a guess, but if you inserting new nonzero locations into C with MatSetValues() then this will be very slow. Are you inserting new locations?<br>
<br>
If so, here is what you need to do. Sweep through the rows of C/-E'*(B\E) determining the number of nonzeros that will be in the result and then use MatCreateMPIAIJ() or MatMPIAIJSetPreallocation() to preallocate the space in a new matrix, say D. Then sweep through all the rows again actually calling the MatSetValues() and put the entries into D. Switching from non-preallocation to preallocation will speed it up dramatically (factors of 100's or more) if you were inserting new locations.<br>
<span class="HOEnZb"><font color="#888888"><br>
Barry<br>
</font></span><div class="HOEnZb"><div class="h5"><br>
<br>
<br>
><br>
> I know that I can set many entries together by<br>
> using the MatSetValues routine but I am not<br>
> sure how to do it because the sparsity pattern of<br>
> each column of -E'*(B\E) differs. Maybe I can<br>
> assemble the sparsified Schur complement<br>
> column-by-column using MatSetValues but is<br>
> there any other idea perhaps?<br>
><br>
> Thanks ! :)<br>
<br>
</div></div></blockquote></div><br></div>