On Jul 9, 2013, at 8:49 PM, Lu Qiyue <[email protected]> wrote:

> Dear All:
> I am using a modified version of ex72.c in 
> /src/mat/examples/tests
> directory to create a matrix with COO format. 
> 
> In the line:
> ierr = MatCreateSeqAIJ(PETSC_COMM_WORLD,m,n, 
> (m*n/nnz),PETSC_NULL,&A);CHKERRQ(ierr);
> 
> The 'nz' is set to (m*n/nnz).

  Hmm, perhaps you are looking at an older version of the code. The current 
version 
http://www.mcs.anl.gov/petsc/petsc-dev/src/mat/examples/tests/ex72.c.html  has 

MatCreateSeqAIJ(PETSC_COMM_WORLD,m,n,nnz*2/m,0,&A);


>  

> And from documents, nz is:
> nz - number of nonzeros per row (same for all rows) 
> 
> http://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/Mat/MatCreateSeqAIJ.html
> 
> 
> 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? 
> 
> If only one value here, should it be the largest number of non-zeroes among 
> all rows?

  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.

   Barry

> 
> Thanks
> 
> Qiyue Lu

Reply via email to