[petsc-users] Fwd: MatCreateSeqAIJ( ) Quesion

Lu Qiyue luqiyue at gmail.com
Fri Jul 19 15:40:07 CDT 2013


---------- Forwarded message ----------
From: Lu Qiyue <luqiyue at gmail.com>
Date: Fri, Jul 19, 2013 at 3:39 PM
Subject: Re: [petsc-users] MatCreateSeqAIJ( ) Quesion
To: Barry Smith <bsmith at mcs.anl.gov>


Thanks Barry.
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:
1) generating a file holding all the correct number of non-zeros for each
row and read-in as cnt

from
http://www.mcs.anl.gov/petsc/petsc-current/src/mat/examples/tutorials/ex12.c.html
It looks cnt should have N+1 dimension and the last value is the total
non-zeros NNZ
One question here is at line 45, why the dimension of matrix are set to be
(n+1), should it be n ?
In http://www.mcs.anl.gov/petsc/petsc-dev/src/mat/examples/tests/ex72.c.html
they are just set to m, n

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

In one word, what's the content(and dimension) of cnt array and how to set
MatCreateSeqAIJ() assuming a N dimension matrix?

Thanks
Qiyue Lu

On Tue, Jul 9, 2013 at 8:56 PM, Barry Smith <bsmith at mcs.anl.gov> wrote:

>
>
> 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
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20130719/2dae70c8/attachment.html>


More information about the petsc-users mailing list