[petsc-users] Question about using MatCreateAIJ
Karsten Lettmann
karsten.lettmann at uni-oldenburg.de
Wed Jun 14 02:14:22 CDT 2023
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,...)
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
More information about the petsc-users
mailing list