[petsc-users] Error handling in petsc4py

Miguel Angel Salazar de Troya miguel.salazar at corintis.com
Mon Nov 27 02:46:08 CST 2023


Hello,

Is there any way to get the PETSc error codes in the python interface? The
test I provided below is just a simple example that I know will run out of
memory.

Miguel

On Wed, Nov 15, 2023 at 10:00 AM Miguel Angel Salazar de Troya <
miguel.salazar at corintis.com> wrote:

> Hello,
>
> The following simple petsc4py snippet runs out of memory, but I would
> like to handle it from python with the usual try-except. Is there any way
> to do so? How can I get the PETSc error codes in the python interface?
>
> Thanks
>
> from petsc4py import PETSc
> import sys, petsc4py
> petsc4py.init(sys.argv)
> try:
>     m, n = 1000000, 1000000
>     A = PETSc.Mat().createAIJ([m, n], nnz=1e6)
>
>     A.assemblyBegin()
>     A.assemblyEnd()
> except Exception as e:
>     print(f"An error occurred: {e}")
>
> An error occurred: error code 55
> [0] MatSeqAIJSetPreallocation() at
> /Users/miguel/repos/firedrake-glacierware/src/petsc/src/mat/impls/aij/seq/aij.c:3942
> [0] MatSeqAIJSetPreallocation_SeqAIJ() at
> /Users/miguel/repos/firedrake-glacierware/src/petsc/src/mat/impls/aij/seq/aij.c:4008
> [0] PetscMallocA() at
> /Users/miguel/repos/firedrake-glacierware/src/petsc/src/sys/memory/mal.c:408
> [0] PetscMallocAlign() at
> /Users/miguel/repos/firedrake-glacierware/src/petsc/src/sys/memory/mal.c:53
> [0] Out of memory. Allocated: 0, Used by process: 59752448
> [0] Memory requested 18446744064984991744
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20231127/6ac1541f/attachment.html>


More information about the petsc-users mailing list