[petsc-users] Error handling in petsc4py

Miguel Angel Salazar de Troya miguel.salazar at corintis.com
Wed Nov 15 03:00:21 CST 2023


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/20231115/b4295faa/attachment.html>


More information about the petsc-users mailing list