[petsc-users] About the use of MatMPIAIJSetPreallocation in 3.3

Barry Smith bsmith at mcs.anl.gov
Wed Nov 7 11:34:20 CST 2012


   Normally we expect the user, based on grid information, etc to decide how many rows to assign to each process. Thus they have the local sizes to pass to the Mat. 

   If you want to have PETSc decide how many rows to assign to each process you can call PetscSplitOwnership() to determine the number of rows to be assigned for each process.

   Barry

On Nov 7, 2012, at 8:43 AM, w_ang_temp <w_ang_temp at 163.com> wrote:

> Hello,
>     Version3.3 makes some change on Preallocation.
>     (1)In version 3.2, my codes are as follows:
>       
>     call MatGetOwnershipRange(A,Istart,Iend,ierr)
>       !premalloc
>       !find the max non-zero numbers of all rows
>        maxnonzero=0
>        do 19,II=Istart+1,Iend
>         !no-zero numbers of this row
>         maxnonzeroII=NROWIN(II+1)-NROWIN(II)
>         if (maxnonzeroII>maxnonzero) then
>         maxnonzero=maxnonzeroII
>         endif
>   19  continue
>        call MatMPIAIJSetPreallocation(A,maxnonzero,PETSC_NULL_INTEGER,maxnonzero,PETSC_NULL_INTEGER,ierr)
>  
>     (2)In version 3.3, my codes are as follows:
>      
>       !premalloc
>       !find the max non-zero numbers of all rows
>        maxnonzero=0
>        do 19,II=1,m
>         !no-zero numbers of this row
>         maxnonzeroII=NROWIN(II+1)-NROWIN(II)
>         if (maxnonzeroII>maxnonzero) then
>         maxnonzero=maxnonzeroII
>         endif
>   19  continue
>        call MatMPIAIJSetPreallocation(A,maxnonzero,PETSC_NULL_INTEGER,maxnonzero,PETSC_NULL_INTEGER,ierr)
>       call MatGetOwnershipRange(A,Istart,Iend,ierr)
> 
>      The modification is:in version3.3, MatMPIAIJSetPreallocation must be in the front of MatGetOwnershipRange.
> And then when I call MatMPIAIJSetPreallocation, I cannot get "Istart&Iend". So I have to use "do 19,II=1,m"
> instead of "do 19,II=Istart+1,Iend" to get the maximum non-zero number of all rows for the use of
> MatMPIAIJSetPreallocation.
>     Is this reasonable of using MatMPIAIJSetPreallocation?
>     Thanks.
>                                                               Jim
> 
> 



More information about the petsc-users mailing list