[petsc-users] Question about using MatCreateAIJ

Matthew Knepley knepley at gmail.com
Thu Jun 15 09:51:19 CDT 2023


On Thu, Jun 15, 2023 at 8:32 AM Karsten Lettmann <
karsten.lettmann at uni-oldenburg.de> wrote:

> Dear all,
>
>
> I'm quite new to PETSC. So I hope the following questions are not too
> stupid.
>
>
> 1) We have a (Fortran) code, that we want to update from an older PETSC
> version (petsc.2.3.3-p16) to a newer version.
>
> Inside the old code, for creating matrices A, there are function calls
> of the from:
> MatCreateMPIAIJ
>
> In the reference page for this old version it says:
> When calling this routine with a single process communicator, a matrix
> of type SEQAIJ is returned.
>
> So I assume the following behavior of this old routine:
> - for N_proc == 1:
>     a matrix of type SEQAIJ is returned.
>
> - for N_proc > 1:
>     a matrix of type MPIAIJ is returned
>
>
>
> 2a) So, in the new code, we want to have a similar behavior.
>
> I found that this function is not present any more in the newer PETSC
> versions.
>
> Instead, one might use: MatCreateAIJ(….)
> ( https://petsc.org/release/manualpages/Mat/MatCreateAIJ/ )
>
> If I understand the reference page of the function correctly, then,
> actually, a similar behavior should be expected:
>
> - for N_proc == 1:
>     a matrix of type SEQAIJ is returned.
>
> - for N_proc > 1:
>     a matrix of type MPIAIJ is returned
>
>
> 2b) However, on the reference page, there is the note:
>
> It is recommended that one use the MatCreate(), MatSetType() and/or
> MatSetFromOptions(), MatXXXXSetPreallocation() paradigm instead of this
> routine directly.
>
> So, if I want the behavior above, it is recommended to code it like
> this, isn't it:
>
> If (N_Proc == 1)
>
>      MatCreate(.. ,A ,...)
>      MatSetType(…,A, MATSEQAIJ,..)
>      MatSetSizes(…,A, ..)
>      MatSeqAIJSetPreallocation(,...A,...)
>
> else
>
>      MatCreate(.. ,A ,...)
>      MatSetType(…,A, MATMPIAIJ,..)
>      MatSetSizes(…,A, ..)
>      MatMPIAIJSetPreallocation(,...A,...)
>

You can use

  MatCreate(comm, &A);
  MatSetType(A, MATAIJ);
  MatSetSizes(A, ...);
  MatXAIJSetPreallocation(A, ...);

We recommend this because we would like to get rid of the convenience
functions that
wrap up exactly this code.

  Thanks,

     Matt


> end
>
>
>
> 3) So my questions are:
>
> - Is my present understanding correct?
>
> If  yes:
>
> - Why might using MatCreateAIJ(….) for my case not be helpful?
>
> - So, why is it recommended to use the way 2b) instead of this
> MatCreateAIJ(….) ?
>
>
> Best, Karsten
>
>
>
>
> --
> ICBM
> Section: Physical Oceanography
> Universitaet Oldenburg
> Postfach 5634
> D-26046 Oldenburg
> Germany
>
> Tel:    +49 (0)441 798 4061
> email:  karsten.lettmann at uni-oldenburg.de
>
>

-- 
What most experimenters take for granted before they begin their
experiments is infinitely more interesting than any results to which their
experiments lead.
-- Norbert Wiener

https://www.cse.buffalo.edu/~knepley/ <http://www.cse.buffalo.edu/~knepley/>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20230615/6ba654f8/attachment-0001.html>


More information about the petsc-users mailing list