[petsc-users] preallocation for FE matrix

Tabrez Ali stali at geology.wisc.edu
Mon Oct 4 16:21:47 CDT 2010


I am trying to assemble a FE matrix (adding one element at a time from 
the local stiffness matrix) and cant seem to get the preallocation 
right. I am correctly calculating the number of non zeros per row and 
storing the value in the array [nnzpr].

Here is part of the relevant code

...
call MatCreateSeqBAIJ(Petsc_Comm_Self, 1, m, n, petsc_null_integer, 
nnzpr, Mat_A, ierr)
...
! Assume a bilinear quad (2 dof per node)
do j1=1,8
  do j2=1,8
    call MatSetValues(Mat_A, 1, indx(j1)-1, 1, indx(j2)-1, k(j1,j2), 
Add_Values, ierr)
  end do
end do
...
call MatAssemblyBegin(Mat_A,Mat_Final_Assembly,ierr)
call MatAssemblyEnd(Mat_A,Mat_Final_Assembly,ierr)
...

On running it I get

-bash-3.00$ ./a.out <inp -info -mat_view_info
...
 Total non-zero elements estimated i.e., sum(nnzpr) =                  112
[0] PetscCommDuplicate(): Duplicating a communicator 1140850689 
-2080374784 max tags = 2147483647
[0] PetscCommDuplicate():   returning tag 2147483647
[0] MatAssemblyEnd_SeqBAIJ(): Matrix size: 12 X 12, block size 1; 
storage space: 42 unneeded, 112 used
[0] MatAssemblyEnd_SeqBAIJ(): Number of mallocs during MatSetValues is 9
[0] MatAssemblyEnd_SeqBAIJ(): Most nonzeros blocks in any row is 12
...
Matrix Object:
  type=seqbaij, rows=12, cols=12
  total: nonzeros=112, allocated nonzeros=154
      block size is 1

I dont understand why -mat_view_info shows allocated nonzeros to be 154 
when sum(nnzpr) is 112.

Thanks in advance.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20101004/135478d7/attachment.htm>


More information about the petsc-users mailing list