[petsc-users] MatCreateSeqAIJ( ) Quesion

Barry Smith bsmith at mcs.anl.gov
Tue Jul 9 20:56:15 CDT 2013


 
On Jul 9, 2013, at 8:49 PM, Lu Qiyue <luqiyue at gmail.com> 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



More information about the petsc-users mailing list