<div class="gmail_quote">On Thu, Feb 24, 2011 at 16:33, M. Scot Breitenfeld <span dir="ltr"><<a href="mailto:brtnfld@uiuc.edu">brtnfld@uiuc.edu</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<div id=":bg">I'm working on a particle type method and I'm using MatSetValues, to<br>
insert values (add_values) into my matrix. Currently I:<br>
<br>
do i, loop over number of particles<br>
do j, loop over particles in i's family<br></div></blockquote><div><br></div><div>How big is a typical family?</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<div id=":bg">
...<br>
in row i's dof; insert values in columns of j's (x,y,z) dofs<br>
(3 calls to MatSetValues for i's x,y,z dof)<br></div></blockquote><div><br></div><div>Why make three calls here instead of one?</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<div id=":bg">
in row j's dof; insert values in columns of i's (x,y,z) dofs<br>
(3 calls to MatSetValues for j's x,y,z dof)<br></div></blockquote><div><br></div><div>Again, why call these separately? Also, is the matrix symmetric?</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<div id=":bg">
...<br>
enddo<br>
enddo<br>
<br>
Running serially, using MatSetValues it takes 294.8 sec. to assemble the<br>
matrix,</div></blockquote><div><br></div><div>Are you sure that it was preallocated correctly? Is the cost to compute the entries essentially zero? </div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<div id=":bg"> if I remove the calls to MatSetValues it takes 29.5 sec. to run<br>
through the same loops, so the MatSetValues calls take up 90% of the<br>
assembling time. I'm preallocating the A matrix specifying d_nnz and o_nnz.<br>
<br>
I guess I need to add extra storage so I can call the MatSetValues with<br>
more values so that I can call it less, or just do a lot of<br>
recalculating of values so that I can add an entire row at once. I just<br>
want to make sure this is expected behavior and not something that I'm<br>
doing wrong before I start to rewrite my assembling routine. Probably a<br>
hash table would be better but I don't want to store that and then<br>
convert that to a CRS matrix, I'm already running into memory issues as<br>
it is.<br>
<br>
Just out of curiosity, wouldn't a finite element code have a similar<br>
situation, in that case you would form the local stiffness matrix and<br>
then insert that into the global stiffness matrix, so you would be<br>
calling MatSetValues "number of elements" times.</div></blockquote></div><br><div>FEM has a simple quadrature loop that builds a dense element matrix, MatSetValues() is called once per element.</div>