xref: /petsc/include/petscerror.h (revision 589f383f811c8b7ec29f4b3e209b48de134b606e)
154a8ef01SBarry Smith /*
2f621e05eSBarry Smith     Contains all error handling interfaces for PETSc.
354a8ef01SBarry Smith */
426bd1501SBarry Smith #if !defined(PETSCERROR_H)
526bd1501SBarry Smith #define PETSCERROR_H
66c7e564aSBarry Smith 
754a8ef01SBarry Smith /*
8329ffe3dSLois Curfman McInnes      These are the generic error codes. These error codes are used
9e2d1d2b7SBarry Smith      many different places in the PETSc source code. The string versions are
100e5e90baSSatish Balay      at src/sys/error/err.c any changes here must also be made there
11e951c290SBarry Smith      These are also define in src/sys/f90-mod/petscerror.h any CHANGES here
120f9cf654SBarry Smith      must be also made there.
1345d48df9SBarry Smith 
1454a8ef01SBarry Smith */
152a6744ebSBarry Smith #define PETSC_ERR_MIN_VALUE        54   /* should always be one less then the smallest value */
162a6744ebSBarry Smith 
1745d48df9SBarry Smith #define PETSC_ERR_MEM              55   /* unable to allocate requested memory */
1847794344SBarry Smith #define PETSC_ERR_SUP              56   /* no support for requested operation */
19e2d1d2b7SBarry Smith #define PETSC_ERR_SUP_SYS          57   /* no support for requested operation on this computer system */
20e2d1d2b7SBarry Smith #define PETSC_ERR_ORDER            58   /* operation done in wrong order */
2145d48df9SBarry Smith #define PETSC_ERR_SIG              59   /* signal received */
22f1caa5a4SBarry Smith #define PETSC_ERR_FP               72   /* floating point exception */
23a8c6a408SBarry Smith #define PETSC_ERR_COR              74   /* corrupted PETSc object */
24a8c6a408SBarry Smith #define PETSC_ERR_LIB              76   /* error in library called by PETSc */
25329ffe3dSLois Curfman McInnes #define PETSC_ERR_PLIB             77   /* PETSc library generated inconsistent data */
26329ffe3dSLois Curfman McInnes #define PETSC_ERR_MEMC             78   /* memory corruption */
27b3cc6726SBarry Smith #define PETSC_ERR_CONV_FAILED      82   /* iterative method (KSP or SNES) failed */
281302d50aSBarry Smith #define PETSC_ERR_USER             83   /* user has not provided needed function */
294e2ffeddSBarry Smith #define PETSC_ERR_SYS              88   /* error in system call */
30a8b45ee7SBarry Smith #define PETSC_ERR_POINTER          70   /* pointer does not point to valid address */
313d96e996SBarry Smith #define PETSC_ERR_MPI_LIB_INCOMP   87   /* MPI library at runtime is not compatible with MPI user compiled with */
3245d48df9SBarry Smith 
3345d48df9SBarry Smith #define PETSC_ERR_ARG_SIZ          60   /* nonconforming object sizes used in operation */
3445d48df9SBarry Smith #define PETSC_ERR_ARG_IDN          61   /* two arguments not allowed to be the same */
35a8c6a408SBarry Smith #define PETSC_ERR_ARG_WRONG        62   /* wrong argument (but object probably ok) */
3645d48df9SBarry Smith #define PETSC_ERR_ARG_CORRUPT      64   /* null or corrupted PETSc object as argument */
3745d48df9SBarry Smith #define PETSC_ERR_ARG_OUTOFRANGE   63   /* input argument, out of range */
384f227f7cSBarry Smith #define PETSC_ERR_ARG_BADPTR       68   /* invalid pointer argument */
394f227f7cSBarry Smith #define PETSC_ERR_ARG_NOTSAMETYPE  69   /* two args must be same object type */
406831982aSBarry Smith #define PETSC_ERR_ARG_NOTSAMECOMM  80   /* two args must be same communicators */
41d252947aSBarry Smith #define PETSC_ERR_ARG_WRONGSTATE   73   /* object in argument is in wrong state, e.g. unassembled mat */
428cda6cd7SBarry Smith #define PETSC_ERR_ARG_TYPENOTSET   89   /* the type of the object has not yet been set */
43a8c6a408SBarry Smith #define PETSC_ERR_ARG_INCOMP       75   /* two arguments are incompatible */
444482741eSBarry Smith #define PETSC_ERR_ARG_NULL         85   /* argument is null that should not be */
45958c9bccSBarry Smith #define PETSC_ERR_ARG_UNKNOWN_TYPE 86   /* type name doesn't match any registered type */
464f227f7cSBarry Smith 
474f227f7cSBarry Smith #define PETSC_ERR_FILE_OPEN        65   /* unable to open file */
484f227f7cSBarry Smith #define PETSC_ERR_FILE_READ        66   /* unable to read from file */
494f227f7cSBarry Smith #define PETSC_ERR_FILE_WRITE       67   /* unable to write to file */
50a8c6a408SBarry Smith #define PETSC_ERR_FILE_UNEXPECTED  79   /* unexpected data in file */
5145d48df9SBarry Smith 
52329ffe3dSLois Curfman McInnes #define PETSC_ERR_MAT_LU_ZRPVT     71   /* detected a zero pivot during LU factorization */
539e3b2f23SBarry Smith #define PETSC_ERR_MAT_CH_ZRPVT     81   /* detected a zero pivot during Cholesky factorization */
5454a8ef01SBarry Smith 
5568e69593SBarry Smith #define PETSC_ERR_INT_OVERFLOW     84
563855c12bSBarry Smith 
57bf3909cdSBarry Smith #define PETSC_ERR_FLOP_COUNT       90
58e113a28aSBarry Smith #define PETSC_ERR_NOT_CONVERGED    91  /* solver did not converge */
5992e8f287SBarry Smith #define PETSC_ERR_MISSING_FACTOR   92  /* MatGetFactor() failed */
60691b26d3SBarry Smith #define PETSC_ERR_OPT_OVERWRITE    93  /* attempted to over write options which should not be changed */
61691b26d3SBarry Smith #define PETSC_ERR_WRONG_MPI_SIZE   94  /* example/application run with number of MPI ranks it does not support */
62691b26d3SBarry Smith #define PETSC_ERR_USER_INPUT       95  /* missing or incorrect user input */
63*589f383fSBarry Smith #define PETSC_ERR_GPU_RESOURCE     96  /* unable to load a GPU resource, for example cuBLAS */
64*589f383fSBarry Smith #define PETSC_ERR_GPU              97  /* An error from a GPU call, this may be due to lack of resources on the GPU or a true error in the call */
65*589f383fSBarry Smith #define PETSC_ERR_MAX_VALUE        98  /* this is always the one more than the largest error code */
66b9eb5ee8SHong Zhang 
6759aaf355SLisandro Dalcin #define PetscStringizeArg(a) #a
6859aaf355SLisandro Dalcin #define PetscStringize(a) PetscStringizeArg(a)
69330cf3c9SBarry Smith 
70e8b7e333SSatish Balay 
7130de9b25SBarry Smith /*MC
721957e957SBarry Smith    SETERRQ - Macro to be called when an error has been detected,
7330de9b25SBarry Smith 
7430de9b25SBarry Smith    Synopsis:
75aaa7dc30SBarry Smith    #include <petscsys.h>
763af045c5SBarry Smith    PetscErrorCode SETERRQ(MPI_Comm comm,PetscErrorCode ierr,char *message)
7730de9b25SBarry Smith 
78d083f849SBarry Smith    Collective
7930de9b25SBarry Smith 
8030de9b25SBarry Smith    Input Parameters:
813af045c5SBarry Smith +  comm - A communicator, use PETSC_COMM_SELF unless you know all ranks of another communicator will detect the error
823af045c5SBarry Smith .  ierr - nonzero error code, see the list of standard error codes in include/petscerror.h
8330de9b25SBarry Smith -  message - error message
8430de9b25SBarry Smith 
8530de9b25SBarry Smith   Level: beginner
8630de9b25SBarry Smith 
8730de9b25SBarry Smith    Notes:
8830de9b25SBarry Smith     Once the error handler is called the calling function is then returned from with the given error code.
8930de9b25SBarry Smith 
9030de9b25SBarry Smith     See SETERRQ1(), SETERRQ2(), SETERRQ3() for versions that take arguments
9130de9b25SBarry Smith 
9230de9b25SBarry Smith     Experienced users can set the error handler with PetscPushErrorHandler().
9330de9b25SBarry Smith 
943b1008b8SBarry Smith    Fortran Notes:
953b1008b8SBarry Smith       SETERRQ() may be called from Fortran subroutines but SETERRA() must be called from the
963b1008b8SBarry Smith       Fortran main program.
973b1008b8SBarry Smith 
9891d3bdf4SKris Buschelman .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), CHKERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2(), SETERRQ3()
9930de9b25SBarry Smith M*/
1003af045c5SBarry Smith #define SETERRQ(comm,ierr,s) return PetscError(comm,__LINE__,PETSC_FUNCTION_NAME,__FILE__,ierr,PETSC_ERROR_INITIAL,s)
101986eef2eSBarry Smith 
102986eef2eSBarry Smith /*MC
103986eef2eSBarry Smith    SETERRMPI - Macro to be called when an error has been detected within an MPI callback function
104986eef2eSBarry Smith 
105986eef2eSBarry Smith    Synopsis:
106986eef2eSBarry Smith    #include <petscsys.h>
107986eef2eSBarry Smith    PetscErrorCode SETERRMPI(MPI_Comm comm,PetscErrorCode ierr,char *message)
108986eef2eSBarry Smith 
109d083f849SBarry Smith    Collective
110986eef2eSBarry Smith 
111986eef2eSBarry Smith    Input Parameters:
112986eef2eSBarry Smith +  comm - A communicator, use PETSC_COMM_SELF unless you know all ranks of another communicator will detect the error
113986eef2eSBarry Smith .  ierr - nonzero error code, see the list of standard error codes in include/petscerror.h
114986eef2eSBarry Smith -  message - error message
115986eef2eSBarry Smith 
116986eef2eSBarry Smith   Level: developer
117986eef2eSBarry Smith 
118986eef2eSBarry Smith    Notes:
119986eef2eSBarry Smith     This macro is FOR USE IN MPI CALLBACK FUNCTIONS ONLY, such as those passed to MPI_Comm_create_keyval(). It always returns the error code PETSC_MPI_ERROR_CODE
120986eef2eSBarry Smith     which is registered with MPI_Add_error_code() when PETSc is initialized.
121986eef2eSBarry Smith 
122986eef2eSBarry Smith .seealso: SETERRQ(), CHKERRQ(), CHKERRMPI(), PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), CHKERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2(), SETERRQ3()
123986eef2eSBarry Smith M*/
12412801b39SBarry Smith #define SETERRMPI(comm,ierr,s) return (PetscError(comm,__LINE__,PETSC_FUNCTION_NAME,__FILE__,ierr,PETSC_ERROR_INITIAL,s),PETSC_MPI_ERROR_CODE)
12530de9b25SBarry Smith 
12630de9b25SBarry Smith /*MC
12730de9b25SBarry Smith    SETERRQ1 - Macro that is called when an error has been detected,
12830de9b25SBarry Smith 
12930de9b25SBarry Smith    Synopsis:
130aaa7dc30SBarry Smith    #include <petscsys.h>
1313af045c5SBarry Smith    PetscErrorCode SETERRQ1(MPI_Comm comm,PetscErrorCode ierr,char *formatmessage,arg)
13230de9b25SBarry Smith 
133d083f849SBarry Smith    Collective
13430de9b25SBarry Smith 
13530de9b25SBarry Smith    Input Parameters:
136fa190f98SMatthew G. Knepley +  comm - A communicator, so that the error can be collective
1373af045c5SBarry Smith .  ierr - nonzero error code, see the list of standard error codes in include/petscerror.h
13830de9b25SBarry Smith .  message - error message in the printf format
13930de9b25SBarry Smith -  arg - argument (for example an integer, string or double)
14030de9b25SBarry Smith 
14130de9b25SBarry Smith   Level: beginner
14230de9b25SBarry Smith 
14330de9b25SBarry Smith    Notes:
14430de9b25SBarry Smith     Once the error handler is called the calling function is then returned from with the given error code.
14530de9b25SBarry Smith 
14630de9b25SBarry Smith    Experienced users can set the error handler with PetscPushErrorHandler().
14730de9b25SBarry Smith 
14891d3bdf4SKris Buschelman .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), CHKERRQ(), CHKMEMQ, SETERRQ(), SETERRQ2(), SETERRQ3()
14930de9b25SBarry Smith M*/
1503af045c5SBarry Smith #define SETERRQ1(comm,ierr,s,a1) return PetscError(comm,__LINE__,PETSC_FUNCTION_NAME,__FILE__,ierr,PETSC_ERROR_INITIAL,s,a1)
15130de9b25SBarry Smith 
15230de9b25SBarry Smith /*MC
15330de9b25SBarry Smith    SETERRQ2 - Macro that is called when an error has been detected,
15430de9b25SBarry Smith 
15530de9b25SBarry Smith    Synopsis:
156aaa7dc30SBarry Smith    #include <petscsys.h>
1573af045c5SBarry Smith    PetscErrorCode SETERRQ2(MPI_Comm comm,PetscErrorCode ierr,char *formatmessage,arg1,arg2)
15830de9b25SBarry Smith 
159d083f849SBarry Smith    Collective
16030de9b25SBarry Smith 
16130de9b25SBarry Smith    Input Parameters:
162fa190f98SMatthew G. Knepley +  comm - A communicator, so that the error can be collective
1633af045c5SBarry Smith .  ierr - nonzero error code, see the list of standard error codes in include/petscerror.h
16430de9b25SBarry Smith .  message - error message in the printf format
16530de9b25SBarry Smith .  arg1 - argument (for example an integer, string or double)
16630de9b25SBarry Smith -  arg2 - argument (for example an integer, string or double)
16730de9b25SBarry Smith 
16830de9b25SBarry Smith   Level: beginner
16930de9b25SBarry Smith 
17030de9b25SBarry Smith    Notes:
17130de9b25SBarry Smith     Once the error handler is called the calling function is then returned from with the given error code.
17230de9b25SBarry Smith 
17330de9b25SBarry Smith    Experienced users can set the error handler with PetscPushErrorHandler().
17430de9b25SBarry Smith 
1756024bd2cSBarry Smith .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), CHKERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ3()
17630de9b25SBarry Smith M*/
1773af045c5SBarry Smith #define SETERRQ2(comm,ierr,s,a1,a2) return PetscError(comm,__LINE__,PETSC_FUNCTION_NAME,__FILE__,ierr,PETSC_ERROR_INITIAL,s,a1,a2)
17830de9b25SBarry Smith 
17930de9b25SBarry Smith /*MC
18030de9b25SBarry Smith    SETERRQ3 - Macro that is called when an error has been detected,
18130de9b25SBarry Smith 
18230de9b25SBarry Smith    Synopsis:
183aaa7dc30SBarry Smith    #include <petscsys.h>
1843af045c5SBarry Smith    PetscErrorCode SETERRQ3(MPI_Comm comm,PetscErrorCode ierr,char *formatmessage,arg1,arg2,arg3)
18530de9b25SBarry Smith 
186d083f849SBarry Smith    Collective
18730de9b25SBarry Smith 
18830de9b25SBarry Smith    Input Parameters:
189fa190f98SMatthew G. Knepley +  comm - A communicator, so that the error can be collective
1903af045c5SBarry Smith .  ierr - nonzero error code, see the list of standard error codes in include/petscerror.h
19130de9b25SBarry Smith .  message - error message in the printf format
19230de9b25SBarry Smith .  arg1 - argument (for example an integer, string or double)
19330de9b25SBarry Smith .  arg2 - argument (for example an integer, string or double)
19430de9b25SBarry Smith -  arg3 - argument (for example an integer, string or double)
19530de9b25SBarry Smith 
19630de9b25SBarry Smith   Level: beginner
19730de9b25SBarry Smith 
19830de9b25SBarry Smith    Notes:
19930de9b25SBarry Smith     Once the error handler is called the calling function is then returned from with the given error code.
20030de9b25SBarry Smith 
201f621e05eSBarry Smith     There are also versions for 4, 5, 6 and 7 arguments.
202f621e05eSBarry Smith 
20330de9b25SBarry Smith    Experienced users can set the error handler with PetscPushErrorHandler().
20430de9b25SBarry Smith 
2056024bd2cSBarry Smith .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), CHKERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2()
20630de9b25SBarry Smith M*/
2073af045c5SBarry Smith #define SETERRQ3(comm,ierr,s,a1,a2,a3) return PetscError(comm,__LINE__,PETSC_FUNCTION_NAME,__FILE__,ierr,PETSC_ERROR_INITIAL,s,a1,a2,a3)
20830de9b25SBarry Smith 
209fa190f98SMatthew G. Knepley /*MC
210fa190f98SMatthew G. Knepley    SETERRQ4 - Macro that is called when an error has been detected,
211fa190f98SMatthew G. Knepley 
212fa190f98SMatthew G. Knepley    Synopsis:
213fa190f98SMatthew G. Knepley    #include <petscsys.h>
21431e9e36bSSatish Balay    PetscErrorCode SETERRQ4(MPI_Comm comm,PetscErrorCode ierr,char *formatmessage,arg1,arg2,arg3,arg4)
215fa190f98SMatthew G. Knepley 
216d083f849SBarry Smith    Collective
217fa190f98SMatthew G. Knepley 
218fa190f98SMatthew G. Knepley    Input Parameters:
219fa190f98SMatthew G. Knepley +  comm - A communicator, so that the error can be collective
2203af045c5SBarry Smith .  ierr - nonzero error code, see the list of standard error codes in include/petscerror.h
221fa190f98SMatthew G. Knepley .  message - error message in the printf format
222fa190f98SMatthew G. Knepley .  arg1 - argument (for example an integer, string or double)
223fa190f98SMatthew G. Knepley .  arg2 - argument (for example an integer, string or double)
224fa190f98SMatthew G. Knepley .  arg3 - argument (for example an integer, string or double)
225fa190f98SMatthew G. Knepley -  arg4 - argument (for example an integer, string or double)
226fa190f98SMatthew G. Knepley 
227fa190f98SMatthew G. Knepley   Level: beginner
228fa190f98SMatthew G. Knepley 
229fa190f98SMatthew G. Knepley    Notes:
230fa190f98SMatthew G. Knepley     Once the error handler is called the calling function is then returned from with the given error code.
231fa190f98SMatthew G. Knepley 
232fa190f98SMatthew G. Knepley     There are also versions for 4, 5, 6 and 7 arguments.
233fa190f98SMatthew G. Knepley 
234fa190f98SMatthew G. Knepley    Experienced users can set the error handler with PetscPushErrorHandler().
235fa190f98SMatthew G. Knepley 
236fa190f98SMatthew G. Knepley .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), CHKERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2()
237fa190f98SMatthew G. Knepley M*/
2383af045c5SBarry Smith #define SETERRQ4(comm,ierr,s,a1,a2,a3,a4) return PetscError(comm,__LINE__,PETSC_FUNCTION_NAME,__FILE__,ierr,PETSC_ERROR_INITIAL,s,a1,a2,a3,a4)
239fa190f98SMatthew G. Knepley 
240fa190f98SMatthew G. Knepley /*MC
241fa190f98SMatthew G. Knepley    SETERRQ5 - Macro that is called when an error has been detected,
242fa190f98SMatthew G. Knepley 
243fa190f98SMatthew G. Knepley    Synopsis:
244fa190f98SMatthew G. Knepley    #include <petscsys.h>
24531e9e36bSSatish Balay    PetscErrorCode SETERRQ5(MPI_Comm comm,PetscErrorCode ierr,char *formatmessage,arg1,arg2,arg3,arg4,arg5)
246fa190f98SMatthew G. Knepley 
247d083f849SBarry Smith    Collective
248fa190f98SMatthew G. Knepley 
249fa190f98SMatthew G. Knepley    Input Parameters:
250fa190f98SMatthew G. Knepley +  comm - A communicator, so that the error can be collective
2513af045c5SBarry Smith .  ierr - nonzero error code, see the list of standard error codes in include/petscerror.h
252fa190f98SMatthew G. Knepley .  message - error message in the printf format
253fa190f98SMatthew G. Knepley .  arg1 - argument (for example an integer, string or double)
254fa190f98SMatthew G. Knepley .  arg2 - argument (for example an integer, string or double)
255fa190f98SMatthew G. Knepley .  arg3 - argument (for example an integer, string or double)
256fa190f98SMatthew G. Knepley .  arg4 - argument (for example an integer, string or double)
257fa190f98SMatthew G. Knepley -  arg5 - argument (for example an integer, string or double)
258fa190f98SMatthew G. Knepley 
259fa190f98SMatthew G. Knepley   Level: beginner
260fa190f98SMatthew G. Knepley 
261fa190f98SMatthew G. Knepley    Notes:
262fa190f98SMatthew G. Knepley     Once the error handler is called the calling function is then returned from with the given error code.
263fa190f98SMatthew G. Knepley 
264fa190f98SMatthew G. Knepley     There are also versions for 4, 5, 6 and 7 arguments.
265fa190f98SMatthew G. Knepley 
266fa190f98SMatthew G. Knepley    Experienced users can set the error handler with PetscPushErrorHandler().
267fa190f98SMatthew G. Knepley 
268fa190f98SMatthew G. Knepley .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), CHKERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2()
269fa190f98SMatthew G. Knepley M*/
2703af045c5SBarry Smith #define SETERRQ5(comm,ierr,s,a1,a2,a3,a4,a5) return PetscError(comm,__LINE__,PETSC_FUNCTION_NAME,__FILE__,ierr,PETSC_ERROR_INITIAL,s,a1,a2,a3,a4,a5)
271fa190f98SMatthew G. Knepley 
272fa190f98SMatthew G. Knepley /*MC
273fa190f98SMatthew G. Knepley    SETERRQ6 - Macro that is called when an error has been detected,
274fa190f98SMatthew G. Knepley 
275fa190f98SMatthew G. Knepley    Synopsis:
276fa190f98SMatthew G. Knepley    #include <petscsys.h>
27731e9e36bSSatish Balay    PetscErrorCode SETERRQ6(MPI_Comm comm,PetscErrorCode ierr,char *formatmessage,arg1,arg2,arg3,arg4,arg5,arg6)
278fa190f98SMatthew G. Knepley 
279d083f849SBarry Smith    Collective
280fa190f98SMatthew G. Knepley 
281fa190f98SMatthew G. Knepley    Input Parameters:
282fa190f98SMatthew G. Knepley +  comm - A communicator, so that the error can be collective
2833af045c5SBarry Smith .  ierr - nonzero error code, see the list of standard error codes in include/petscerror.h
284fa190f98SMatthew G. Knepley .  message - error message in the printf format
285fa190f98SMatthew G. Knepley .  arg1 - argument (for example an integer, string or double)
286fa190f98SMatthew G. Knepley .  arg2 - argument (for example an integer, string or double)
287fa190f98SMatthew G. Knepley .  arg3 - argument (for example an integer, string or double)
288fa190f98SMatthew G. Knepley .  arg4 - argument (for example an integer, string or double)
289fa190f98SMatthew G. Knepley .  arg5 - argument (for example an integer, string or double)
290fa190f98SMatthew G. Knepley -  arg6 - argument (for example an integer, string or double)
291fa190f98SMatthew G. Knepley 
292fa190f98SMatthew G. Knepley   Level: beginner
293fa190f98SMatthew G. Knepley 
294fa190f98SMatthew G. Knepley    Notes:
295fa190f98SMatthew G. Knepley     Once the error handler is called the calling function is then returned from with the given error code.
296fa190f98SMatthew G. Knepley 
297fa190f98SMatthew G. Knepley     There are also versions for 4, 5, 6 and 7 arguments.
298fa190f98SMatthew G. Knepley 
299fa190f98SMatthew G. Knepley    Experienced users can set the error handler with PetscPushErrorHandler().
300fa190f98SMatthew G. Knepley 
301fa190f98SMatthew G. Knepley .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), CHKERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2()
302fa190f98SMatthew G. Knepley M*/
3033af045c5SBarry Smith #define SETERRQ6(comm,ierr,s,a1,a2,a3,a4,a5,a6) return PetscError(comm,__LINE__,PETSC_FUNCTION_NAME,__FILE__,ierr,PETSC_ERROR_INITIAL,s,a1,a2,a3,a4,a5,a6)
304fa190f98SMatthew G. Knepley 
305fa190f98SMatthew G. Knepley /*MC
306fa190f98SMatthew G. Knepley    SETERRQ7 - Macro that is called when an error has been detected,
307fa190f98SMatthew G. Knepley 
308fa190f98SMatthew G. Knepley    Synopsis:
309fa190f98SMatthew G. Knepley    #include <petscsys.h>
31031e9e36bSSatish Balay    PetscErrorCode SETERRQ7(MPI_Comm comm,PetscErrorCode ierr,char *formatmessage,arg1,arg2,arg3,arg4,arg5,arg6,arg7)
311fa190f98SMatthew G. Knepley 
312d083f849SBarry Smith    Collective
313fa190f98SMatthew G. Knepley 
314fa190f98SMatthew G. Knepley    Input Parameters:
315fa190f98SMatthew G. Knepley +  comm - A communicator, so that the error can be collective
3163af045c5SBarry Smith .  ierr - nonzero error code, see the list of standard error codes in include/petscerror.h
317fa190f98SMatthew G. Knepley .  message - error message in the printf format
318fa190f98SMatthew G. Knepley .  arg1 - argument (for example an integer, string or double)
319fa190f98SMatthew G. Knepley .  arg2 - argument (for example an integer, string or double)
320fa190f98SMatthew G. Knepley .  arg3 - argument (for example an integer, string or double)
321fa190f98SMatthew G. Knepley .  arg4 - argument (for example an integer, string or double)
322fa190f98SMatthew G. Knepley .  arg5 - argument (for example an integer, string or double)
323fa190f98SMatthew G. Knepley .  arg6 - argument (for example an integer, string or double)
324fa190f98SMatthew G. Knepley -  arg7 - argument (for example an integer, string or double)
325fa190f98SMatthew G. Knepley 
326fa190f98SMatthew G. Knepley   Level: beginner
327fa190f98SMatthew G. Knepley 
328fa190f98SMatthew G. Knepley    Notes:
329fa190f98SMatthew G. Knepley     Once the error handler is called the calling function is then returned from with the given error code.
330fa190f98SMatthew G. Knepley 
331fa190f98SMatthew G. Knepley     There are also versions for 4, 5, 6 and 7 arguments.
332fa190f98SMatthew G. Knepley 
333fa190f98SMatthew G. Knepley    Experienced users can set the error handler with PetscPushErrorHandler().
334fa190f98SMatthew G. Knepley 
335fa190f98SMatthew G. Knepley .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), CHKERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2()
336fa190f98SMatthew G. Knepley M*/
3373af045c5SBarry Smith #define SETERRQ7(comm,ierr,s,a1,a2,a3,a4,a5,a6,a7) return PetscError(comm,__LINE__,PETSC_FUNCTION_NAME,__FILE__,ierr,PETSC_ERROR_INITIAL,s,a1,a2,a3,a4,a5,a6,a7)
338fa190f98SMatthew G. Knepley 
339fa190f98SMatthew G. Knepley /*MC
340fa190f98SMatthew G. Knepley    SETERRQ8 - Macro that is called when an error has been detected,
341fa190f98SMatthew G. Knepley 
342fa190f98SMatthew G. Knepley    Synopsis:
343fa190f98SMatthew G. Knepley    #include <petscsys.h>
34431e9e36bSSatish Balay    PetscErrorCode SETERRQ8(MPI_Comm comm,PetscErrorCode ierr,char *formatmessage,arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8)
345fa190f98SMatthew G. Knepley 
346d083f849SBarry Smith    Collective
347fa190f98SMatthew G. Knepley 
348fa190f98SMatthew G. Knepley    Input Parameters:
349fa190f98SMatthew G. Knepley +  comm - A communicator, so that the error can be collective
3503af045c5SBarry Smith .  ierr - nonzero error code, see the list of standard error codes in include/petscerror.h
351fa190f98SMatthew G. Knepley .  message - error message in the printf format
352fa190f98SMatthew G. Knepley .  arg1 - argument (for example an integer, string or double)
353fa190f98SMatthew G. Knepley .  arg2 - argument (for example an integer, string or double)
354fa190f98SMatthew G. Knepley .  arg3 - argument (for example an integer, string or double)
355fa190f98SMatthew G. Knepley .  arg4 - argument (for example an integer, string or double)
356fa190f98SMatthew G. Knepley .  arg5 - argument (for example an integer, string or double)
357fa190f98SMatthew G. Knepley .  arg6 - argument (for example an integer, string or double)
358fa190f98SMatthew G. Knepley .  arg7 - argument (for example an integer, string or double)
359fa190f98SMatthew G. Knepley -  arg8 - argument (for example an integer, string or double)
360fa190f98SMatthew G. Knepley 
361fa190f98SMatthew G. Knepley   Level: beginner
362fa190f98SMatthew G. Knepley 
363fa190f98SMatthew G. Knepley    Notes:
364fa190f98SMatthew G. Knepley     Once the error handler is called the calling function is then returned from with the given error code.
365fa190f98SMatthew G. Knepley 
366fa190f98SMatthew G. Knepley     There are also versions for 4, 5, 6 and 7 arguments.
367fa190f98SMatthew G. Knepley 
368fa190f98SMatthew G. Knepley    Experienced users can set the error handler with PetscPushErrorHandler().
369fa190f98SMatthew G. Knepley 
370fa190f98SMatthew G. Knepley .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), CHKERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2()
371fa190f98SMatthew G. Knepley M*/
3723af045c5SBarry Smith #define SETERRQ8(comm,ierr,s,a1,a2,a3,a4,a5,a6,a7,a8) return PetscError(comm,__LINE__,PETSC_FUNCTION_NAME,__FILE__,ierr,PETSC_ERROR_INITIAL,s,a1,a2,a3,a4,a5,a6,a7,a8)
373fa190f98SMatthew G. Knepley 
374fa190f98SMatthew G. Knepley /*MC
375ee8199e6SMatthew G. Knepley    SETERRQ9 - Macro that is called when an error has been detected,
376ee8199e6SMatthew G. Knepley 
377ee8199e6SMatthew G. Knepley    Synopsis:
378ee8199e6SMatthew G. Knepley    #include <petscsys.h>
37931e9e36bSSatish Balay    PetscErrorCode SETERRQ9(MPI_Comm comm,PetscErrorCode ierr,char *formatmessage,arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9)
380ee8199e6SMatthew G. Knepley 
381d083f849SBarry Smith    Collective
382ee8199e6SMatthew G. Knepley 
383ee8199e6SMatthew G. Knepley    Input Parameters:
384ee8199e6SMatthew G. Knepley +  comm - A communicator, so that the error can be collective
385ee8199e6SMatthew G. Knepley .  ierr - nonzero error code, see the list of standard error codes in include/petscerror.h
386ee8199e6SMatthew G. Knepley .  message - error message in the printf format
387ee8199e6SMatthew G. Knepley .  arg1 - argument (for example an integer, string or double)
388ee8199e6SMatthew G. Knepley .  arg2 - argument (for example an integer, string or double)
389ee8199e6SMatthew G. Knepley .  arg3 - argument (for example an integer, string or double)
390ee8199e6SMatthew G. Knepley .  arg4 - argument (for example an integer, string or double)
391ee8199e6SMatthew G. Knepley .  arg5 - argument (for example an integer, string or double)
392ee8199e6SMatthew G. Knepley .  arg6 - argument (for example an integer, string or double)
393ee8199e6SMatthew G. Knepley .  arg7 - argument (for example an integer, string or double)
394ee8199e6SMatthew G. Knepley .  arg8 - argument (for example an integer, string or double)
395ee8199e6SMatthew G. Knepley -  arg9 - argument (for example an integer, string or double)
396ee8199e6SMatthew G. Knepley 
397ee8199e6SMatthew G. Knepley   Level: beginner
398ee8199e6SMatthew G. Knepley 
399ee8199e6SMatthew G. Knepley    Notes:
400ee8199e6SMatthew G. Knepley     Once the error handler is called the calling function is then returned from with the given error code.
401ee8199e6SMatthew G. Knepley 
402ee8199e6SMatthew G. Knepley     There are also versions for 0 to 9 arguments.
403ee8199e6SMatthew G. Knepley 
404ee8199e6SMatthew G. Knepley    Experienced users can set the error handler with PetscPushErrorHandler().
405ee8199e6SMatthew G. Knepley 
406ee8199e6SMatthew G. Knepley .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), CHKERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2()
407ee8199e6SMatthew G. Knepley M*/
408ee8199e6SMatthew G. Knepley #define SETERRQ9(comm,ierr,s,a1,a2,a3,a4,a5,a6,a7,a8,a9) return PetscError(comm,__LINE__,PETSC_FUNCTION_NAME,__FILE__,ierr,PETSC_ERROR_INITIAL,s,a1,a2,a3,a4,a5,a6,a7,a8,a9)
409ee8199e6SMatthew G. Knepley 
410ee8199e6SMatthew G. Knepley /*MC
411fa190f98SMatthew G. Knepley    SETERRABORT - Macro that can be called when an error has been detected,
412fa190f98SMatthew G. Knepley 
413fa190f98SMatthew G. Knepley    Synopsis:
414fa190f98SMatthew G. Knepley    #include <petscsys.h>
4153af045c5SBarry Smith    PetscErrorCode SETERRABORT(MPI_Comm comm,PetscErrorCode ierr,char *message)
416fa190f98SMatthew G. Knepley 
417d083f849SBarry Smith    Collective
418fa190f98SMatthew G. Knepley 
419fa190f98SMatthew G. Knepley    Input Parameters:
420fa190f98SMatthew G. Knepley +  comm - A communicator, so that the error can be collective
4213af045c5SBarry Smith .  ierr - nonzero error code, see the list of standard error codes in include/petscerror.h
422fa190f98SMatthew G. Knepley -  message - error message in the printf format
423fa190f98SMatthew G. Knepley 
424fa190f98SMatthew G. Knepley   Level: beginner
425fa190f98SMatthew G. Knepley 
426fa190f98SMatthew G. Knepley    Notes:
427fa190f98SMatthew G. Knepley     This function just calls MPI_Abort().
428fa190f98SMatthew G. Knepley 
429fa190f98SMatthew G. Knepley .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), CHKERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2()
430fa190f98SMatthew G. Knepley M*/
4313af045c5SBarry Smith #define SETERRABORT(comm,ierr,s) do {PetscError(comm,__LINE__,PETSC_FUNCTION_NAME,__FILE__,ierr,PETSC_ERROR_INITIAL,s);MPI_Abort(comm,ierr);} while (0)
4329a00fa46SSatish Balay 
43330de9b25SBarry Smith /*MC
43430de9b25SBarry Smith    CHKERRQ - Checks error code, if non-zero it calls the error handler and then returns
43530de9b25SBarry Smith 
43630de9b25SBarry Smith    Synopsis:
437aaa7dc30SBarry Smith    #include <petscsys.h>
4383af045c5SBarry Smith    PetscErrorCode CHKERRQ(PetscErrorCode ierr)
43930de9b25SBarry Smith 
440eca87e8dSBarry Smith    Not Collective
44130de9b25SBarry Smith 
44230de9b25SBarry Smith    Input Parameters:
4433af045c5SBarry Smith .  ierr - nonzero error code, see the list of standard error codes in include/petscerror.h
44430de9b25SBarry Smith 
44530de9b25SBarry Smith   Level: beginner
44630de9b25SBarry Smith 
44730de9b25SBarry Smith    Notes:
44830de9b25SBarry Smith     Once the error handler is called the calling function is then returned from with the given error code.
44930de9b25SBarry Smith 
45030de9b25SBarry Smith     Experienced users can set the error handler with PetscPushErrorHandler().
4515324ea47SKris Buschelman 
4523af045c5SBarry Smith     CHKERRQ(ierr) is fundamentally a macro replacement for
4533af045c5SBarry Smith          if (ierr) return(PetscError(...,ierr,...));
4545324ea47SKris Buschelman 
4555324ea47SKris Buschelman     Although typical usage resembles "void CHKERRQ(PetscErrorCode)" as described above, for certain uses it is
4565324ea47SKris Buschelman     highly inappropriate to use it in this manner as it invokes return(PetscErrorCode). In particular,
4575324ea47SKris Buschelman     it cannot be used in functions which return(void) or any other datatype.  In these types of functions,
45858ebbce7SBarry Smith     you can use CHKERRV() which returns without an error code (bad idea since the error is ignored or
4593af045c5SBarry Smith          if (ierr) {PetscError(....); return(YourReturnType);}
4600298fd71SBarry Smith     where you may pass back a NULL to indicate an error. You can also call CHKERRABORT(comm,n) to have
46158ebbce7SBarry Smith     MPI_Abort() returned immediately.
46258ebbce7SBarry Smith 
46391d3bdf4SKris Buschelman .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), SETERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2(), SETERRQ2()
46430de9b25SBarry Smith M*/
465ee74f559SJed Brown #define CHKERRQ(ierr)          do {PetscErrorCode ierr__ = (ierr); if (PetscUnlikely(ierr__)) return PetscError(PETSC_COMM_SELF,__LINE__,PETSC_FUNCTION_NAME,__FILE__,ierr__,PETSC_ERROR_REPEAT," ");} while (0)
4660219f5dfSJed Brown #define CHKERRV(ierr)          do {PetscErrorCode ierr__ = (ierr); if (PetscUnlikely(ierr__)) {PetscError(PETSC_COMM_SELF,__LINE__,PETSC_FUNCTION_NAME,__FILE__,ierr__,PETSC_ERROR_REPEAT," ");return;}} while (0)
467ee74f559SJed Brown #define CHKERRABORT(comm,ierr) do {PetscErrorCode ierr__ = (ierr); if (PetscUnlikely(ierr__)) {PetscError(PETSC_COMM_SELF,__LINE__,PETSC_FUNCTION_NAME,__FILE__,ierr__,PETSC_ERROR_REPEAT," ");MPI_Abort(comm,ierr);}} while (0)
468ee74f559SJed Brown #define CHKERRCONTINUE(ierr)   do {PetscErrorCode ierr__ = (ierr); if (PetscUnlikely(ierr__)) {PetscError(PETSC_COMM_SELF,__LINE__,PETSC_FUNCTION_NAME,__FILE__,ierr__,PETSC_ERROR_REPEAT," ");}} while (0)
469986eef2eSBarry Smith 
4707c66cc67SJunchao Zhang PETSC_EXTERN PetscErrorCode PetscAbortFindSourceFile_Private(const char*,PetscInt*);
471bf4d2887SBarry Smith PETSC_EXTERN PetscBool petscwaitonerror,petscindebugger;
4727c66cc67SJunchao Zhang 
4737c66cc67SJunchao Zhang /*MC
4747c66cc67SJunchao Zhang    PETSCABORT - Call MPI_Abort with an informative error code
4757c66cc67SJunchao Zhang 
4767c66cc67SJunchao Zhang    Synopsis:
4777c66cc67SJunchao Zhang    #include <petscsys.h>
4787c66cc67SJunchao Zhang    PETSCABORT(MPI_Comm comm, PetscErrorCode ierr)
4797c66cc67SJunchao Zhang 
4807c66cc67SJunchao Zhang    Collective
4817c66cc67SJunchao Zhang 
4827c66cc67SJunchao Zhang    Input Parameters:
4837c66cc67SJunchao Zhang +  comm - A communicator, so that the error can be collective
4847c66cc67SJunchao Zhang -  ierr - nonzero error code, see the list of standard error codes in include/petscerror.h
4857c66cc67SJunchao Zhang 
486bf4d2887SBarry Smith    Level: advanced
4877c66cc67SJunchao Zhang 
488bf4d2887SBarry Smith    Notes:
489bf4d2887SBarry Smith    We pass MPI_Abort() an error code of format XX_YYYY_ZZZ, where XX, YYYY are an index and line number of the file
4907233276eSBarry Smith    where PETSCABORT is called, respectively. ZZZ is the PETSc error code.
4917c66cc67SJunchao Zhang 
4927233276eSBarry Smith    If XX is zero, this means that the call was made in the routine main().
4937233276eSBarry Smith    If XX is one, that means 1) the file is not in PETSc (it may be in users code); OR 2) the file is in PETSc but PetscAbortSourceFiles[]
4947c66cc67SJunchao Zhang      is out of date. PETSc developers have to update it.
495a0760fecSJunchao Zhang    Otherwise, look up the value of XX in the table PetscAbortSourceFiles[] in src/sys/error/err.c to map XX back to the source file where the PETSCABORT() was called.
4967233276eSBarry Smith 
497bf4d2887SBarry Smith    If the option -start_in_debugger was used then this calls abort() to stop the program in the debugger.
498bf4d2887SBarry Smith 
4997c66cc67SJunchao Zhang M*/
5007c66cc67SJunchao Zhang #define PETSCABORT(comm,ierr)  \
5017c66cc67SJunchao Zhang    do {                                                               \
5027c66cc67SJunchao Zhang       PetscInt       idx = 0;                                         \
5037c66cc67SJunchao Zhang       PetscMPIInt    errcode;                                         \
5047c66cc67SJunchao Zhang       PetscAbortFindSourceFile_Private(__FILE__,&idx);                \
5057c66cc67SJunchao Zhang       errcode = (PetscMPIInt)(idx*10000000 + __LINE__*1000 + ierr);   \
5062a2a2941SBarry Smith       if (petscwaitonerror) PetscSleep(1000);                         \
507bf4d2887SBarry Smith       if (petscindebugger) abort();                                   \
508bf4d2887SBarry Smith       else MPI_Abort(comm,errcode);                                   \
5097c66cc67SJunchao Zhang    } while (0)
510986eef2eSBarry Smith 
511986eef2eSBarry Smith /*MC
512986eef2eSBarry Smith    CHKERRMPI - Checks error code, if non-zero it calls the error handler and then returns
513986eef2eSBarry Smith 
514986eef2eSBarry Smith    Synopsis:
515986eef2eSBarry Smith    #include <petscsys.h>
516986eef2eSBarry Smith    PetscErrorCode CHKERRMPI(PetscErrorCode ierr)
517986eef2eSBarry Smith 
518986eef2eSBarry Smith    Not Collective
519986eef2eSBarry Smith 
520986eef2eSBarry Smith    Input Parameters:
521986eef2eSBarry Smith .  ierr - nonzero error code, see the list of standard error codes in include/petscerror.h
522986eef2eSBarry Smith 
523986eef2eSBarry Smith   Level: developer
524986eef2eSBarry Smith 
525986eef2eSBarry Smith    Notes:
526986eef2eSBarry Smith     This macro is FOR USE IN MPI CALLBACK FUNCTIONS ONLY, such as those passed to MPI_Comm_create_keyval(). It always returns the error code PETSC_MPI_ERROR_CODE
527986eef2eSBarry Smith     which is registered with MPI_Add_error_code() when PETSc is initialized.
528986eef2eSBarry Smith 
529986eef2eSBarry Smith .seealso: CHKERRQ(), PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), SETERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2(), SETERRQ2()
530986eef2eSBarry Smith M*/
53112801b39SBarry Smith #define CHKERRMPI(ierr)        do {if (PetscUnlikely(ierr)) return (PetscError(PETSC_COMM_SELF,__LINE__,PETSC_FUNCTION_NAME,__FILE__,ierr,PETSC_ERROR_REPEAT," "),PETSC_MPI_ERROR_CODE);} while (0)
53285614651SBarry Smith 
533fd705b32SMatthew Knepley #ifdef PETSC_CLANGUAGE_CXX
534fd705b32SMatthew Knepley 
535cc26af49SMatthew Knepley /*MC
536cc26af49SMatthew Knepley    CHKERRXX - Checks error code, if non-zero it calls the C++ error handler which throws an exception
537cc26af49SMatthew Knepley 
538cc26af49SMatthew Knepley    Synopsis:
539aaa7dc30SBarry Smith    #include <petscsys.h>
5403af045c5SBarry Smith    void CHKERRXX(PetscErrorCode ierr)
541cc26af49SMatthew Knepley 
542eca87e8dSBarry Smith    Not Collective
543cc26af49SMatthew Knepley 
544cc26af49SMatthew Knepley    Input Parameters:
5453af045c5SBarry Smith .  ierr - nonzero error code, see the list of standard error codes in include/petscerror.h
546cc26af49SMatthew Knepley 
547cc26af49SMatthew Knepley   Level: beginner
548cc26af49SMatthew Knepley 
549cc26af49SMatthew Knepley    Notes:
550cc26af49SMatthew Knepley     Once the error handler throws a ??? exception.
551cc26af49SMatthew Knepley 
552cc26af49SMatthew Knepley     You can use CHKERRV() which returns without an error code (bad idea since the error is ignored)
553cc26af49SMatthew Knepley     or CHKERRABORT(comm,n) to have MPI_Abort() returned immediately.
554cc26af49SMatthew Knepley 
555cc26af49SMatthew Knepley .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), SETERRQ(), CHKERRQ(), CHKMEMQ
556cc26af49SMatthew Knepley M*/
5573af045c5SBarry Smith #define CHKERRXX(ierr)  do {if (PetscUnlikely(ierr)) {PetscError(PETSC_COMM_SELF,__LINE__,PETSC_FUNCTION_NAME,__FILE__,ierr,PETSC_ERROR_IN_CXX,0);}} while (0)
558fd705b32SMatthew Knepley 
559fd705b32SMatthew Knepley #endif
560fd705b32SMatthew Knepley 
5617fd2f626SJose E. Roman #if defined(PETSC_HAVE_CUDA)
5627fd2f626SJose E. Roman #define CHKERRCUSOLVER(err) do {if (PetscUnlikely(err)) SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_LIB,"CUSOLVER error %d",err);} while (0)
5637fd2f626SJose E. Roman #endif
56430de9b25SBarry Smith /*MC
56530de9b25SBarry Smith    CHKMEMQ - Checks the memory for corruption, calls error handler if any is detected
56630de9b25SBarry Smith 
56730de9b25SBarry Smith    Synopsis:
568aaa7dc30SBarry Smith    #include <petscsys.h>
56991d3bdf4SKris Buschelman    CHKMEMQ;
57030de9b25SBarry Smith 
571eca87e8dSBarry Smith    Not Collective
572eca87e8dSBarry Smith 
57330de9b25SBarry Smith   Level: beginner
57430de9b25SBarry Smith 
57530de9b25SBarry Smith    Notes:
576a8d69d7bSBarry Smith     We highly recommend using valgrind https://www.mcs.anl.gov/petsc/documentation/faq.html#valgrind for finding memory problems. This is useful
5771957e957SBarry Smith     on systems that do not have valgrind, but much much less useful.
5781957e957SBarry Smith 
57979dccf82SBarry Smith     Must run with the option -malloc_debug (-malloc_test in debug mode; or if PetscMallocSetDebug() called) to enable this option
58030de9b25SBarry Smith 
58130de9b25SBarry Smith     Once the error handler is called the calling function is then returned from with the given error code.
58230de9b25SBarry Smith 
58330de9b25SBarry Smith     By defaults prints location where memory that is corrupted was allocated.
58430de9b25SBarry Smith 
585f621e05eSBarry Smith     Use CHKMEMA for functions that return void
586f621e05eSBarry Smith 
5876024bd2cSBarry Smith .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), SETERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2(), SETERRQ3(),
588ff002950SBarry Smith           PetscMallocValidate()
58930de9b25SBarry Smith M*/
590efca3c55SSatish Balay #define CHKMEMQ do {PetscErrorCode _7_ierr = PetscMallocValidate(__LINE__,PETSC_FUNCTION_NAME,__FILE__);CHKERRQ(_7_ierr);} while (0)
59185614651SBarry Smith 
592efca3c55SSatish Balay #define CHKMEMA PetscMallocValidate(__LINE__,PETSC_FUNCTION_NAME,__FILE__)
593e68848bdSBarry Smith 
594668f157eSBarry Smith /*E
595668f157eSBarry Smith   PetscErrorType - passed to the PETSc error handling routines indicating if this is the first or a later call to the error handlers
596668f157eSBarry Smith 
597668f157eSBarry Smith   Level: advanced
598668f157eSBarry Smith 
599d736bfebSBarry Smith   PETSC_ERROR_IN_CXX indicates the error was detected in C++ and an exception should be generated
600d736bfebSBarry Smith 
60195452b02SPatrick Sanan   Developer Notes:
60295452b02SPatrick Sanan     This is currently used to decide when to print the detailed information about the run in PetscTraceBackErrorHandler()
603668f157eSBarry Smith 
604d736bfebSBarry Smith .seealso: PetscError(), SETERRXX()
605668f157eSBarry Smith E*/
606d736bfebSBarry Smith typedef enum {PETSC_ERROR_INITIAL=0,PETSC_ERROR_REPEAT=1,PETSC_ERROR_IN_CXX = 2} PetscErrorType;
6074b209cf6SBarry Smith 
608eb9e708aSLisandro Dalcin #if defined(__clang_analyzer__)
609eb9e708aSLisandro Dalcin __attribute__((analyzer_noreturn))
610eb9e708aSLisandro Dalcin #endif
611eb9e708aSLisandro Dalcin PETSC_EXTERN PetscErrorCode PetscError(MPI_Comm,int,const char*,const char*,PetscErrorCode,PetscErrorType,const char*,...);
612eb9e708aSLisandro Dalcin 
613014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscErrorPrintfInitialize(void);
614014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscErrorMessage(int,const char*[],char **);
615efca3c55SSatish Balay PETSC_EXTERN PetscErrorCode PetscTraceBackErrorHandler(MPI_Comm,int,const char*,const char*,PetscErrorCode,PetscErrorType,const char*,void*);
616efca3c55SSatish Balay PETSC_EXTERN PetscErrorCode PetscIgnoreErrorHandler(MPI_Comm,int,const char*,const char*,PetscErrorCode,PetscErrorType,const char*,void*);
617efca3c55SSatish Balay PETSC_EXTERN PetscErrorCode PetscEmacsClientErrorHandler(MPI_Comm,int,const char*,const char*,PetscErrorCode,PetscErrorType,const char*,void*);
618efca3c55SSatish Balay PETSC_EXTERN PetscErrorCode PetscMPIAbortErrorHandler(MPI_Comm,int,const char*,const char*,PetscErrorCode,PetscErrorType,const char*,void*);
619efca3c55SSatish Balay PETSC_EXTERN PetscErrorCode PetscAbortErrorHandler(MPI_Comm,int,const char*,const char*,PetscErrorCode,PetscErrorType,const char*,void*);
620efca3c55SSatish Balay PETSC_EXTERN PetscErrorCode PetscAttachDebuggerErrorHandler(MPI_Comm,int,const char*,const char*,PetscErrorCode,PetscErrorType,const char*,void*);
621efca3c55SSatish Balay PETSC_EXTERN PetscErrorCode PetscReturnErrorHandler(MPI_Comm,int,const char*,const char*,PetscErrorCode,PetscErrorType,const char*,void*);
622efca3c55SSatish Balay PETSC_EXTERN PetscErrorCode PetscPushErrorHandler(PetscErrorCode (*handler)(MPI_Comm,int,const char*,const char*,PetscErrorCode,PetscErrorType,const char*,void*),void*);
623014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscPopErrorHandler(void);
6248d359177SBarry Smith PETSC_EXTERN PetscErrorCode PetscSignalHandlerDefault(int,void*);
625014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscPushSignalHandler(PetscErrorCode (*)(int,void *),void*);
626014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscPopSignalHandler(void);
62728559dc8SJed Brown PETSC_EXTERN PetscErrorCode PetscCheckPointerSetIntensity(PetscInt);
628c2a741eeSJunchao Zhang PETSC_EXTERN void PetscSignalSegvCheckPointerOrMpi(void);
629c2a741eeSJunchao Zhang PETSC_DEPRECATED_FUNCTION("Use PetscSignalSegvCheckPointerOrMpi() (since version 3.13)") PETSC_STATIC_INLINE void PetscSignalSegvCheckPointer(void) {PetscSignalSegvCheckPointerOrMpi();}
630329f5518SBarry Smith 
631639ff905SBarry Smith /*MC
632639ff905SBarry Smith     PetscErrorPrintf - Prints error messages.
633639ff905SBarry Smith 
634639ff905SBarry Smith    Synopsis:
635aaa7dc30SBarry Smith     #include <petscsys.h>
636639ff905SBarry Smith      PetscErrorCode (*PetscErrorPrintf)(const char format[],...);
637639ff905SBarry Smith 
638639ff905SBarry Smith     Not Collective
639639ff905SBarry Smith 
640639ff905SBarry Smith     Input Parameters:
641639ff905SBarry Smith .   format - the usual printf() format string
642639ff905SBarry Smith 
643639ff905SBarry Smith    Options Database Keys:
6441957e957SBarry Smith +    -error_output_stdout - cause error messages to be printed to stdout instead of the  (default) stderr
645e1bc860dSBarry Smith -    -error_output_none - to turn off all printing of error messages (does not change the way the error is handled.)
646639ff905SBarry Smith 
64795452b02SPatrick Sanan    Notes:
64895452b02SPatrick Sanan     Use
649639ff905SBarry Smith $     PetscErrorPrintf = PetscErrorPrintfNone; to turn off all printing of error messages (does not change the way the
650639ff905SBarry Smith $                        error is handled.) and
6511957e957SBarry Smith $     PetscErrorPrintf = PetscErrorPrintfDefault; to turn it back on or you can use your own function
652639ff905SBarry Smith 
653639ff905SBarry Smith           Use
654639ff905SBarry Smith      PETSC_STDERR = FILE* obtained from a file open etc. to have stderr printed to the file.
655639ff905SBarry Smith      PETSC_STDOUT = FILE* obtained from a file open etc. to have stdout printed to the file.
656639ff905SBarry Smith 
657639ff905SBarry Smith           Use
658639ff905SBarry Smith       PetscPushErrorHandler() to provide your own error handler that determines what kind of messages to print
659639ff905SBarry Smith 
660639ff905SBarry Smith    Level: developer
661639ff905SBarry Smith 
662639ff905SBarry Smith     Fortran Note:
663639ff905SBarry Smith     This routine is not supported in Fortran.
664639ff905SBarry Smith 
665639ff905SBarry Smith 
6662b60790dSJed Brown .seealso: PetscFPrintf(), PetscSynchronizedPrintf(), PetscHelpPrintf(), PetscPrintf(), PetscPushErrorHandler(), PetscVFPrintf(), PetscHelpPrintf()
667639ff905SBarry Smith M*/
668639ff905SBarry Smith PETSC_EXTERN PetscErrorCode (*PetscErrorPrintf)(const char[],...);
669639ff905SBarry Smith 
670329f5518SBarry Smith typedef enum {PETSC_FP_TRAP_OFF=0,PETSC_FP_TRAP_ON=1} PetscFPTrap;
671014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSetFPTrap(PetscFPTrap);
672014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscFPTrapPush(PetscFPTrap);
673014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscFPTrapPop(void);
674aba4c478SBarry Smith PETSC_EXTERN PetscErrorCode PetscDetermineInitialFPTrap(void);
67554a8ef01SBarry Smith 
6763a40ed3dSBarry Smith /*
6773a40ed3dSBarry Smith       Allows the code to build a stack frame as it runs
6783a40ed3dSBarry Smith */
6793a40ed3dSBarry Smith 
68099cd645aSJed Brown #define PETSCSTACKSIZE 64
681184914b5SBarry Smith 
6823a40ed3dSBarry Smith typedef struct  {
6830e33f6ddSBarry Smith   const char      *function[PETSCSTACKSIZE];
6840e33f6ddSBarry Smith   const char      *file[PETSCSTACKSIZE];
685184914b5SBarry Smith         int       line[PETSCSTACKSIZE];
686a8d2bbe5SBarry Smith         PetscBool petscroutine[PETSCSTACKSIZE];
687184914b5SBarry Smith         int       currentsize;
688a2f94806SJed Brown         int       hotdepth;
6893a40ed3dSBarry Smith } PetscStack;
6903a40ed3dSBarry Smith 
6911f46d60fSShri Abhyankar PETSC_EXTERN PetscStack *petscstack;
692184914b5SBarry Smith 
6936f5c2d7aSBarry Smith PetscErrorCode  PetscStackCopy(PetscStack*,PetscStack*);
6946f5c2d7aSBarry Smith PetscErrorCode  PetscStackPrint(PetscStack *,FILE*);
6955d12eec7SSatish Balay #if defined(PETSC_SERIALIZE_FUNCTIONS)
6965d12eec7SSatish Balay #include <petsc/private/petscfptimpl.h>
6975d12eec7SSatish Balay /*
6985d12eec7SSatish Balay    Registers the current function into the global function pointer to function name table
6995d12eec7SSatish Balay 
7005d12eec7SSatish Balay    Have to fix this to handle errors but cannot return error since used in PETSC_VIEWER_DRAW_() etc
7015d12eec7SSatish Balay */
7025d12eec7SSatish Balay #define PetscRegister__FUNCT__() do { \
7035d12eec7SSatish Balay   static PetscBool __chked = PETSC_FALSE; \
7045d12eec7SSatish Balay   if (!__chked) {\
7055d12eec7SSatish Balay   void *ptr; PetscDLSym(NULL,PETSC_FUNCTION_NAME,&ptr);\
7065d12eec7SSatish Balay   __chked = PETSC_TRUE;\
7075d12eec7SSatish Balay   }} while (0)
7085d12eec7SSatish Balay #else
7095d12eec7SSatish Balay #define PetscRegister__FUNCT__()
7105d12eec7SSatish Balay #endif
7115d12eec7SSatish Balay 
7122d7c6352SJed Brown #if defined(PETSC_USE_DEBUG)
713dbf62e16SBarry Smith PETSC_STATIC_INLINE PetscBool PetscStackActive(void)
714dbf62e16SBarry Smith {
7155c25fcd7SBarry Smith   return(petscstack ? PETSC_TRUE : PETSC_FALSE);
716dbf62e16SBarry Smith }
7173a40ed3dSBarry Smith 
718441dd030SJed Brown /* Stack handling is based on the following two "NoCheck" macros.  These should only be called directly by other error
719441dd030SJed Brown  * handling macros.  We record the line of the call, which may or may not be the location of the definition.  But is at
720441dd030SJed Brown  * least more useful than "unknown" because it can distinguish multiple calls from the same function.
721441dd030SJed Brown  */
722441dd030SJed Brown 
723a2f94806SJed Brown #define PetscStackPushNoCheck(funct,petsc_routine,hot)                        \
724441dd030SJed Brown   do {                                                                        \
725e04113cfSBarry Smith     PetscStackSAWsTakeAccess();                                                \
7265c25fcd7SBarry Smith     if (petscstack && (petscstack->currentsize < PETSCSTACKSIZE)) {         \
7275c25fcd7SBarry Smith       petscstack->function[petscstack->currentsize]  = funct;               \
7285c25fcd7SBarry Smith       petscstack->file[petscstack->currentsize]      = __FILE__;            \
7295c25fcd7SBarry Smith       petscstack->line[petscstack->currentsize]      = __LINE__;            \
7305c25fcd7SBarry Smith       petscstack->petscroutine[petscstack->currentsize] = petsc_routine;    \
7315c25fcd7SBarry Smith       petscstack->currentsize++;                                             \
732441dd030SJed Brown     }                                                                         \
7335c25fcd7SBarry Smith     if (petscstack) {                                                        \
7345c25fcd7SBarry Smith       petscstack->hotdepth += (hot || petscstack->hotdepth);                \
735a2f94806SJed Brown     }                                                                         \
736e04113cfSBarry Smith     PetscStackSAWsGrantAccess();                                               \
737441dd030SJed Brown   } while (0)
738441dd030SJed Brown 
739441dd030SJed Brown #define PetscStackPopNoCheck                                            \
7405c25fcd7SBarry Smith   do {                                                                  \
741e04113cfSBarry Smith     PetscStackSAWsTakeAccess();                                          \
7425c25fcd7SBarry Smith     if (petscstack && petscstack->currentsize > 0) {                  \
7435c25fcd7SBarry Smith       petscstack->currentsize--;                                       \
744ffc31a0eSLisandro Dalcin       petscstack->function[petscstack->currentsize]  = NULL;             \
745ffc31a0eSLisandro Dalcin       petscstack->file[petscstack->currentsize]      = NULL;             \
7465c25fcd7SBarry Smith       petscstack->line[petscstack->currentsize]      = 0;             \
7475c25fcd7SBarry Smith       petscstack->petscroutine[petscstack->currentsize] = PETSC_FALSE;\
748441dd030SJed Brown     }                                                                   \
7495c25fcd7SBarry Smith     if (petscstack) {                                                  \
7505c25fcd7SBarry Smith       petscstack->hotdepth = PetscMax(petscstack->hotdepth-1,0);      \
751a2f94806SJed Brown     }                                                                   \
752e04113cfSBarry Smith     PetscStackSAWsGrantAccess();                                         \
753441dd030SJed Brown   } while (0)
754441dd030SJed Brown 
75530de9b25SBarry Smith /*MC
7561957e957SBarry Smith    PetscFunctionBegin - First executable line of each PETSc function,  used for error handling. Final
7571957e957SBarry Smith       line of PETSc functions should be PetscFunctionReturn(0);
75830de9b25SBarry Smith 
75930de9b25SBarry Smith    Synopsis:
760aaa7dc30SBarry Smith    #include <petscsys.h>
76130de9b25SBarry Smith    void PetscFunctionBegin;
76230de9b25SBarry Smith 
763eca87e8dSBarry Smith    Not Collective
764eca87e8dSBarry Smith 
76530de9b25SBarry Smith    Usage:
76630de9b25SBarry Smith .vb
76730de9b25SBarry Smith      int something;
76830de9b25SBarry Smith 
76930de9b25SBarry Smith      PetscFunctionBegin;
77030de9b25SBarry Smith .ve
77130de9b25SBarry Smith 
77230de9b25SBarry Smith    Notes:
7731957e957SBarry Smith      Use PetscFunctionBeginUser for application codes.
7741957e957SBarry Smith 
77530de9b25SBarry Smith      Not available in Fortran
77630de9b25SBarry Smith 
77730de9b25SBarry Smith    Level: developer
77830de9b25SBarry Smith 
7791957e957SBarry Smith .seealso: PetscFunctionReturn(), PetscFunctionBeginHot(), PetscFunctionBeginUser()
78030de9b25SBarry Smith 
78130de9b25SBarry Smith M*/
782441dd030SJed Brown #define PetscFunctionBegin do {                                        \
783a2f94806SJed Brown     PetscStackPushNoCheck(PETSC_FUNCTION_NAME,PETSC_TRUE,PETSC_FALSE); \
784a2f94806SJed Brown     PetscRegister__FUNCT__();                                          \
785a2f94806SJed Brown   } while (0)
786a2f94806SJed Brown 
787a2f94806SJed Brown /*MC
788a2f94806SJed Brown    PetscFunctionBeginHot - Substitute for PetscFunctionBegin to be used in functions that are called in
789a2f94806SJed Brown    performance-critical circumstances.  Use of this function allows for lighter profiling by default.
790a2f94806SJed Brown 
791a2f94806SJed Brown    Synopsis:
792aaa7dc30SBarry Smith    #include <petscsys.h>
793a2f94806SJed Brown    void PetscFunctionBeginHot;
794a2f94806SJed Brown 
795a2f94806SJed Brown    Not Collective
796a2f94806SJed Brown 
797a2f94806SJed Brown    Usage:
798a2f94806SJed Brown .vb
799a2f94806SJed Brown      int something;
800a2f94806SJed Brown 
801a2f94806SJed Brown      PetscFunctionBeginHot;
802a2f94806SJed Brown .ve
803a2f94806SJed Brown 
804a2f94806SJed Brown    Notes:
805a2f94806SJed Brown      Not available in Fortran
806a2f94806SJed Brown 
807a2f94806SJed Brown    Level: developer
808a2f94806SJed Brown 
809a2f94806SJed Brown .seealso: PetscFunctionBegin, PetscFunctionReturn()
810a2f94806SJed Brown 
811a2f94806SJed Brown M*/
812a2f94806SJed Brown #define PetscFunctionBeginHot do {                                     \
813a2f94806SJed Brown     PetscStackPushNoCheck(PETSC_FUNCTION_NAME,PETSC_TRUE,PETSC_TRUE);  \
8142d53ad75SBarry Smith     PetscRegister__FUNCT__();                                          \
81553c77d0aSJed Brown   } while (0)
81653c77d0aSJed Brown 
817a8d2bbe5SBarry Smith /*MC
818a8d2bbe5SBarry Smith    PetscFunctionBeginUser - First executable line of user provided PETSc routine
819a8d2bbe5SBarry Smith 
820a8d2bbe5SBarry Smith    Synopsis:
821aaa7dc30SBarry Smith    #include <petscsys.h>
822a8d2bbe5SBarry Smith    void PetscFunctionBeginUser;
823a8d2bbe5SBarry Smith 
824a8d2bbe5SBarry Smith    Not Collective
825a8d2bbe5SBarry Smith 
826a8d2bbe5SBarry Smith    Usage:
827a8d2bbe5SBarry Smith .vb
828a8d2bbe5SBarry Smith      int something;
829a8d2bbe5SBarry Smith 
830ac285190SBarry Smith      PetscFunctionBeginUser;
831a8d2bbe5SBarry Smith .ve
832a8d2bbe5SBarry Smith 
833a8d2bbe5SBarry Smith    Notes:
8341957e957SBarry Smith       Final line of PETSc functions should be PetscFunctionReturn(0) except for main().
8351957e957SBarry Smith 
836a8d2bbe5SBarry Smith       Not available in Fortran
837a8d2bbe5SBarry Smith 
838ac285190SBarry Smith       This is identical to PetscFunctionBegin except it labels the routine as a user
839ac285190SBarry Smith       routine instead of as a PETSc library routine.
840ac285190SBarry Smith 
841a2f94806SJed Brown    Level: intermediate
842a8d2bbe5SBarry Smith 
843a2f94806SJed Brown .seealso: PetscFunctionReturn(), PetscFunctionBegin, PetscFunctionBeginHot
844a8d2bbe5SBarry Smith 
845a8d2bbe5SBarry Smith M*/
846a8d2bbe5SBarry Smith #define PetscFunctionBeginUser                                          \
847a8d2bbe5SBarry Smith   do {                                                                  \
848a2f94806SJed Brown     PetscStackPushNoCheck(PETSC_FUNCTION_NAME,PETSC_FALSE,PETSC_FALSE); \
849a8d2bbe5SBarry Smith     PetscRegister__FUNCT__();                                           \
850a8d2bbe5SBarry Smith   } while (0)
851a8d2bbe5SBarry Smith 
852a8d2bbe5SBarry Smith 
8535cd90555SBarry Smith #define PetscStackPush(n) \
85461d886c9SShri Abhyankar   do {                                                                  \
855a2f94806SJed Brown     PetscStackPushNoCheck(n,PETSC_FALSE,PETSC_FALSE);                   \
85615681b3cSBarry Smith     CHKMEMQ;                                                            \
85715681b3cSBarry Smith   } while (0)
8583a40ed3dSBarry Smith 
859d64ed03dSBarry Smith #define PetscStackPop                           \
860441dd030SJed Brown     do {                                        \
861441dd030SJed Brown       CHKMEMQ;                                  \
862441dd030SJed Brown       PetscStackPopNoCheck;                     \
86315681b3cSBarry Smith     } while (0)
864d64ed03dSBarry Smith 
86530de9b25SBarry Smith /*MC
86630de9b25SBarry Smith    PetscFunctionReturn - Last executable line of each PETSc function
86730de9b25SBarry Smith         used for error handling. Replaces return()
86830de9b25SBarry Smith 
86930de9b25SBarry Smith    Synopsis:
870aaa7dc30SBarry Smith    #include <petscsys.h>
87130de9b25SBarry Smith    void PetscFunctionReturn(0);
87230de9b25SBarry Smith 
873eca87e8dSBarry Smith    Not Collective
874eca87e8dSBarry Smith 
87530de9b25SBarry Smith    Usage:
87630de9b25SBarry Smith .vb
87730de9b25SBarry Smith     ....
87830de9b25SBarry Smith      PetscFunctionReturn(0);
87930de9b25SBarry Smith    }
88030de9b25SBarry Smith .ve
88130de9b25SBarry Smith 
88230de9b25SBarry Smith    Notes:
88330de9b25SBarry Smith      Not available in Fortran
88430de9b25SBarry Smith 
88530de9b25SBarry Smith    Level: developer
88630de9b25SBarry Smith 
88730de9b25SBarry Smith .seealso: PetscFunctionBegin()
88830de9b25SBarry Smith 
88930de9b25SBarry Smith M*/
8905cd90555SBarry Smith #define PetscFunctionReturn(a) \
8918246ba0dSJed Brown   do {                                                                \
892441dd030SJed Brown     PetscStackPopNoCheck;                                             \
8938246ba0dSJed Brown     return(a);} while (0)
894d64ed03dSBarry Smith 
895ff94ddecSSatish Balay #define PetscFunctionReturnVoid() \
8968246ba0dSJed Brown   do {                                                                \
897441dd030SJed Brown     PetscStackPopNoCheck;                                             \
8988246ba0dSJed Brown     return;} while (0)
89976386721SLisandro Dalcin 
9006d385327SIbrahima Ba #else
9016d385327SIbrahima Ba 
902c82b4e47SJed Brown PETSC_STATIC_INLINE PetscBool PetscStackActive(void) {return PETSC_FALSE;}
903a2f94806SJed Brown #define PetscStackPushNoCheck(funct,petsc_routine,hot) do {} while (0)
904441dd030SJed Brown #define PetscStackPopNoCheck                           do {} while (0)
9053a40ed3dSBarry Smith #define PetscFunctionBegin
9060bdf7c52SPeter Brune #define PetscFunctionBeginUser
907a2f94806SJed Brown #define PetscFunctionBeginHot
9083a40ed3dSBarry Smith #define PetscFunctionReturn(a)    return(a)
9095665465eSBarry Smith #define PetscFunctionReturnVoid() return
910812af9f3SBarry Smith #define PetscStackPop             CHKMEMQ
911812af9f3SBarry Smith #define PetscStackPush(f)         CHKMEMQ
9123a40ed3dSBarry Smith 
9133a40ed3dSBarry Smith #endif
9143a40ed3dSBarry Smith 
915eb6b5d47SBarry Smith /*
916eb6b5d47SBarry Smith     PetscStackCall - Calls an external library routine or user function after pushing the name of the routine on the stack.
917eb6b5d47SBarry Smith 
918eb6b5d47SBarry Smith    Input Parameters:
919eb6b5d47SBarry Smith +   name - string that gives the name of the function being called
920fd3f9acdSBarry Smith -   routine - actual call to the routine, including ierr = and CHKERRQ(ierr);
921fd3f9acdSBarry Smith 
922dbf62e16SBarry Smith    Note: Often one should use PetscStackCallStandard() instead. This routine is intended for external library routines that DO NOT return error codes
923eb6b5d47SBarry Smith 
924eb6b5d47SBarry Smith    Developer Note: this is so that when a user or external library routine results in a crash or corrupts memory, they get blamed instead of PETSc.
925eb6b5d47SBarry Smith 
926fd3f9acdSBarry Smith 
927fd3f9acdSBarry Smith 
928eb6b5d47SBarry Smith */
92930ecc5abSKarl Rupp #define PetscStackCall(name,routine) do { PetscStackPush(name);routine;PetscStackPop; } while (0)
930eb6b5d47SBarry Smith 
931fd3f9acdSBarry Smith /*
932fd3f9acdSBarry Smith     PetscStackCallStandard - Calls an external library routine after pushing the name of the routine on the stack.
933fd3f9acdSBarry Smith 
934fd3f9acdSBarry Smith    Input Parameters:
935fd3f9acdSBarry Smith +   func-  name of the routine
936fd3f9acdSBarry Smith -   args - arguments to the routine surrounded by ()
937fd3f9acdSBarry Smith 
93895452b02SPatrick Sanan    Notes:
93995452b02SPatrick Sanan     This is intended for external package routines that return error codes. Use PetscStackCall() for those that do not.
940dbf62e16SBarry Smith 
941dbf62e16SBarry Smith    Developer Note: this is so that when an external packge routine results in a crash or corrupts memory, they get blamed instead of PETSc.
942fd3f9acdSBarry Smith 
943fd3f9acdSBarry Smith */
944fd3f9acdSBarry Smith #define PetscStackCallStandard(func,args) do {                                                            \
9451d4906efSStefano Zampini     PetscErrorCode __ierr;                                                                                \
9461d4906efSStefano Zampini     PetscStackPush(#func);                                                                                \
9471d4906efSStefano Zampini     __ierr = func args;                                                                                   \
9481d4906efSStefano Zampini     PetscStackPop;                                                                                        \
9491d4906efSStefano Zampini     if (__ierr) SETERRQ2(PETSC_COMM_SELF,PETSC_ERR_LIB,"Error in %s(): error code %d",#func,(int)__ierr); \
950fd3f9acdSBarry Smith   } while (0)
951fd3f9acdSBarry Smith 
952014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscStackCreate(void);
953639ff905SBarry Smith PETSC_EXTERN PetscErrorCode PetscStackView(FILE*);
954014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscStackDestroy(void);
95506d1fe2cSBarry Smith 
95606d1fe2cSBarry Smith #endif
957