<div dir="ltr"><div>Thanks for your response! I suppose I should have just checked the code out myself :-)<br></div><div><br></div>Makes sense - I won't worry about it then unless it shows up in profiling (which I doubt). I just wanted to make sure it wasn't an N^2 operation (which it's not since my matrices are very sparse).<div><br></div><div>Thanks again,</div><div>Derek</div></div><br><div class="gmail_quote"><div dir="ltr">On Fri, Apr 27, 2018 at 12:00 PM Smith, Barry F. <<a href="mailto:bsmith@mcs.anl.gov">bsmith@mcs.anl.gov</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><br>
Here is the current code: ;-)<br>
<br>
PetscErrorCode MatGetRowSum(Mat mat, Vec v)<br>
{<br>
Vec ones;<br>
PetscErrorCode ierr;<br>
<br>
PetscFunctionBegin;<br>
PetscValidHeaderSpecific(mat,MAT_CLASSID,1);<br>
PetscValidType(mat,1);<br>
PetscValidHeaderSpecific(v,VEC_CLASSID,2);<br>
if (!mat->assembled) SETERRQ(PetscObjectComm((PetscObject)mat),PETSC_ERR_ARG_WRONGSTATE,"Not for unassembled matrix");<br>
MatCheckPreallocated(mat,1);<br>
ierr = MatCreateVecs(mat,&ones,NULL);CHKERRQ(ierr);<br>
ierr = VecSet(ones,1.);CHKERRQ(ierr);<br>
ierr = MatMult(mat,ones,v);CHKERRQ(ierr);<br>
ierr = VecDestroy(&ones);CHKERRQ(ierr);<br>
PetscFunctionReturn(0);<br>
}<br>
<br>
An optimized for AIJ one would avoid creating the matrix and avoid the multiples by 1 in the summation and avoid the communication.<br>
<br>
I wouldn't worry about its performance; it won't be the bottle neck generally. Writing a custom routine for AIJ (seq and MPI) would be easy, just structure it like the MatMult_xxx() routine.<br>
<br>
Barry<br>
<br>
<br>
> On Apr 27, 2018, at 11:58 AM, Derek Gaston <<a href="mailto:friedmud@gmail.com" target="_blank">friedmud@gmail.com</a>> wrote:<br>
> <br>
> I was wondering about the comment on MatGetRowSum that says:<br>
> <br>
> "This code is slow since it is not currently specialized for different formats"<br>
> <br>
> How slow are we talking about here? Is it actually going to loop over i,j from 0 to N on a sparse matrix?<br>
> <br>
> I need to get a vector that represents the "lumped" mass matrix: but I would like to get it fairly quickly. I would just compute the lumped matrix directly and then use MatGetDiag - but I actually want both (unlumped/consistent and lumped) and MatGetRowSum seemed like the best direction. Willing to take advice though!<br>
> <br>
> Derek<br>
<br>
</blockquote></div>