[petsc-users] issues with MatSeqAIJSetPreallocation
Chung-Kan Huang
ckhuangf at gmail.com
Wed Oct 16 23:53:57 CDT 2013
Hi,
I am using Petsc to solve a linear system contain variable size of nnz for
each row.
The maximal nnz in some cases could be several hundreds times of minimal
nnz so I was trying to use following,
Mat A;
int N;
PetscInt * d_nnz;
PetscMalloc<http://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/Sys/PetscMalloc.html#PetscMalloc>
((N)*sizeof(PetscInt<http://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/Sys/PetscInt.html#PetscInt>),
&d_nnz);
*** assigning d_nnz ***
MatCreate<http://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/Mat/MatCreate.html#MatCreate>
(PETSC_COMM_WORLD<http://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/Sys/PETSC_COMM_WORLD.html#PETSC_COMM_WORLD>,
&A);
MatSetSizes<http://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/Mat/MatSetSizes.html#MatSetSizes>(A,
PETSC_DECIDE<http://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/Sys/PETSC_DECIDE.html#PETSC_DECIDE>,
PETSC_DECIDE<http://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/Sys/PETSC_DECIDE.html#PETSC_DECIDE>,
N, N);
MatSetFromOptions<http://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/Mat/MatSetFromOptions.html#MatSetFromOptions>
(A);
MatSeqAIJSetPreallocation<http://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/Mat/MatMPIAIJSetPreallocation.html#MatMPIAIJSetPreallocation>(A,
0, d_nnz);
PetscFree<http://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/Sys/PetscFree.html#PetscFree>
(d_nnz);
However, by doing this I noticed that it became really slow during
SetValues stage and the reason is that it was allocating memory.
[0]PETSC ERROR: MatSetValues_SeqAIJ() line 353 in
src/mat/impls/aij/seq/aij.c
[0]PETSC ERROR: MatSetValues() line 1106 in src/mat/interface/matrix.c
[0]PETSC ERROR: --------------------- Error Message
------------------------------------
sumintoj: 7980
[0]PETSC ERROR: Argument out of range!
[0]PETSC ERROR: New nonzero at (79800,79800) caused a malloc!
The problem went away after I did
PetscInt d_nz = max(d_nnz);
MatSeqAIJSetPreallocation<http://www.mcs.anl.gov/petsc/petsc-current/docs/manualpages/Mat/MatMPIAIJSetPreallocation.html#MatMPIAIJSetPreallocation>(A,
d_nz,
d_nnz);
But like I mentioned the size of nnz varied and it can be very different
from row to row and it ran out memory pretty quick if the problem is large.
I have checked my d_nnz array and it is correct and I wonder someone can
point out anything I missed.
Thanks for the help,
Kan
--
*Cheers*
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20131016/40a7d6ad/attachment.html>
More information about the petsc-users
mailing list