<div dir="ltr"><div><span class="gmail_signature_prefix">Hello,</span></div><div><span class="gmail_signature_prefix"><br></span></div><div><span class="gmail_signature_prefix">The following </span><span class="gmail_signature_prefix">simple petsc4py </span><span class="gmail_signature_prefix">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?</span></div><div><span class="gmail_signature_prefix"><br></span></div><div><span class="gmail_signature_prefix">Thanks<br></span></div><div><span class="gmail_signature_prefix"><br></span></div><div>from petsc4py import PETSc<br>import sys, petsc4py<br>petsc4py.init(sys.argv)<br>try:<br>    m, n = 1000000, 1000000<br>    A = PETSc.Mat().createAIJ([m, n], nnz=1e6)<br>   <br>    A.assemblyBegin()<br>    A.assemblyEnd()<br>except Exception as e:<br>    print(f"An error occurred: {e}")<br></div><div><br></div><div>An error occurred: error code 55<br>[0] MatSeqAIJSetPreallocation() at /Users/miguel/repos/firedrake-glacierware/src/petsc/src/mat/impls/aij/seq/aij.c:3942<br>[0] MatSeqAIJSetPreallocation_SeqAIJ() at /Users/miguel/repos/firedrake-glacierware/src/petsc/src/mat/impls/aij/seq/aij.c:4008<br>[0] PetscMallocA() at /Users/miguel/repos/firedrake-glacierware/src/petsc/src/sys/memory/mal.c:408<br>[0] PetscMallocAlign() at /Users/miguel/repos/firedrake-glacierware/src/petsc/src/sys/memory/mal.c:53<br>[0] Out of memory. Allocated: 0, Used by process: 59752448<br>[0] Memory requested 18446744064984991744</div><div><span class="gmail_signature_prefix"></span></div><div dir="ltr" class="gmail_signature" data-smartmail="gmail_signature"><table><tbody><tr><td height="1" width="500" style="line-height:1px"><br></td> </tr></tbody></table> <table cellpadding="0" cellspacing="0" border="0" style="float:none;font-size:12px;font-family:sans-serif;color:#626262;border-collapse:collapse"><tbody><tr> <td height="5" width="100%" style="font-size:5px;line-height:5px">   </td> </tr></tbody></table>   <table><tbody><tr> <td height="1" width="500" style="line-height:1px"> <img src="https://cdn.signite.io/static/spacer.gif" width="500" height="1" border="0" style="display:block" alt=""> </td> </tr> </tbody></table></div></div>