[petsc-users] preallocation for FE matrix
Tabrez Ali
stali at geology.wisc.edu
Mon Oct 4 16:43:44 CDT 2010
Barry Smith wrote:
> On Oct 4, 2010, at 4:21 PM, Tabrez Ali wrote:
>
>
>> 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].
>>
>
> (For sequential case) you cannot be calculating the number of nonzeros per row correctly and yet not getting the preallocation correct.
>
> For your simple problem. Print the nonzeros per row you are computing then print the sparse matrix you computing. That will show which rows are not computed or set properly.
>
I am calculating the nonzeros per row correctly and have checked this by
explicitly forming the dense matrix.
Here is the stiffness matrix (1 corresponds to non zero location)
pattern for the same problem.
1 1 1 1 1 1 1 1 0 0 0 0
1 1 1 1 1 1 1 1 0 0 0 0
1 1 1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 0 0 0 0
1 1 1 1 1 1 1 1 0 0 0 0
0 0 1 1 1 1 0 0 1 1 1 1
0 0 1 1 1 1 0 0 1 1 1 1
0 0 1 1 1 1 0 0 1 1 1 1
0 0 1 1 1 1 0 0 1 1 1 1
and here is the [nnzpr] array that I passed to MatCreateSeqBAIJ
8
8
12
12
12
12
8
8
8
8
8
8
The sum of values in [nnzpr] adds up to 112.
Thanks again
>> I dont understand why -mat_view_info shows allocated nonzeros to be 154 when sum(nnzpr) is 112.
>>
>
> If you mess up the count on a row it allocates a few extra for that row (incase you end up needing them) so the number allocated can be more then the number actually needed.
>
> Barry
>
>
>
>> 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/c144f95e/attachment.htm>
More information about the petsc-users
mailing list