<div dir="ltr"><br><br><div class="gmail_quote">---------- Forwarded message ----------<br>From: <b class="gmail_sendername">Lu Qiyue</b> <span dir="ltr"><<a href="mailto:luqiyue@gmail.com">luqiyue@gmail.com</a>></span><br>
Date: Fri, Jul 19, 2013 at 3:39 PM<br>Subject: Re: [petsc-users] MatCreateSeqAIJ( ) Quesion<br>To: Barry Smith <<a href="mailto:bsmith@mcs.anl.gov">bsmith@mcs.anl.gov</a>><br><br><br><div dir="ltr"><div class="gmail_extra">
<div class="gmail_quote">Thanks Barry.<br></div><div class="gmail_quote">I am trying to premalloc the correct value for each row. Assume the matrix is in COO format and N is the dimension, NNZ is total non-zeros. My workflow is as below: <br>

</div><div class="gmail_quote">1) generating a file holding all the correct number of non-zeros for each row and read-in as cnt<br></div><div class="gmail_quote"><br>from <br><a href="http://www.mcs.anl.gov/petsc/petsc-current/src/mat/examples/tutorials/ex12.c.html" target="_blank">http://www.mcs.anl.gov/petsc/petsc-current/src/mat/examples/tutorials/ex12.c.html</a><br>

</div><div class="gmail_quote">It looks cnt should have N+1 dimension and the last value is the total non-zeros NNZ<br></div><div class="gmail_quote">One question here is at line 45, why the dimension of matrix are set to be (n+1), should it be n ?<br>

</div><div class="gmail_quote">In <a href="http://www.mcs.anl.gov/petsc/petsc-dev/src/mat/examples/tests/ex72.c.html" target="_blank">http://www.mcs.anl.gov/petsc/petsc-dev/src/mat/examples/tests/ex72.c.html</a><br>they are just set to m, n<br>

<br>For ex72.c, the code copy the entries which not on the diagonal and make the symmetric COO matrix to be FULL. <br>But when we do the MatCreateSeqAIJ, the cnt should holding number of non-zeros per row of FULL matrix, right?<br>

<br></div><div class="gmail_quote">In one word, what's the content(and dimension) of cnt array and how to set  MatCreateSeqAIJ() assuming a N dimension matrix?<br></div><div class="gmail_quote"><br></div><div class="gmail_quote">

</div><div class="gmail_quote">Thanks<span class="HOEnZb"><font color="#888888"><br></font></span></div><span class="HOEnZb"><font color="#888888"><div class="gmail_quote">Qiyue Lu<br> <br></div></font></span><div><div class="h5">
<div class="gmail_quote">On Tue, Jul 9, 2013 at 8:56 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:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div><br>
<br>
On Jul 9, 2013, at 8:49 PM, Lu Qiyue <<a href="mailto:luqiyue@gmail.com" target="_blank">luqiyue@gmail.com</a>> wrote:<br>
<br>
> Dear All:<br>
> I am using a modified version of ex72.c in<br>
> /src/mat/examples/tests<br>
> directory to create a matrix with COO format.<br>
><br>
> In the line:<br>
> ierr = MatCreateSeqAIJ(PETSC_COMM_WORLD,m,n, (m*n/nnz),PETSC_NULL,&A);CHKERRQ(ierr);<br>
><br>
> The 'nz' is set to (m*n/nnz).<br>
<br>
</div>  Hmm, perhaps you are looking at an older version of the code. The current version <a href="http://www.mcs.anl.gov/petsc/petsc-dev/src/mat/examples/tests/ex72.c.html" target="_blank">http://www.mcs.anl.gov/petsc/petsc-dev/src/mat/examples/tests/ex72.c.html</a>  has<br>



<br>
MatCreateSeqAIJ(PETSC_COMM_WORLD,m,n,nnz*2/m,0,&A);<br>
<div><br>
<br>
><br>
<br>
> And from documents, nz is:<br>
> nz - number of nonzeros per row (same for all rows)<br>
><br>
> <a href="http://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/Mat/MatCreateSeqAIJ.html" target="_blank">http://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/Mat/MatCreateSeqAIJ.html</a><br>
><br>
><br>
> I am wondering, why this value is set to be m*n/nnz? Looks obvious this is not the number of nonzeros per row. What's the rule for choosing nz?<br>
><br>
> If only one value here, should it be the largest number of non-zeroes among all rows?<br>
<br>
</div>  Yes it should be the largest, this will lead to the fastest mat assembly (at an expense of using extra memory). We recommend preallocating the correct value for each row except in the most trivial codes.<br>
<br>
   Barry<br>
<br>
><br>
> Thanks<br>
><br>
> Qiyue Lu<br>
<br>
</blockquote></div><br></div></div></div></div>
</div><br></div>