Re: [petsc-users] Error handling in petsc4py

2023-11-27 Thread Jose E. Roman
The exception has been caught and the execution reaches the print() statement. I think you just need to disable the PETSc error handler, try with this: PETSc.Sys.pushErrorHandler("ignore") Jose > El 27 nov 2023, a las 16:41, Barry Smith escribió: > > > I see > > cdef extern from *

Re: [petsc-users] Error handling in petsc4py

2023-11-27 Thread Barry Smith
I see cdef extern from * nogil: ctypedef enum PetscErrorCode: PETSC_SUCCESS PETSC_ERR_PLIB PETSC_ERR_SUP PETSC_ERR_USER PETSC_ERR_MEM PETSC_ERR_MPI PETSC_ERR_PYTHON ctypedef enum PetscErrorType: PETSC_ERROR_INITIAL PETSC_ERROR_REPEAT cdef

Re: [petsc-users] Error handling in petsc4py

2023-11-27 Thread Miguel Angel Salazar de Troya
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.sala...@corintis.com> wrote: > Hello, > > The

[petsc-users] Error handling in petsc4py

2023-11-15 Thread Miguel Angel Salazar de Troya
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

Re: [petsc-users] error handling

2020-01-21 Thread Smith, Barry F. via petsc-users
Yes, it is essentially like a system error. Barry > On Jan 21, 2020, at 10:49 AM, Sam Guo wrote: > > I use PETSc from my application. Sounds you are saying I just treat ierr!=0 > as an system error and no need to call Destroy functions. > > On Tuesday, January 21, 2020, Smith, Barry

Re: [petsc-users] error handling

2020-01-21 Thread Sam Guo
Thanks. On Tue, Jan 21, 2020 at 11:03 AM Jeremy Theler wrote: > Dear Sam > > Probably you are already aware of the following paragraph, but just in > case. Quote from > https://www.gnu.org/prep/standards/standards.html#Memory-Usage > > > Memory analysis tools such as valgrind can be useful, but

Re: [petsc-users] error handling

2020-01-21 Thread Jed Brown
Jeremy Theler writes: > Dear Sam > > Probably you are already aware of the following paragraph, but just in > case. Quote from > https://www.gnu.org/prep/standards/standards.html#Memory-Usage > > > Memory analysis tools such as valgrind can be useful, but don’t > complicate a program merely to

Re: [petsc-users] error handling

2020-01-21 Thread Jeremy Theler
Dear Sam Probably you are already aware of the following paragraph, but just in case. Quote from https://www.gnu.org/prep/standards/standards.html#Memory-Usage Memory analysis tools such as valgrind can be useful, but don’t complicate a program merely to avoid their false alarms. For example,

Re: [petsc-users] error handling

2020-01-21 Thread Sam Guo
I use PETSc from my application. Sounds you are saying I just treat ierr!=0 as an system error and no need to call Destroy functions. On Tuesday, January 21, 2020, Smith, Barry F. wrote: > > > > On Jan 20, 2020, at 6:32 PM, Sam Guo wrote: > > > > Hi Barry, > > I understand ierr != 0 means

Re: [petsc-users] error handling

2020-01-21 Thread Smith, Barry F. via petsc-users
> On Jan 20, 2020, at 6:32 PM, Sam Guo wrote: > > Hi Barry, > I understand ierr != 0 means something catastrophic. I just want to > release all memory before I exit PETSc. In general not possible. If you run with the debug version and -malloc_debug it is possible but because of the

Re: [petsc-users] error handling

2020-01-21 Thread Patrick Sanan
Just to clarify: are you using PETSc within some larger application, which you are hoping to continue executing, even after PETSc produces an error? Am Di., 21. Jan. 2020 um 01:33 Uhr schrieb Sam Guo : > Hi Barry, > I understand ierr != 0 means something catastrophic. I just want to > release

Re: [petsc-users] error handling

2020-01-20 Thread Sam Guo
Hi Barry, I understand ierr != 0 means something catastrophic. I just want to release all memory before I exit PETSc. Thanks, Sam On Mon, Jan 20, 2020 at 4:06 PM Smith, Barry F. wrote: > > Sam, > > I am not sure what your goal is but PETSc error return codes are error > return codes

Re: [petsc-users] error handling

2020-01-20 Thread Smith, Barry F. via petsc-users
Sam, I am not sure what your goal is but PETSc error return codes are error return codes not exceptions. They mean that something catastrophic happened and there is no recovery. Note that PETSc solvers do not return nonzero error codes on failure to converge etc. You call, for

Re: [petsc-users] error handling

2020-01-20 Thread Matthew Knepley
Not if you initialize the pointers to zero: Mat A = NULL. Matt On Mon, Jan 20, 2020 at 6:31 PM Sam Guo wrote: > I mean MatDestroy. > > On Mon, Jan 20, 2020 at 3:28 PM Sam Guo wrote: > >> Does it hurt to call Destroy function without calling CreateFunction? For >> example >> Mat A, B; >> >>

Re: [petsc-users] error handling

2020-01-20 Thread Sam Guo
I mean MatDestroy. On Mon, Jan 20, 2020 at 3:28 PM Sam Guo wrote: > Does it hurt to call Destroy function without calling CreateFunction? For > example > Mat A, B; > > PetscErrorCode > >

Re: [petsc-users] error handling

2020-01-20 Thread Sam Guo
Does it hurt to call Destroy function without calling CreateFunction? For example Mat A, B; PetscErrorCode ierr1, ierr2; ierr1 = MatCreate

Re: [petsc-users] error handling

2020-01-20 Thread Dave May
On Mon 20. Jan 2020 at 19:47, Sam Guo wrote: > Can I assume if there is MatCreat or VecCreate, I should clean up the > memory myself? > Yes. You will need to call the matching Destroy function. > On Mon, Jan 20, 2020 at 10:45 AM Sam Guo wrote: > >> I only include the first few lines of

Re: [petsc-users] error handling

2020-01-20 Thread Sam Guo
Can I assume if there is MatCreat or VecCreate, I should clean up the memory myself? On Mon, Jan 20, 2020 at 10:45 AM Sam Guo wrote: > I only include the first few lines of SLEPc example. What about following > ierr = MatCreate(PETSC_COMM_WORLD,);CHKERRQ(ierr); > ierr =

Re: [petsc-users] error handling

2020-01-20 Thread Sam Guo
I only include the first few lines of SLEPc example. What about following ierr = MatCreate(PETSC_COMM_WORLD,);CHKERRQ(ierr); ierr = MatSetSizes(A,PETSC_DECIDE,PETSC_DECIDE,n,n);CHKERRQ(ierr); Is there any memory lost? On Mon, Jan 20, 2020 at 10:41 AM Dave May wrote: > > > On Mon 20. Jan

Re: [petsc-users] error handling

2020-01-20 Thread Dave May
On Mon 20. Jan 2020 at 19:39, Sam Guo wrote: > I don't have a specific case yet. Currently every call of PETSc is > checked. If ierr is not zero, print the error and return. For example, >Mat A; /* problem matrix */ >EPS eps; /* eigenproblem solver context */ >EPSType type; >

Re: [petsc-users] error handling

2020-01-20 Thread Sam Guo
I don't have a specific case yet. Currently every call of PETSc is checked. If ierr is not zero, print the error and return. For example, Mat A; /* problem matrix */ EPS eps; /* eigenproblem solver context */ EPSType type; PetscReal error,tol,re,im; PetscScalar kr,ki; Vec xr,xi; 25

Re: [petsc-users] error handling

2020-01-20 Thread Dave May
On Mon 20. Jan 2020 at 19:11, Sam Guo wrote: > Dear PETSc dev team, >If PETSc function returns an error, what's the correct way to clean > PETSc? > The answer depends on the error message reported. Send the complete error message and a better answer can be provided. Particularly how to

[petsc-users] error handling

2020-01-20 Thread Sam Guo
Dear PETSc dev team, If PETSc function returns an error, what's the correct way to clean PETSc? Particularly how to clean up the memory? Thanks, Sam