xref: /petsc/include/petscerror.h (revision baae8e41e456b8868c966bc28e9b654ba1daab12)
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 */
63e57d7714SBarry Smith #define PETSC_ERR_GPU_RESOURCE     96  /* missing or incorrect user input */
64e57d7714SBarry Smith #define PETSC_ERR_MAX_VALUE        97  /* this is always the one more than the largest error code */
65b9eb5ee8SHong Zhang 
6659aaf355SLisandro Dalcin #define PetscStringizeArg(a) #a
6759aaf355SLisandro Dalcin #define PetscStringize(a) PetscStringizeArg(a)
68330cf3c9SBarry Smith 
69e8b7e333SSatish Balay 
7030de9b25SBarry Smith /*MC
711957e957SBarry Smith    SETERRQ - Macro to be called when an error has been detected,
7230de9b25SBarry Smith 
7330de9b25SBarry Smith    Synopsis:
74aaa7dc30SBarry Smith    #include <petscsys.h>
753af045c5SBarry Smith    PetscErrorCode SETERRQ(MPI_Comm comm,PetscErrorCode ierr,char *message)
7630de9b25SBarry Smith 
77d083f849SBarry Smith    Collective
7830de9b25SBarry Smith 
7930de9b25SBarry Smith    Input Parameters:
803af045c5SBarry Smith +  comm - A communicator, use PETSC_COMM_SELF unless you know all ranks of another communicator will detect the error
813af045c5SBarry Smith .  ierr - nonzero error code, see the list of standard error codes in include/petscerror.h
8230de9b25SBarry Smith -  message - error message
8330de9b25SBarry Smith 
8430de9b25SBarry Smith   Level: beginner
8530de9b25SBarry Smith 
8630de9b25SBarry Smith    Notes:
8730de9b25SBarry Smith     Once the error handler is called the calling function is then returned from with the given error code.
8830de9b25SBarry Smith 
8930de9b25SBarry Smith     See SETERRQ1(), SETERRQ2(), SETERRQ3() for versions that take arguments
9030de9b25SBarry Smith 
9130de9b25SBarry Smith     Experienced users can set the error handler with PetscPushErrorHandler().
9230de9b25SBarry Smith 
933b1008b8SBarry Smith    Fortran Notes:
943b1008b8SBarry Smith       SETERRQ() may be called from Fortran subroutines but SETERRA() must be called from the
953b1008b8SBarry Smith       Fortran main program.
963b1008b8SBarry Smith 
9791d3bdf4SKris Buschelman .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), CHKERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2(), SETERRQ3()
9830de9b25SBarry Smith M*/
993af045c5SBarry Smith #define SETERRQ(comm,ierr,s) return PetscError(comm,__LINE__,PETSC_FUNCTION_NAME,__FILE__,ierr,PETSC_ERROR_INITIAL,s)
100986eef2eSBarry Smith 
101986eef2eSBarry Smith /*MC
102986eef2eSBarry Smith    SETERRMPI - Macro to be called when an error has been detected within an MPI callback function
103986eef2eSBarry Smith 
104986eef2eSBarry Smith    Synopsis:
105986eef2eSBarry Smith    #include <petscsys.h>
106986eef2eSBarry Smith    PetscErrorCode SETERRMPI(MPI_Comm comm,PetscErrorCode ierr,char *message)
107986eef2eSBarry Smith 
108d083f849SBarry Smith    Collective
109986eef2eSBarry Smith 
110986eef2eSBarry Smith    Input Parameters:
111986eef2eSBarry Smith +  comm - A communicator, use PETSC_COMM_SELF unless you know all ranks of another communicator will detect the error
112986eef2eSBarry Smith .  ierr - nonzero error code, see the list of standard error codes in include/petscerror.h
113986eef2eSBarry Smith -  message - error message
114986eef2eSBarry Smith 
115986eef2eSBarry Smith   Level: developer
116986eef2eSBarry Smith 
117986eef2eSBarry Smith    Notes:
118986eef2eSBarry 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
119986eef2eSBarry Smith     which is registered with MPI_Add_error_code() when PETSc is initialized.
120986eef2eSBarry Smith 
121986eef2eSBarry Smith .seealso: SETERRQ(), CHKERRQ(), CHKERRMPI(), PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), CHKERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2(), SETERRQ3()
122986eef2eSBarry Smith M*/
12312801b39SBarry Smith #define SETERRMPI(comm,ierr,s) return (PetscError(comm,__LINE__,PETSC_FUNCTION_NAME,__FILE__,ierr,PETSC_ERROR_INITIAL,s),PETSC_MPI_ERROR_CODE)
12430de9b25SBarry Smith 
12530de9b25SBarry Smith /*MC
12630de9b25SBarry Smith    SETERRQ1 - Macro that is called when an error has been detected,
12730de9b25SBarry Smith 
12830de9b25SBarry Smith    Synopsis:
129aaa7dc30SBarry Smith    #include <petscsys.h>
1303af045c5SBarry Smith    PetscErrorCode SETERRQ1(MPI_Comm comm,PetscErrorCode ierr,char *formatmessage,arg)
13130de9b25SBarry Smith 
132d083f849SBarry Smith    Collective
13330de9b25SBarry Smith 
13430de9b25SBarry Smith    Input Parameters:
135fa190f98SMatthew G. Knepley +  comm - A communicator, so that the error can be collective
1363af045c5SBarry Smith .  ierr - nonzero error code, see the list of standard error codes in include/petscerror.h
13730de9b25SBarry Smith .  message - error message in the printf format
13830de9b25SBarry Smith -  arg - argument (for example an integer, string or double)
13930de9b25SBarry Smith 
14030de9b25SBarry Smith   Level: beginner
14130de9b25SBarry Smith 
14230de9b25SBarry Smith    Notes:
14330de9b25SBarry Smith     Once the error handler is called the calling function is then returned from with the given error code.
14430de9b25SBarry Smith 
14530de9b25SBarry Smith    Experienced users can set the error handler with PetscPushErrorHandler().
14630de9b25SBarry Smith 
14791d3bdf4SKris Buschelman .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), CHKERRQ(), CHKMEMQ, SETERRQ(), SETERRQ2(), SETERRQ3()
14830de9b25SBarry Smith M*/
1493af045c5SBarry Smith #define SETERRQ1(comm,ierr,s,a1) return PetscError(comm,__LINE__,PETSC_FUNCTION_NAME,__FILE__,ierr,PETSC_ERROR_INITIAL,s,a1)
15030de9b25SBarry Smith 
15130de9b25SBarry Smith /*MC
15230de9b25SBarry Smith    SETERRQ2 - Macro that is called when an error has been detected,
15330de9b25SBarry Smith 
15430de9b25SBarry Smith    Synopsis:
155aaa7dc30SBarry Smith    #include <petscsys.h>
1563af045c5SBarry Smith    PetscErrorCode SETERRQ2(MPI_Comm comm,PetscErrorCode ierr,char *formatmessage,arg1,arg2)
15730de9b25SBarry Smith 
158d083f849SBarry Smith    Collective
15930de9b25SBarry Smith 
16030de9b25SBarry Smith    Input Parameters:
161fa190f98SMatthew G. Knepley +  comm - A communicator, so that the error can be collective
1623af045c5SBarry Smith .  ierr - nonzero error code, see the list of standard error codes in include/petscerror.h
16330de9b25SBarry Smith .  message - error message in the printf format
16430de9b25SBarry Smith .  arg1 - argument (for example an integer, string or double)
16530de9b25SBarry Smith -  arg2 - argument (for example an integer, string or double)
16630de9b25SBarry Smith 
16730de9b25SBarry Smith   Level: beginner
16830de9b25SBarry Smith 
16930de9b25SBarry Smith    Notes:
17030de9b25SBarry Smith     Once the error handler is called the calling function is then returned from with the given error code.
17130de9b25SBarry Smith 
17230de9b25SBarry Smith    Experienced users can set the error handler with PetscPushErrorHandler().
17330de9b25SBarry Smith 
1746024bd2cSBarry Smith .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), CHKERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ3()
17530de9b25SBarry Smith M*/
1763af045c5SBarry Smith #define SETERRQ2(comm,ierr,s,a1,a2) return PetscError(comm,__LINE__,PETSC_FUNCTION_NAME,__FILE__,ierr,PETSC_ERROR_INITIAL,s,a1,a2)
17730de9b25SBarry Smith 
17830de9b25SBarry Smith /*MC
17930de9b25SBarry Smith    SETERRQ3 - Macro that is called when an error has been detected,
18030de9b25SBarry Smith 
18130de9b25SBarry Smith    Synopsis:
182aaa7dc30SBarry Smith    #include <petscsys.h>
1833af045c5SBarry Smith    PetscErrorCode SETERRQ3(MPI_Comm comm,PetscErrorCode ierr,char *formatmessage,arg1,arg2,arg3)
18430de9b25SBarry Smith 
185d083f849SBarry Smith    Collective
18630de9b25SBarry Smith 
18730de9b25SBarry Smith    Input Parameters:
188fa190f98SMatthew G. Knepley +  comm - A communicator, so that the error can be collective
1893af045c5SBarry Smith .  ierr - nonzero error code, see the list of standard error codes in include/petscerror.h
19030de9b25SBarry Smith .  message - error message in the printf format
19130de9b25SBarry Smith .  arg1 - argument (for example an integer, string or double)
19230de9b25SBarry Smith .  arg2 - argument (for example an integer, string or double)
19330de9b25SBarry Smith -  arg3 - argument (for example an integer, string or double)
19430de9b25SBarry Smith 
19530de9b25SBarry Smith   Level: beginner
19630de9b25SBarry Smith 
19730de9b25SBarry Smith    Notes:
19830de9b25SBarry Smith     Once the error handler is called the calling function is then returned from with the given error code.
19930de9b25SBarry Smith 
200f621e05eSBarry Smith     There are also versions for 4, 5, 6 and 7 arguments.
201f621e05eSBarry Smith 
20230de9b25SBarry Smith    Experienced users can set the error handler with PetscPushErrorHandler().
20330de9b25SBarry Smith 
2046024bd2cSBarry Smith .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), CHKERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2()
20530de9b25SBarry Smith M*/
2063af045c5SBarry 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)
20730de9b25SBarry Smith 
208fa190f98SMatthew G. Knepley /*MC
209fa190f98SMatthew G. Knepley    SETERRQ4 - Macro that is called when an error has been detected,
210fa190f98SMatthew G. Knepley 
211fa190f98SMatthew G. Knepley    Synopsis:
212fa190f98SMatthew G. Knepley    #include <petscsys.h>
21331e9e36bSSatish Balay    PetscErrorCode SETERRQ4(MPI_Comm comm,PetscErrorCode ierr,char *formatmessage,arg1,arg2,arg3,arg4)
214fa190f98SMatthew G. Knepley 
215d083f849SBarry Smith    Collective
216fa190f98SMatthew G. Knepley 
217fa190f98SMatthew G. Knepley    Input Parameters:
218fa190f98SMatthew G. Knepley +  comm - A communicator, so that the error can be collective
2193af045c5SBarry Smith .  ierr - nonzero error code, see the list of standard error codes in include/petscerror.h
220fa190f98SMatthew G. Knepley .  message - error message in the printf format
221fa190f98SMatthew G. Knepley .  arg1 - argument (for example an integer, string or double)
222fa190f98SMatthew G. Knepley .  arg2 - argument (for example an integer, string or double)
223fa190f98SMatthew G. Knepley .  arg3 - argument (for example an integer, string or double)
224fa190f98SMatthew G. Knepley -  arg4 - argument (for example an integer, string or double)
225fa190f98SMatthew G. Knepley 
226fa190f98SMatthew G. Knepley   Level: beginner
227fa190f98SMatthew G. Knepley 
228fa190f98SMatthew G. Knepley    Notes:
229fa190f98SMatthew G. Knepley     Once the error handler is called the calling function is then returned from with the given error code.
230fa190f98SMatthew G. Knepley 
231fa190f98SMatthew G. Knepley     There are also versions for 4, 5, 6 and 7 arguments.
232fa190f98SMatthew G. Knepley 
233fa190f98SMatthew G. Knepley    Experienced users can set the error handler with PetscPushErrorHandler().
234fa190f98SMatthew G. Knepley 
235fa190f98SMatthew G. Knepley .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), CHKERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2()
236fa190f98SMatthew G. Knepley M*/
2373af045c5SBarry 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)
238fa190f98SMatthew G. Knepley 
239fa190f98SMatthew G. Knepley /*MC
240fa190f98SMatthew G. Knepley    SETERRQ5 - Macro that is called when an error has been detected,
241fa190f98SMatthew G. Knepley 
242fa190f98SMatthew G. Knepley    Synopsis:
243fa190f98SMatthew G. Knepley    #include <petscsys.h>
24431e9e36bSSatish Balay    PetscErrorCode SETERRQ5(MPI_Comm comm,PetscErrorCode ierr,char *formatmessage,arg1,arg2,arg3,arg4,arg5)
245fa190f98SMatthew G. Knepley 
246d083f849SBarry Smith    Collective
247fa190f98SMatthew G. Knepley 
248fa190f98SMatthew G. Knepley    Input Parameters:
249fa190f98SMatthew G. Knepley +  comm - A communicator, so that the error can be collective
2503af045c5SBarry Smith .  ierr - nonzero error code, see the list of standard error codes in include/petscerror.h
251fa190f98SMatthew G. Knepley .  message - error message in the printf format
252fa190f98SMatthew G. Knepley .  arg1 - argument (for example an integer, string or double)
253fa190f98SMatthew G. Knepley .  arg2 - argument (for example an integer, string or double)
254fa190f98SMatthew G. Knepley .  arg3 - argument (for example an integer, string or double)
255fa190f98SMatthew G. Knepley .  arg4 - argument (for example an integer, string or double)
256fa190f98SMatthew G. Knepley -  arg5 - argument (for example an integer, string or double)
257fa190f98SMatthew G. Knepley 
258fa190f98SMatthew G. Knepley   Level: beginner
259fa190f98SMatthew G. Knepley 
260fa190f98SMatthew G. Knepley    Notes:
261fa190f98SMatthew G. Knepley     Once the error handler is called the calling function is then returned from with the given error code.
262fa190f98SMatthew G. Knepley 
263fa190f98SMatthew G. Knepley     There are also versions for 4, 5, 6 and 7 arguments.
264fa190f98SMatthew G. Knepley 
265fa190f98SMatthew G. Knepley    Experienced users can set the error handler with PetscPushErrorHandler().
266fa190f98SMatthew G. Knepley 
267fa190f98SMatthew G. Knepley .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), CHKERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2()
268fa190f98SMatthew G. Knepley M*/
2693af045c5SBarry 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)
270fa190f98SMatthew G. Knepley 
271fa190f98SMatthew G. Knepley /*MC
272fa190f98SMatthew G. Knepley    SETERRQ6 - Macro that is called when an error has been detected,
273fa190f98SMatthew G. Knepley 
274fa190f98SMatthew G. Knepley    Synopsis:
275fa190f98SMatthew G. Knepley    #include <petscsys.h>
27631e9e36bSSatish Balay    PetscErrorCode SETERRQ6(MPI_Comm comm,PetscErrorCode ierr,char *formatmessage,arg1,arg2,arg3,arg4,arg5,arg6)
277fa190f98SMatthew G. Knepley 
278d083f849SBarry Smith    Collective
279fa190f98SMatthew G. Knepley 
280fa190f98SMatthew G. Knepley    Input Parameters:
281fa190f98SMatthew G. Knepley +  comm - A communicator, so that the error can be collective
2823af045c5SBarry Smith .  ierr - nonzero error code, see the list of standard error codes in include/petscerror.h
283fa190f98SMatthew G. Knepley .  message - error message in the printf format
284fa190f98SMatthew G. Knepley .  arg1 - argument (for example an integer, string or double)
285fa190f98SMatthew G. Knepley .  arg2 - argument (for example an integer, string or double)
286fa190f98SMatthew G. Knepley .  arg3 - argument (for example an integer, string or double)
287fa190f98SMatthew G. Knepley .  arg4 - argument (for example an integer, string or double)
288fa190f98SMatthew G. Knepley .  arg5 - argument (for example an integer, string or double)
289fa190f98SMatthew G. Knepley -  arg6 - argument (for example an integer, string or double)
290fa190f98SMatthew G. Knepley 
291fa190f98SMatthew G. Knepley   Level: beginner
292fa190f98SMatthew G. Knepley 
293fa190f98SMatthew G. Knepley    Notes:
294fa190f98SMatthew G. Knepley     Once the error handler is called the calling function is then returned from with the given error code.
295fa190f98SMatthew G. Knepley 
296fa190f98SMatthew G. Knepley     There are also versions for 4, 5, 6 and 7 arguments.
297fa190f98SMatthew G. Knepley 
298fa190f98SMatthew G. Knepley    Experienced users can set the error handler with PetscPushErrorHandler().
299fa190f98SMatthew G. Knepley 
300fa190f98SMatthew G. Knepley .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), CHKERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2()
301fa190f98SMatthew G. Knepley M*/
3023af045c5SBarry 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)
303fa190f98SMatthew G. Knepley 
304fa190f98SMatthew G. Knepley /*MC
305fa190f98SMatthew G. Knepley    SETERRQ7 - Macro that is called when an error has been detected,
306fa190f98SMatthew G. Knepley 
307fa190f98SMatthew G. Knepley    Synopsis:
308fa190f98SMatthew G. Knepley    #include <petscsys.h>
30931e9e36bSSatish Balay    PetscErrorCode SETERRQ7(MPI_Comm comm,PetscErrorCode ierr,char *formatmessage,arg1,arg2,arg3,arg4,arg5,arg6,arg7)
310fa190f98SMatthew G. Knepley 
311d083f849SBarry Smith    Collective
312fa190f98SMatthew G. Knepley 
313fa190f98SMatthew G. Knepley    Input Parameters:
314fa190f98SMatthew G. Knepley +  comm - A communicator, so that the error can be collective
3153af045c5SBarry Smith .  ierr - nonzero error code, see the list of standard error codes in include/petscerror.h
316fa190f98SMatthew G. Knepley .  message - error message in the printf format
317fa190f98SMatthew G. Knepley .  arg1 - argument (for example an integer, string or double)
318fa190f98SMatthew G. Knepley .  arg2 - argument (for example an integer, string or double)
319fa190f98SMatthew G. Knepley .  arg3 - argument (for example an integer, string or double)
320fa190f98SMatthew G. Knepley .  arg4 - argument (for example an integer, string or double)
321fa190f98SMatthew G. Knepley .  arg5 - argument (for example an integer, string or double)
322fa190f98SMatthew G. Knepley .  arg6 - argument (for example an integer, string or double)
323fa190f98SMatthew G. Knepley -  arg7 - argument (for example an integer, string or double)
324fa190f98SMatthew G. Knepley 
325fa190f98SMatthew G. Knepley   Level: beginner
326fa190f98SMatthew G. Knepley 
327fa190f98SMatthew G. Knepley    Notes:
328fa190f98SMatthew G. Knepley     Once the error handler is called the calling function is then returned from with the given error code.
329fa190f98SMatthew G. Knepley 
330fa190f98SMatthew G. Knepley     There are also versions for 4, 5, 6 and 7 arguments.
331fa190f98SMatthew G. Knepley 
332fa190f98SMatthew G. Knepley    Experienced users can set the error handler with PetscPushErrorHandler().
333fa190f98SMatthew G. Knepley 
334fa190f98SMatthew G. Knepley .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), CHKERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2()
335fa190f98SMatthew G. Knepley M*/
3363af045c5SBarry 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)
337fa190f98SMatthew G. Knepley 
338fa190f98SMatthew G. Knepley /*MC
339fa190f98SMatthew G. Knepley    SETERRQ8 - Macro that is called when an error has been detected,
340fa190f98SMatthew G. Knepley 
341fa190f98SMatthew G. Knepley    Synopsis:
342fa190f98SMatthew G. Knepley    #include <petscsys.h>
34331e9e36bSSatish Balay    PetscErrorCode SETERRQ8(MPI_Comm comm,PetscErrorCode ierr,char *formatmessage,arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8)
344fa190f98SMatthew G. Knepley 
345d083f849SBarry Smith    Collective
346fa190f98SMatthew G. Knepley 
347fa190f98SMatthew G. Knepley    Input Parameters:
348fa190f98SMatthew G. Knepley +  comm - A communicator, so that the error can be collective
3493af045c5SBarry Smith .  ierr - nonzero error code, see the list of standard error codes in include/petscerror.h
350fa190f98SMatthew G. Knepley .  message - error message in the printf format
351fa190f98SMatthew G. Knepley .  arg1 - argument (for example an integer, string or double)
352fa190f98SMatthew G. Knepley .  arg2 - argument (for example an integer, string or double)
353fa190f98SMatthew G. Knepley .  arg3 - argument (for example an integer, string or double)
354fa190f98SMatthew G. Knepley .  arg4 - argument (for example an integer, string or double)
355fa190f98SMatthew G. Knepley .  arg5 - argument (for example an integer, string or double)
356fa190f98SMatthew G. Knepley .  arg6 - argument (for example an integer, string or double)
357fa190f98SMatthew G. Knepley .  arg7 - argument (for example an integer, string or double)
358fa190f98SMatthew G. Knepley -  arg8 - argument (for example an integer, string or double)
359fa190f98SMatthew G. Knepley 
360fa190f98SMatthew G. Knepley   Level: beginner
361fa190f98SMatthew G. Knepley 
362fa190f98SMatthew G. Knepley    Notes:
363fa190f98SMatthew G. Knepley     Once the error handler is called the calling function is then returned from with the given error code.
364fa190f98SMatthew G. Knepley 
365fa190f98SMatthew G. Knepley     There are also versions for 4, 5, 6 and 7 arguments.
366fa190f98SMatthew G. Knepley 
367fa190f98SMatthew G. Knepley    Experienced users can set the error handler with PetscPushErrorHandler().
368fa190f98SMatthew G. Knepley 
369fa190f98SMatthew G. Knepley .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), CHKERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2()
370fa190f98SMatthew G. Knepley M*/
3713af045c5SBarry 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)
372fa190f98SMatthew G. Knepley 
373fa190f98SMatthew G. Knepley /*MC
374ee8199e6SMatthew G. Knepley    SETERRQ9 - Macro that is called when an error has been detected,
375ee8199e6SMatthew G. Knepley 
376ee8199e6SMatthew G. Knepley    Synopsis:
377ee8199e6SMatthew G. Knepley    #include <petscsys.h>
37831e9e36bSSatish Balay    PetscErrorCode SETERRQ9(MPI_Comm comm,PetscErrorCode ierr,char *formatmessage,arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9)
379ee8199e6SMatthew G. Knepley 
380d083f849SBarry Smith    Collective
381ee8199e6SMatthew G. Knepley 
382ee8199e6SMatthew G. Knepley    Input Parameters:
383ee8199e6SMatthew G. Knepley +  comm - A communicator, so that the error can be collective
384ee8199e6SMatthew G. Knepley .  ierr - nonzero error code, see the list of standard error codes in include/petscerror.h
385ee8199e6SMatthew G. Knepley .  message - error message in the printf format
386ee8199e6SMatthew G. Knepley .  arg1 - argument (for example an integer, string or double)
387ee8199e6SMatthew G. Knepley .  arg2 - argument (for example an integer, string or double)
388ee8199e6SMatthew G. Knepley .  arg3 - argument (for example an integer, string or double)
389ee8199e6SMatthew G. Knepley .  arg4 - argument (for example an integer, string or double)
390ee8199e6SMatthew G. Knepley .  arg5 - argument (for example an integer, string or double)
391ee8199e6SMatthew G. Knepley .  arg6 - argument (for example an integer, string or double)
392ee8199e6SMatthew G. Knepley .  arg7 - argument (for example an integer, string or double)
393ee8199e6SMatthew G. Knepley .  arg8 - argument (for example an integer, string or double)
394ee8199e6SMatthew G. Knepley -  arg9 - argument (for example an integer, string or double)
395ee8199e6SMatthew G. Knepley 
396ee8199e6SMatthew G. Knepley   Level: beginner
397ee8199e6SMatthew G. Knepley 
398ee8199e6SMatthew G. Knepley    Notes:
399ee8199e6SMatthew G. Knepley     Once the error handler is called the calling function is then returned from with the given error code.
400ee8199e6SMatthew G. Knepley 
401ee8199e6SMatthew G. Knepley     There are also versions for 0 to 9 arguments.
402ee8199e6SMatthew G. Knepley 
403ee8199e6SMatthew G. Knepley    Experienced users can set the error handler with PetscPushErrorHandler().
404ee8199e6SMatthew G. Knepley 
405ee8199e6SMatthew G. Knepley .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), CHKERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2()
406ee8199e6SMatthew G. Knepley M*/
407ee8199e6SMatthew 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)
408ee8199e6SMatthew G. Knepley 
409ee8199e6SMatthew G. Knepley /*MC
410fa190f98SMatthew G. Knepley    SETERRABORT - Macro that can be called when an error has been detected,
411fa190f98SMatthew G. Knepley 
412fa190f98SMatthew G. Knepley    Synopsis:
413fa190f98SMatthew G. Knepley    #include <petscsys.h>
4143af045c5SBarry Smith    PetscErrorCode SETERRABORT(MPI_Comm comm,PetscErrorCode ierr,char *message)
415fa190f98SMatthew G. Knepley 
416d083f849SBarry Smith    Collective
417fa190f98SMatthew G. Knepley 
418fa190f98SMatthew G. Knepley    Input Parameters:
419fa190f98SMatthew G. Knepley +  comm - A communicator, so that the error can be collective
4203af045c5SBarry Smith .  ierr - nonzero error code, see the list of standard error codes in include/petscerror.h
421fa190f98SMatthew G. Knepley -  message - error message in the printf format
422fa190f98SMatthew G. Knepley 
423fa190f98SMatthew G. Knepley   Level: beginner
424fa190f98SMatthew G. Knepley 
425fa190f98SMatthew G. Knepley    Notes:
426fa190f98SMatthew G. Knepley     This function just calls MPI_Abort().
427fa190f98SMatthew G. Knepley 
428fa190f98SMatthew G. Knepley .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), CHKERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2()
429fa190f98SMatthew G. Knepley M*/
4303af045c5SBarry 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)
4319a00fa46SSatish Balay 
43230de9b25SBarry Smith /*MC
43330de9b25SBarry Smith    CHKERRQ - Checks error code, if non-zero it calls the error handler and then returns
43430de9b25SBarry Smith 
43530de9b25SBarry Smith    Synopsis:
436aaa7dc30SBarry Smith    #include <petscsys.h>
4373af045c5SBarry Smith    PetscErrorCode CHKERRQ(PetscErrorCode ierr)
43830de9b25SBarry Smith 
439eca87e8dSBarry Smith    Not Collective
44030de9b25SBarry Smith 
44130de9b25SBarry Smith    Input Parameters:
4423af045c5SBarry Smith .  ierr - nonzero error code, see the list of standard error codes in include/petscerror.h
44330de9b25SBarry Smith 
44430de9b25SBarry Smith   Level: beginner
44530de9b25SBarry Smith 
44630de9b25SBarry Smith    Notes:
44730de9b25SBarry Smith     Once the error handler is called the calling function is then returned from with the given error code.
44830de9b25SBarry Smith 
44930de9b25SBarry Smith     Experienced users can set the error handler with PetscPushErrorHandler().
4505324ea47SKris Buschelman 
4513af045c5SBarry Smith     CHKERRQ(ierr) is fundamentally a macro replacement for
4523af045c5SBarry Smith          if (ierr) return(PetscError(...,ierr,...));
4535324ea47SKris Buschelman 
4545324ea47SKris Buschelman     Although typical usage resembles "void CHKERRQ(PetscErrorCode)" as described above, for certain uses it is
4555324ea47SKris Buschelman     highly inappropriate to use it in this manner as it invokes return(PetscErrorCode). In particular,
4565324ea47SKris Buschelman     it cannot be used in functions which return(void) or any other datatype.  In these types of functions,
45758ebbce7SBarry Smith     you can use CHKERRV() which returns without an error code (bad idea since the error is ignored or
4583af045c5SBarry Smith          if (ierr) {PetscError(....); return(YourReturnType);}
4590298fd71SBarry Smith     where you may pass back a NULL to indicate an error. You can also call CHKERRABORT(comm,n) to have
46058ebbce7SBarry Smith     MPI_Abort() returned immediately.
46158ebbce7SBarry Smith 
46291d3bdf4SKris Buschelman .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), SETERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2(), SETERRQ2()
46330de9b25SBarry Smith M*/
464ee74f559SJed 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)
4650219f5dfSJed 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)
466ee74f559SJed 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)
467ee74f559SJed 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)
468986eef2eSBarry Smith 
4697c66cc67SJunchao Zhang PETSC_EXTERN PetscErrorCode PetscAbortFindSourceFile_Private(const char*,PetscInt*);
470*baae8e41SSatish Balay PETSC_EXTERN PetscBool petscwaitonerrorflg,petscindebugger;
4717c66cc67SJunchao Zhang 
4727c66cc67SJunchao Zhang /*MC
4737c66cc67SJunchao Zhang    PETSCABORT - Call MPI_Abort with an informative error code
4747c66cc67SJunchao Zhang 
4757c66cc67SJunchao Zhang    Synopsis:
4767c66cc67SJunchao Zhang    #include <petscsys.h>
4777c66cc67SJunchao Zhang    PETSCABORT(MPI_Comm comm, PetscErrorCode ierr)
4787c66cc67SJunchao Zhang 
4797c66cc67SJunchao Zhang    Collective
4807c66cc67SJunchao Zhang 
4817c66cc67SJunchao Zhang    Input Parameters:
4827c66cc67SJunchao Zhang +  comm - A communicator, so that the error can be collective
4837c66cc67SJunchao Zhang -  ierr - nonzero error code, see the list of standard error codes in include/petscerror.h
4847c66cc67SJunchao Zhang 
485bf4d2887SBarry Smith    Level: advanced
4867c66cc67SJunchao Zhang 
487bf4d2887SBarry Smith    Notes:
488bf4d2887SBarry 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
4897233276eSBarry Smith    where PETSCABORT is called, respectively. ZZZ is the PETSc error code.
4907c66cc67SJunchao Zhang 
4917233276eSBarry Smith    If XX is zero, this means that the call was made in the routine main().
4927233276eSBarry 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[]
4937c66cc67SJunchao Zhang      is out of date. PETSc developers have to update it.
494a0760fecSJunchao 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.
4957233276eSBarry Smith 
496bf4d2887SBarry Smith    If the option -start_in_debugger was used then this calls abort() to stop the program in the debugger.
497bf4d2887SBarry Smith 
4987c66cc67SJunchao Zhang M*/
4997c66cc67SJunchao Zhang #define PETSCABORT(comm,ierr)  \
5007c66cc67SJunchao Zhang    do {                                                               \
5017c66cc67SJunchao Zhang       PetscInt       idx = 0;                                         \
5027c66cc67SJunchao Zhang       PetscMPIInt    errcode;                                         \
5037c66cc67SJunchao Zhang       PetscAbortFindSourceFile_Private(__FILE__,&idx);                \
5047c66cc67SJunchao Zhang       errcode = (PetscMPIInt)(idx*10000000 + __LINE__*1000 + ierr);   \
505*baae8e41SSatish Balay       if (petscwaitonerrorflg) PetscSleep(1000);                      \
506bf4d2887SBarry Smith       if (petscindebugger) abort();                                   \
507bf4d2887SBarry Smith       else MPI_Abort(comm,errcode);                                   \
5087c66cc67SJunchao Zhang    } while (0)
509986eef2eSBarry Smith 
510986eef2eSBarry Smith /*MC
511986eef2eSBarry Smith    CHKERRMPI - Checks error code, if non-zero it calls the error handler and then returns
512986eef2eSBarry Smith 
513986eef2eSBarry Smith    Synopsis:
514986eef2eSBarry Smith    #include <petscsys.h>
515986eef2eSBarry Smith    PetscErrorCode CHKERRMPI(PetscErrorCode ierr)
516986eef2eSBarry Smith 
517986eef2eSBarry Smith    Not Collective
518986eef2eSBarry Smith 
519986eef2eSBarry Smith    Input Parameters:
520986eef2eSBarry Smith .  ierr - nonzero error code, see the list of standard error codes in include/petscerror.h
521986eef2eSBarry Smith 
522986eef2eSBarry Smith   Level: developer
523986eef2eSBarry Smith 
524986eef2eSBarry Smith    Notes:
525986eef2eSBarry 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
526986eef2eSBarry Smith     which is registered with MPI_Add_error_code() when PETSc is initialized.
527986eef2eSBarry Smith 
528986eef2eSBarry Smith .seealso: CHKERRQ(), PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), SETERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2(), SETERRQ2()
529986eef2eSBarry Smith M*/
53012801b39SBarry 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)
53185614651SBarry Smith 
532fd705b32SMatthew Knepley #ifdef PETSC_CLANGUAGE_CXX
533fd705b32SMatthew Knepley 
534cc26af49SMatthew Knepley /*MC
535cc26af49SMatthew Knepley    CHKERRXX - Checks error code, if non-zero it calls the C++ error handler which throws an exception
536cc26af49SMatthew Knepley 
537cc26af49SMatthew Knepley    Synopsis:
538aaa7dc30SBarry Smith    #include <petscsys.h>
5393af045c5SBarry Smith    void CHKERRXX(PetscErrorCode ierr)
540cc26af49SMatthew Knepley 
541eca87e8dSBarry Smith    Not Collective
542cc26af49SMatthew Knepley 
543cc26af49SMatthew Knepley    Input Parameters:
5443af045c5SBarry Smith .  ierr - nonzero error code, see the list of standard error codes in include/petscerror.h
545cc26af49SMatthew Knepley 
546cc26af49SMatthew Knepley   Level: beginner
547cc26af49SMatthew Knepley 
548cc26af49SMatthew Knepley    Notes:
549cc26af49SMatthew Knepley     Once the error handler throws a ??? exception.
550cc26af49SMatthew Knepley 
551cc26af49SMatthew Knepley     You can use CHKERRV() which returns without an error code (bad idea since the error is ignored)
552cc26af49SMatthew Knepley     or CHKERRABORT(comm,n) to have MPI_Abort() returned immediately.
553cc26af49SMatthew Knepley 
554cc26af49SMatthew Knepley .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), SETERRQ(), CHKERRQ(), CHKMEMQ
555cc26af49SMatthew Knepley M*/
5563af045c5SBarry 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)
557fd705b32SMatthew Knepley 
558fd705b32SMatthew Knepley #endif
559fd705b32SMatthew Knepley 
5607fd2f626SJose E. Roman #if defined(PETSC_HAVE_CUDA)
5617fd2f626SJose E. Roman #define CHKERRCUSOLVER(err) do {if (PetscUnlikely(err)) SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_LIB,"CUSOLVER error %d",err);} while (0)
5627fd2f626SJose E. Roman #endif
56330de9b25SBarry Smith /*MC
56430de9b25SBarry Smith    CHKMEMQ - Checks the memory for corruption, calls error handler if any is detected
56530de9b25SBarry Smith 
56630de9b25SBarry Smith    Synopsis:
567aaa7dc30SBarry Smith    #include <petscsys.h>
56891d3bdf4SKris Buschelman    CHKMEMQ;
56930de9b25SBarry Smith 
570eca87e8dSBarry Smith    Not Collective
571eca87e8dSBarry Smith 
57230de9b25SBarry Smith   Level: beginner
57330de9b25SBarry Smith 
57430de9b25SBarry Smith    Notes:
575a8d69d7bSBarry Smith     We highly recommend using valgrind https://www.mcs.anl.gov/petsc/documentation/faq.html#valgrind for finding memory problems. This is useful
5761957e957SBarry Smith     on systems that do not have valgrind, but much much less useful.
5771957e957SBarry Smith 
57879dccf82SBarry Smith     Must run with the option -malloc_debug (-malloc_test in debug mode; or if PetscMallocSetDebug() called) to enable this option
57930de9b25SBarry Smith 
58030de9b25SBarry Smith     Once the error handler is called the calling function is then returned from with the given error code.
58130de9b25SBarry Smith 
58230de9b25SBarry Smith     By defaults prints location where memory that is corrupted was allocated.
58330de9b25SBarry Smith 
584f621e05eSBarry Smith     Use CHKMEMA for functions that return void
585f621e05eSBarry Smith 
5866024bd2cSBarry Smith .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), SETERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2(), SETERRQ3(),
587ff002950SBarry Smith           PetscMallocValidate()
58830de9b25SBarry Smith M*/
589efca3c55SSatish Balay #define CHKMEMQ do {PetscErrorCode _7_ierr = PetscMallocValidate(__LINE__,PETSC_FUNCTION_NAME,__FILE__);CHKERRQ(_7_ierr);} while (0)
59085614651SBarry Smith 
591efca3c55SSatish Balay #define CHKMEMA PetscMallocValidate(__LINE__,PETSC_FUNCTION_NAME,__FILE__)
592e68848bdSBarry Smith 
593668f157eSBarry Smith /*E
594668f157eSBarry Smith   PetscErrorType - passed to the PETSc error handling routines indicating if this is the first or a later call to the error handlers
595668f157eSBarry Smith 
596668f157eSBarry Smith   Level: advanced
597668f157eSBarry Smith 
598d736bfebSBarry Smith   PETSC_ERROR_IN_CXX indicates the error was detected in C++ and an exception should be generated
599d736bfebSBarry Smith 
60095452b02SPatrick Sanan   Developer Notes:
60195452b02SPatrick Sanan     This is currently used to decide when to print the detailed information about the run in PetscTraceBackErrorHandler()
602668f157eSBarry Smith 
603d736bfebSBarry Smith .seealso: PetscError(), SETERRXX()
604668f157eSBarry Smith E*/
605d736bfebSBarry Smith typedef enum {PETSC_ERROR_INITIAL=0,PETSC_ERROR_REPEAT=1,PETSC_ERROR_IN_CXX = 2} PetscErrorType;
6064b209cf6SBarry Smith 
607eb9e708aSLisandro Dalcin #if defined(__clang_analyzer__)
608eb9e708aSLisandro Dalcin __attribute__((analyzer_noreturn))
609eb9e708aSLisandro Dalcin #endif
610eb9e708aSLisandro Dalcin PETSC_EXTERN PetscErrorCode PetscError(MPI_Comm,int,const char*,const char*,PetscErrorCode,PetscErrorType,const char*,...);
611eb9e708aSLisandro Dalcin 
612014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscErrorPrintfInitialize(void);
613014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscErrorMessage(int,const char*[],char **);
614efca3c55SSatish Balay PETSC_EXTERN PetscErrorCode PetscTraceBackErrorHandler(MPI_Comm,int,const char*,const char*,PetscErrorCode,PetscErrorType,const char*,void*);
615efca3c55SSatish Balay PETSC_EXTERN PetscErrorCode PetscIgnoreErrorHandler(MPI_Comm,int,const char*,const char*,PetscErrorCode,PetscErrorType,const char*,void*);
616efca3c55SSatish Balay PETSC_EXTERN PetscErrorCode PetscEmacsClientErrorHandler(MPI_Comm,int,const char*,const char*,PetscErrorCode,PetscErrorType,const char*,void*);
617efca3c55SSatish Balay PETSC_EXTERN PetscErrorCode PetscMPIAbortErrorHandler(MPI_Comm,int,const char*,const char*,PetscErrorCode,PetscErrorType,const char*,void*);
618efca3c55SSatish Balay PETSC_EXTERN PetscErrorCode PetscAbortErrorHandler(MPI_Comm,int,const char*,const char*,PetscErrorCode,PetscErrorType,const char*,void*);
619efca3c55SSatish Balay PETSC_EXTERN PetscErrorCode PetscAttachDebuggerErrorHandler(MPI_Comm,int,const char*,const char*,PetscErrorCode,PetscErrorType,const char*,void*);
620efca3c55SSatish Balay PETSC_EXTERN PetscErrorCode PetscReturnErrorHandler(MPI_Comm,int,const char*,const char*,PetscErrorCode,PetscErrorType,const char*,void*);
621efca3c55SSatish Balay PETSC_EXTERN PetscErrorCode PetscPushErrorHandler(PetscErrorCode (*handler)(MPI_Comm,int,const char*,const char*,PetscErrorCode,PetscErrorType,const char*,void*),void*);
622014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscPopErrorHandler(void);
6238d359177SBarry Smith PETSC_EXTERN PetscErrorCode PetscSignalHandlerDefault(int,void*);
624014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscPushSignalHandler(PetscErrorCode (*)(int,void *),void*);
625014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscPopSignalHandler(void);
62628559dc8SJed Brown PETSC_EXTERN PetscErrorCode PetscCheckPointerSetIntensity(PetscInt);
627c2a741eeSJunchao Zhang PETSC_EXTERN void PetscSignalSegvCheckPointerOrMpi(void);
628c2a741eeSJunchao Zhang PETSC_DEPRECATED_FUNCTION("Use PetscSignalSegvCheckPointerOrMpi() (since version 3.13)") PETSC_STATIC_INLINE void PetscSignalSegvCheckPointer(void) {PetscSignalSegvCheckPointerOrMpi();}
629329f5518SBarry Smith 
630639ff905SBarry Smith /*MC
631639ff905SBarry Smith     PetscErrorPrintf - Prints error messages.
632639ff905SBarry Smith 
633639ff905SBarry Smith    Synopsis:
634aaa7dc30SBarry Smith     #include <petscsys.h>
635639ff905SBarry Smith      PetscErrorCode (*PetscErrorPrintf)(const char format[],...);
636639ff905SBarry Smith 
637639ff905SBarry Smith     Not Collective
638639ff905SBarry Smith 
639639ff905SBarry Smith     Input Parameters:
640639ff905SBarry Smith .   format - the usual printf() format string
641639ff905SBarry Smith 
642639ff905SBarry Smith    Options Database Keys:
6431957e957SBarry Smith +    -error_output_stdout - cause error messages to be printed to stdout instead of the  (default) stderr
644e1bc860dSBarry Smith -    -error_output_none - to turn off all printing of error messages (does not change the way the error is handled.)
645639ff905SBarry Smith 
64695452b02SPatrick Sanan    Notes:
64795452b02SPatrick Sanan     Use
648639ff905SBarry Smith $     PetscErrorPrintf = PetscErrorPrintfNone; to turn off all printing of error messages (does not change the way the
649639ff905SBarry Smith $                        error is handled.) and
6501957e957SBarry Smith $     PetscErrorPrintf = PetscErrorPrintfDefault; to turn it back on or you can use your own function
651639ff905SBarry Smith 
652639ff905SBarry Smith           Use
653639ff905SBarry Smith      PETSC_STDERR = FILE* obtained from a file open etc. to have stderr printed to the file.
654639ff905SBarry Smith      PETSC_STDOUT = FILE* obtained from a file open etc. to have stdout printed to the file.
655639ff905SBarry Smith 
656639ff905SBarry Smith           Use
657639ff905SBarry Smith       PetscPushErrorHandler() to provide your own error handler that determines what kind of messages to print
658639ff905SBarry Smith 
659639ff905SBarry Smith    Level: developer
660639ff905SBarry Smith 
661639ff905SBarry Smith     Fortran Note:
662639ff905SBarry Smith     This routine is not supported in Fortran.
663639ff905SBarry Smith 
664639ff905SBarry Smith 
6652b60790dSJed Brown .seealso: PetscFPrintf(), PetscSynchronizedPrintf(), PetscHelpPrintf(), PetscPrintf(), PetscPushErrorHandler(), PetscVFPrintf(), PetscHelpPrintf()
666639ff905SBarry Smith M*/
667639ff905SBarry Smith PETSC_EXTERN PetscErrorCode (*PetscErrorPrintf)(const char[],...);
668639ff905SBarry Smith 
669329f5518SBarry Smith typedef enum {PETSC_FP_TRAP_OFF=0,PETSC_FP_TRAP_ON=1} PetscFPTrap;
670014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSetFPTrap(PetscFPTrap);
671014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscFPTrapPush(PetscFPTrap);
672014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscFPTrapPop(void);
673aba4c478SBarry Smith PETSC_EXTERN PetscErrorCode PetscDetermineInitialFPTrap(void);
67454a8ef01SBarry Smith 
6753a40ed3dSBarry Smith /*
6763a40ed3dSBarry Smith       Allows the code to build a stack frame as it runs
6773a40ed3dSBarry Smith */
6783a40ed3dSBarry Smith 
67999cd645aSJed Brown #define PETSCSTACKSIZE 64
680184914b5SBarry Smith 
6813a40ed3dSBarry Smith typedef struct  {
6820e33f6ddSBarry Smith   const char      *function[PETSCSTACKSIZE];
6830e33f6ddSBarry Smith   const char      *file[PETSCSTACKSIZE];
684184914b5SBarry Smith         int       line[PETSCSTACKSIZE];
685a8d2bbe5SBarry Smith         PetscBool petscroutine[PETSCSTACKSIZE];
686184914b5SBarry Smith         int       currentsize;
687a2f94806SJed Brown         int       hotdepth;
6883a40ed3dSBarry Smith } PetscStack;
6893a40ed3dSBarry Smith 
6901f46d60fSShri Abhyankar PETSC_EXTERN PetscStack *petscstack;
691184914b5SBarry Smith 
6926f5c2d7aSBarry Smith PetscErrorCode  PetscStackCopy(PetscStack*,PetscStack*);
6936f5c2d7aSBarry Smith PetscErrorCode  PetscStackPrint(PetscStack *,FILE*);
6945d12eec7SSatish Balay #if defined(PETSC_SERIALIZE_FUNCTIONS)
6955d12eec7SSatish Balay #include <petsc/private/petscfptimpl.h>
6965d12eec7SSatish Balay /*
6975d12eec7SSatish Balay    Registers the current function into the global function pointer to function name table
6985d12eec7SSatish Balay 
6995d12eec7SSatish Balay    Have to fix this to handle errors but cannot return error since used in PETSC_VIEWER_DRAW_() etc
7005d12eec7SSatish Balay */
7015d12eec7SSatish Balay #define PetscRegister__FUNCT__() do { \
7025d12eec7SSatish Balay   static PetscBool __chked = PETSC_FALSE; \
7035d12eec7SSatish Balay   if (!__chked) {\
7045d12eec7SSatish Balay   void *ptr; PetscDLSym(NULL,PETSC_FUNCTION_NAME,&ptr);\
7055d12eec7SSatish Balay   __chked = PETSC_TRUE;\
7065d12eec7SSatish Balay   }} while (0)
7075d12eec7SSatish Balay #else
7085d12eec7SSatish Balay #define PetscRegister__FUNCT__()
7095d12eec7SSatish Balay #endif
7105d12eec7SSatish Balay 
7112d7c6352SJed Brown #if defined(PETSC_USE_DEBUG)
712dbf62e16SBarry Smith PETSC_STATIC_INLINE PetscBool PetscStackActive(void)
713dbf62e16SBarry Smith {
7145c25fcd7SBarry Smith   return(petscstack ? PETSC_TRUE : PETSC_FALSE);
715dbf62e16SBarry Smith }
7163a40ed3dSBarry Smith 
717441dd030SJed Brown /* Stack handling is based on the following two "NoCheck" macros.  These should only be called directly by other error
718441dd030SJed Brown  * handling macros.  We record the line of the call, which may or may not be the location of the definition.  But is at
719441dd030SJed Brown  * least more useful than "unknown" because it can distinguish multiple calls from the same function.
720441dd030SJed Brown  */
721441dd030SJed Brown 
722a2f94806SJed Brown #define PetscStackPushNoCheck(funct,petsc_routine,hot)                        \
723441dd030SJed Brown   do {                                                                        \
724e04113cfSBarry Smith     PetscStackSAWsTakeAccess();                                                \
7255c25fcd7SBarry Smith     if (petscstack && (petscstack->currentsize < PETSCSTACKSIZE)) {         \
7265c25fcd7SBarry Smith       petscstack->function[petscstack->currentsize]  = funct;               \
7275c25fcd7SBarry Smith       petscstack->file[petscstack->currentsize]      = __FILE__;            \
7285c25fcd7SBarry Smith       petscstack->line[petscstack->currentsize]      = __LINE__;            \
7295c25fcd7SBarry Smith       petscstack->petscroutine[petscstack->currentsize] = petsc_routine;    \
7305c25fcd7SBarry Smith       petscstack->currentsize++;                                             \
731441dd030SJed Brown     }                                                                         \
7325c25fcd7SBarry Smith     if (petscstack) {                                                        \
7335c25fcd7SBarry Smith       petscstack->hotdepth += (hot || petscstack->hotdepth);                \
734a2f94806SJed Brown     }                                                                         \
735e04113cfSBarry Smith     PetscStackSAWsGrantAccess();                                               \
736441dd030SJed Brown   } while (0)
737441dd030SJed Brown 
738441dd030SJed Brown #define PetscStackPopNoCheck                                            \
7395c25fcd7SBarry Smith   do {                                                                  \
740e04113cfSBarry Smith     PetscStackSAWsTakeAccess();                                          \
7415c25fcd7SBarry Smith     if (petscstack && petscstack->currentsize > 0) {                  \
7425c25fcd7SBarry Smith       petscstack->currentsize--;                                       \
743ffc31a0eSLisandro Dalcin       petscstack->function[petscstack->currentsize]  = NULL;             \
744ffc31a0eSLisandro Dalcin       petscstack->file[petscstack->currentsize]      = NULL;             \
7455c25fcd7SBarry Smith       petscstack->line[petscstack->currentsize]      = 0;             \
7465c25fcd7SBarry Smith       petscstack->petscroutine[petscstack->currentsize] = PETSC_FALSE;\
747441dd030SJed Brown     }                                                                   \
7485c25fcd7SBarry Smith     if (petscstack) {                                                  \
7495c25fcd7SBarry Smith       petscstack->hotdepth = PetscMax(petscstack->hotdepth-1,0);      \
750a2f94806SJed Brown     }                                                                   \
751e04113cfSBarry Smith     PetscStackSAWsGrantAccess();                                         \
752441dd030SJed Brown   } while (0)
753441dd030SJed Brown 
75430de9b25SBarry Smith /*MC
7551957e957SBarry Smith    PetscFunctionBegin - First executable line of each PETSc function,  used for error handling. Final
7561957e957SBarry Smith       line of PETSc functions should be PetscFunctionReturn(0);
75730de9b25SBarry Smith 
75830de9b25SBarry Smith    Synopsis:
759aaa7dc30SBarry Smith    #include <petscsys.h>
76030de9b25SBarry Smith    void PetscFunctionBegin;
76130de9b25SBarry Smith 
762eca87e8dSBarry Smith    Not Collective
763eca87e8dSBarry Smith 
76430de9b25SBarry Smith    Usage:
76530de9b25SBarry Smith .vb
76630de9b25SBarry Smith      int something;
76730de9b25SBarry Smith 
76830de9b25SBarry Smith      PetscFunctionBegin;
76930de9b25SBarry Smith .ve
77030de9b25SBarry Smith 
77130de9b25SBarry Smith    Notes:
7721957e957SBarry Smith      Use PetscFunctionBeginUser for application codes.
7731957e957SBarry Smith 
77430de9b25SBarry Smith      Not available in Fortran
77530de9b25SBarry Smith 
77630de9b25SBarry Smith    Level: developer
77730de9b25SBarry Smith 
7781957e957SBarry Smith .seealso: PetscFunctionReturn(), PetscFunctionBeginHot(), PetscFunctionBeginUser()
77930de9b25SBarry Smith 
78030de9b25SBarry Smith M*/
781441dd030SJed Brown #define PetscFunctionBegin do {                                        \
782a2f94806SJed Brown     PetscStackPushNoCheck(PETSC_FUNCTION_NAME,PETSC_TRUE,PETSC_FALSE); \
783a2f94806SJed Brown     PetscRegister__FUNCT__();                                          \
784a2f94806SJed Brown   } while (0)
785a2f94806SJed Brown 
786a2f94806SJed Brown /*MC
787a2f94806SJed Brown    PetscFunctionBeginHot - Substitute for PetscFunctionBegin to be used in functions that are called in
788a2f94806SJed Brown    performance-critical circumstances.  Use of this function allows for lighter profiling by default.
789a2f94806SJed Brown 
790a2f94806SJed Brown    Synopsis:
791aaa7dc30SBarry Smith    #include <petscsys.h>
792a2f94806SJed Brown    void PetscFunctionBeginHot;
793a2f94806SJed Brown 
794a2f94806SJed Brown    Not Collective
795a2f94806SJed Brown 
796a2f94806SJed Brown    Usage:
797a2f94806SJed Brown .vb
798a2f94806SJed Brown      int something;
799a2f94806SJed Brown 
800a2f94806SJed Brown      PetscFunctionBeginHot;
801a2f94806SJed Brown .ve
802a2f94806SJed Brown 
803a2f94806SJed Brown    Notes:
804a2f94806SJed Brown      Not available in Fortran
805a2f94806SJed Brown 
806a2f94806SJed Brown    Level: developer
807a2f94806SJed Brown 
808a2f94806SJed Brown .seealso: PetscFunctionBegin, PetscFunctionReturn()
809a2f94806SJed Brown 
810a2f94806SJed Brown M*/
811a2f94806SJed Brown #define PetscFunctionBeginHot do {                                     \
812a2f94806SJed Brown     PetscStackPushNoCheck(PETSC_FUNCTION_NAME,PETSC_TRUE,PETSC_TRUE);  \
8132d53ad75SBarry Smith     PetscRegister__FUNCT__();                                          \
81453c77d0aSJed Brown   } while (0)
81553c77d0aSJed Brown 
816a8d2bbe5SBarry Smith /*MC
817a8d2bbe5SBarry Smith    PetscFunctionBeginUser - First executable line of user provided PETSc routine
818a8d2bbe5SBarry Smith 
819a8d2bbe5SBarry Smith    Synopsis:
820aaa7dc30SBarry Smith    #include <petscsys.h>
821a8d2bbe5SBarry Smith    void PetscFunctionBeginUser;
822a8d2bbe5SBarry Smith 
823a8d2bbe5SBarry Smith    Not Collective
824a8d2bbe5SBarry Smith 
825a8d2bbe5SBarry Smith    Usage:
826a8d2bbe5SBarry Smith .vb
827a8d2bbe5SBarry Smith      int something;
828a8d2bbe5SBarry Smith 
829ac285190SBarry Smith      PetscFunctionBeginUser;
830a8d2bbe5SBarry Smith .ve
831a8d2bbe5SBarry Smith 
832a8d2bbe5SBarry Smith    Notes:
8331957e957SBarry Smith       Final line of PETSc functions should be PetscFunctionReturn(0) except for main().
8341957e957SBarry Smith 
835a8d2bbe5SBarry Smith       Not available in Fortran
836a8d2bbe5SBarry Smith 
837ac285190SBarry Smith       This is identical to PetscFunctionBegin except it labels the routine as a user
838ac285190SBarry Smith       routine instead of as a PETSc library routine.
839ac285190SBarry Smith 
840a2f94806SJed Brown    Level: intermediate
841a8d2bbe5SBarry Smith 
842a2f94806SJed Brown .seealso: PetscFunctionReturn(), PetscFunctionBegin, PetscFunctionBeginHot
843a8d2bbe5SBarry Smith 
844a8d2bbe5SBarry Smith M*/
845a8d2bbe5SBarry Smith #define PetscFunctionBeginUser                                          \
846a8d2bbe5SBarry Smith   do {                                                                  \
847a2f94806SJed Brown     PetscStackPushNoCheck(PETSC_FUNCTION_NAME,PETSC_FALSE,PETSC_FALSE); \
848a8d2bbe5SBarry Smith     PetscRegister__FUNCT__();                                           \
849a8d2bbe5SBarry Smith   } while (0)
850a8d2bbe5SBarry Smith 
851a8d2bbe5SBarry Smith 
8525cd90555SBarry Smith #define PetscStackPush(n) \
85361d886c9SShri Abhyankar   do {                                                                  \
854a2f94806SJed Brown     PetscStackPushNoCheck(n,PETSC_FALSE,PETSC_FALSE);                   \
85515681b3cSBarry Smith     CHKMEMQ;                                                            \
85615681b3cSBarry Smith   } while (0)
8573a40ed3dSBarry Smith 
858d64ed03dSBarry Smith #define PetscStackPop                           \
859441dd030SJed Brown     do {                                        \
860441dd030SJed Brown       CHKMEMQ;                                  \
861441dd030SJed Brown       PetscStackPopNoCheck;                     \
86215681b3cSBarry Smith     } while (0)
863d64ed03dSBarry Smith 
86430de9b25SBarry Smith /*MC
86530de9b25SBarry Smith    PetscFunctionReturn - Last executable line of each PETSc function
86630de9b25SBarry Smith         used for error handling. Replaces return()
86730de9b25SBarry Smith 
86830de9b25SBarry Smith    Synopsis:
869aaa7dc30SBarry Smith    #include <petscsys.h>
87030de9b25SBarry Smith    void PetscFunctionReturn(0);
87130de9b25SBarry Smith 
872eca87e8dSBarry Smith    Not Collective
873eca87e8dSBarry Smith 
87430de9b25SBarry Smith    Usage:
87530de9b25SBarry Smith .vb
87630de9b25SBarry Smith     ....
87730de9b25SBarry Smith      PetscFunctionReturn(0);
87830de9b25SBarry Smith    }
87930de9b25SBarry Smith .ve
88030de9b25SBarry Smith 
88130de9b25SBarry Smith    Notes:
88230de9b25SBarry Smith      Not available in Fortran
88330de9b25SBarry Smith 
88430de9b25SBarry Smith    Level: developer
88530de9b25SBarry Smith 
88630de9b25SBarry Smith .seealso: PetscFunctionBegin()
88730de9b25SBarry Smith 
88830de9b25SBarry Smith M*/
8895cd90555SBarry Smith #define PetscFunctionReturn(a) \
8908246ba0dSJed Brown   do {                                                                \
891441dd030SJed Brown     PetscStackPopNoCheck;                                             \
8928246ba0dSJed Brown     return(a);} while (0)
893d64ed03dSBarry Smith 
894ff94ddecSSatish Balay #define PetscFunctionReturnVoid() \
8958246ba0dSJed Brown   do {                                                                \
896441dd030SJed Brown     PetscStackPopNoCheck;                                             \
8978246ba0dSJed Brown     return;} while (0)
89876386721SLisandro Dalcin 
8996d385327SIbrahima Ba #else
9006d385327SIbrahima Ba 
901c82b4e47SJed Brown PETSC_STATIC_INLINE PetscBool PetscStackActive(void) {return PETSC_FALSE;}
902a2f94806SJed Brown #define PetscStackPushNoCheck(funct,petsc_routine,hot) do {} while (0)
903441dd030SJed Brown #define PetscStackPopNoCheck                           do {} while (0)
9043a40ed3dSBarry Smith #define PetscFunctionBegin
9050bdf7c52SPeter Brune #define PetscFunctionBeginUser
906a2f94806SJed Brown #define PetscFunctionBeginHot
9073a40ed3dSBarry Smith #define PetscFunctionReturn(a)    return(a)
9085665465eSBarry Smith #define PetscFunctionReturnVoid() return
909812af9f3SBarry Smith #define PetscStackPop             CHKMEMQ
910812af9f3SBarry Smith #define PetscStackPush(f)         CHKMEMQ
9113a40ed3dSBarry Smith 
9123a40ed3dSBarry Smith #endif
9133a40ed3dSBarry Smith 
914eb6b5d47SBarry Smith /*
915eb6b5d47SBarry Smith     PetscStackCall - Calls an external library routine or user function after pushing the name of the routine on the stack.
916eb6b5d47SBarry Smith 
917eb6b5d47SBarry Smith    Input Parameters:
918eb6b5d47SBarry Smith +   name - string that gives the name of the function being called
919fd3f9acdSBarry Smith -   routine - actual call to the routine, including ierr = and CHKERRQ(ierr);
920fd3f9acdSBarry Smith 
921dbf62e16SBarry Smith    Note: Often one should use PetscStackCallStandard() instead. This routine is intended for external library routines that DO NOT return error codes
922eb6b5d47SBarry Smith 
923eb6b5d47SBarry 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.
924eb6b5d47SBarry Smith 
925fd3f9acdSBarry Smith 
926fd3f9acdSBarry Smith 
927eb6b5d47SBarry Smith */
92830ecc5abSKarl Rupp #define PetscStackCall(name,routine) do { PetscStackPush(name);routine;PetscStackPop; } while (0)
929eb6b5d47SBarry Smith 
930fd3f9acdSBarry Smith /*
931fd3f9acdSBarry Smith     PetscStackCallStandard - Calls an external library routine after pushing the name of the routine on the stack.
932fd3f9acdSBarry Smith 
933fd3f9acdSBarry Smith    Input Parameters:
934fd3f9acdSBarry Smith +   func-  name of the routine
935fd3f9acdSBarry Smith -   args - arguments to the routine surrounded by ()
936fd3f9acdSBarry Smith 
93795452b02SPatrick Sanan    Notes:
93895452b02SPatrick Sanan     This is intended for external package routines that return error codes. Use PetscStackCall() for those that do not.
939dbf62e16SBarry Smith 
940dbf62e16SBarry 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.
941fd3f9acdSBarry Smith 
942fd3f9acdSBarry Smith */
943fd3f9acdSBarry Smith #define PetscStackCallStandard(func,args) do {                                                            \
9441d4906efSStefano Zampini     PetscErrorCode __ierr;                                                                                \
9451d4906efSStefano Zampini     PetscStackPush(#func);                                                                                \
9461d4906efSStefano Zampini     __ierr = func args;                                                                                   \
9471d4906efSStefano Zampini     PetscStackPop;                                                                                        \
9481d4906efSStefano Zampini     if (__ierr) SETERRQ2(PETSC_COMM_SELF,PETSC_ERR_LIB,"Error in %s(): error code %d",#func,(int)__ierr); \
949fd3f9acdSBarry Smith   } while (0)
950fd3f9acdSBarry Smith 
951014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscStackCreate(void);
952639ff905SBarry Smith PETSC_EXTERN PetscErrorCode PetscStackView(FILE*);
953014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscStackDestroy(void);
95406d1fe2cSBarry Smith 
95506d1fe2cSBarry Smith #endif
956