On Thu, Feb 24, 2011 at 9:33 AM, M. Scot Breitenfeld <span dir="ltr"><<a href="mailto:brtnfld@uiuc.edu">brtnfld@uiuc.edu</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;">
Hi,<br>
<br>
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>
...<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></blockquote><div><br></div><div>You can set this whole row with a single call.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
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>
...<br>
enddo<br>
enddo<br>
<br>
Running serially, using MatSetValues it takes 294.8 sec. to assemble the<br>
matrix, 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></blockquote><div><br></div><div>Its hard to believe that the preallocation is correct. In order to check, use</div><div><br></div><div> MatSetOption(A, MAT_NEW_NONZERO_ALLOCATION_ERR)</div>
<div><br></div><div>before your MatSetValues() calls.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
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></blockquote><div><br></div><div>Recalculating?</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
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.<br>
</blockquote></div><br>No, you call it once per element matrix.<div><br></div><div> Matt<br clear="all"><br>-- <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>
</div>