xref: /petsc/include/petscerror.h (revision 064a246e8b5c1f87897a54b4a9ec05181ea08258)
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 */
63589f383fSBarry Smith #define PETSC_ERR_GPU_RESOURCE     96  /* unable to load a GPU resource, for example cuBLAS */
64589f383fSBarry 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 */
65ffc4695bSBarry Smith #define PETSC_ERR_MPI              98  /* general MPI error */
66ffc4695bSBarry Smith #define PETSC_ERR_MAX_VALUE        99  /* this is always the one more than the largest error code */
67b9eb5ee8SHong Zhang 
6859aaf355SLisandro Dalcin #define PetscStringizeArg(a) #a
6959aaf355SLisandro Dalcin #define PetscStringize(a) PetscStringizeArg(a)
70330cf3c9SBarry Smith 
71e8b7e333SSatish Balay 
7230de9b25SBarry Smith /*MC
731957e957SBarry Smith    SETERRQ - Macro to be called when an error has been detected,
7430de9b25SBarry Smith 
7530de9b25SBarry Smith    Synopsis:
76aaa7dc30SBarry Smith    #include <petscsys.h>
773af045c5SBarry Smith    PetscErrorCode SETERRQ(MPI_Comm comm,PetscErrorCode ierr,char *message)
7830de9b25SBarry Smith 
79d083f849SBarry Smith    Collective
8030de9b25SBarry Smith 
8130de9b25SBarry Smith    Input Parameters:
823af045c5SBarry Smith +  comm - A communicator, use PETSC_COMM_SELF unless you know all ranks of another communicator will detect the error
833af045c5SBarry Smith .  ierr - nonzero error code, see the list of standard error codes in include/petscerror.h
8430de9b25SBarry Smith -  message - error message
8530de9b25SBarry Smith 
8630de9b25SBarry Smith   Level: beginner
8730de9b25SBarry Smith 
8830de9b25SBarry Smith    Notes:
8930de9b25SBarry Smith     Once the error handler is called the calling function is then returned from with the given error code.
9030de9b25SBarry Smith 
9130de9b25SBarry Smith     See SETERRQ1(), SETERRQ2(), SETERRQ3() for versions that take arguments
9230de9b25SBarry Smith 
9330de9b25SBarry Smith     Experienced users can set the error handler with PetscPushErrorHandler().
9430de9b25SBarry Smith 
953b1008b8SBarry Smith    Fortran Notes:
963b1008b8SBarry Smith       SETERRQ() may be called from Fortran subroutines but SETERRA() must be called from the
973b1008b8SBarry Smith       Fortran main program.
983b1008b8SBarry Smith 
99888a1fb3SBarry Smith .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), CHKERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2(), SETERRQ3(), CHKERRMPI()
10030de9b25SBarry Smith M*/
1013af045c5SBarry Smith #define SETERRQ(comm,ierr,s) return PetscError(comm,__LINE__,PETSC_FUNCTION_NAME,__FILE__,ierr,PETSC_ERROR_INITIAL,s)
102986eef2eSBarry Smith 
103ffc4695bSBarry Smith /*
104ffc4695bSBarry Smith     Returned from PETSc functions that are called from MPI, such as related to attributes
105ffc4695bSBarry Smith       Do not confuse PETSC_MPI_ERROR_CODE and PETSC_ERR_MPI, the first is registered with MPI and returned to MPI as
106888a1fb3SBarry Smith       an error code, the latter is a regular PETSc error code passed within PETSc code indicating an error was detected in an MPI call.
107ffc4695bSBarry Smith */
108ffc4695bSBarry Smith PETSC_EXTERN PetscMPIInt PETSC_MPI_ERROR_CLASS;
109ffc4695bSBarry Smith PETSC_EXTERN PetscMPIInt PETSC_MPI_ERROR_CODE;
110ffc4695bSBarry Smith 
111ffc4695bSBarry Smith 
112986eef2eSBarry Smith /*MC
113986eef2eSBarry Smith    SETERRMPI - Macro to be called when an error has been detected within an MPI callback function
114986eef2eSBarry Smith 
115986eef2eSBarry Smith    Synopsis:
116986eef2eSBarry Smith    #include <petscsys.h>
117986eef2eSBarry Smith    PetscErrorCode SETERRMPI(MPI_Comm comm,PetscErrorCode ierr,char *message)
118986eef2eSBarry Smith 
119d083f849SBarry Smith    Collective
120986eef2eSBarry Smith 
121986eef2eSBarry Smith    Input Parameters:
122986eef2eSBarry Smith +  comm - A communicator, use PETSC_COMM_SELF unless you know all ranks of another communicator will detect the error
123986eef2eSBarry Smith .  ierr - nonzero error code, see the list of standard error codes in include/petscerror.h
124986eef2eSBarry Smith -  message - error message
125986eef2eSBarry Smith 
126986eef2eSBarry Smith   Level: developer
127986eef2eSBarry Smith 
128986eef2eSBarry Smith    Notes:
129888a1fb3SBarry 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
130986eef2eSBarry Smith     which is registered with MPI_Add_error_code() when PETSc is initialized.
131986eef2eSBarry Smith 
132986eef2eSBarry Smith .seealso: SETERRQ(), CHKERRQ(), CHKERRMPI(), PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), CHKERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2(), SETERRQ3()
133986eef2eSBarry Smith M*/
13412801b39SBarry Smith #define SETERRMPI(comm,ierr,s) return (PetscError(comm,__LINE__,PETSC_FUNCTION_NAME,__FILE__,ierr,PETSC_ERROR_INITIAL,s),PETSC_MPI_ERROR_CODE)
13530de9b25SBarry Smith 
13630de9b25SBarry Smith /*MC
13730de9b25SBarry Smith    SETERRQ1 - Macro that is called when an error has been detected,
13830de9b25SBarry Smith 
13930de9b25SBarry Smith    Synopsis:
140aaa7dc30SBarry Smith    #include <petscsys.h>
1413af045c5SBarry Smith    PetscErrorCode SETERRQ1(MPI_Comm comm,PetscErrorCode ierr,char *formatmessage,arg)
14230de9b25SBarry Smith 
143d083f849SBarry Smith    Collective
14430de9b25SBarry Smith 
14530de9b25SBarry Smith    Input Parameters:
146fa190f98SMatthew G. Knepley +  comm - A communicator, so that the error can be collective
1473af045c5SBarry Smith .  ierr - nonzero error code, see the list of standard error codes in include/petscerror.h
14830de9b25SBarry Smith .  message - error message in the printf format
14930de9b25SBarry Smith -  arg - argument (for example an integer, string or double)
15030de9b25SBarry Smith 
15130de9b25SBarry Smith   Level: beginner
15230de9b25SBarry Smith 
15330de9b25SBarry Smith    Notes:
15430de9b25SBarry Smith     Once the error handler is called the calling function is then returned from with the given error code.
15530de9b25SBarry Smith 
15630de9b25SBarry Smith    Experienced users can set the error handler with PetscPushErrorHandler().
15730de9b25SBarry Smith 
15891d3bdf4SKris Buschelman .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), CHKERRQ(), CHKMEMQ, SETERRQ(), SETERRQ2(), SETERRQ3()
15930de9b25SBarry Smith M*/
1603af045c5SBarry Smith #define SETERRQ1(comm,ierr,s,a1) return PetscError(comm,__LINE__,PETSC_FUNCTION_NAME,__FILE__,ierr,PETSC_ERROR_INITIAL,s,a1)
16130de9b25SBarry Smith 
16230de9b25SBarry Smith /*MC
16330de9b25SBarry Smith    SETERRQ2 - Macro that is called when an error has been detected,
16430de9b25SBarry Smith 
16530de9b25SBarry Smith    Synopsis:
166aaa7dc30SBarry Smith    #include <petscsys.h>
1673af045c5SBarry Smith    PetscErrorCode SETERRQ2(MPI_Comm comm,PetscErrorCode ierr,char *formatmessage,arg1,arg2)
16830de9b25SBarry Smith 
169d083f849SBarry Smith    Collective
17030de9b25SBarry Smith 
17130de9b25SBarry Smith    Input Parameters:
172fa190f98SMatthew G. Knepley +  comm - A communicator, so that the error can be collective
1733af045c5SBarry Smith .  ierr - nonzero error code, see the list of standard error codes in include/petscerror.h
17430de9b25SBarry Smith .  message - error message in the printf format
17530de9b25SBarry Smith .  arg1 - argument (for example an integer, string or double)
17630de9b25SBarry Smith -  arg2 - argument (for example an integer, string or double)
17730de9b25SBarry Smith 
17830de9b25SBarry Smith   Level: beginner
17930de9b25SBarry Smith 
18030de9b25SBarry Smith    Notes:
18130de9b25SBarry Smith     Once the error handler is called the calling function is then returned from with the given error code.
18230de9b25SBarry Smith 
18330de9b25SBarry Smith    Experienced users can set the error handler with PetscPushErrorHandler().
18430de9b25SBarry Smith 
1856024bd2cSBarry Smith .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), CHKERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ3()
18630de9b25SBarry Smith M*/
1873af045c5SBarry Smith #define SETERRQ2(comm,ierr,s,a1,a2) return PetscError(comm,__LINE__,PETSC_FUNCTION_NAME,__FILE__,ierr,PETSC_ERROR_INITIAL,s,a1,a2)
18830de9b25SBarry Smith 
18930de9b25SBarry Smith /*MC
19030de9b25SBarry Smith    SETERRQ3 - Macro that is called when an error has been detected,
19130de9b25SBarry Smith 
19230de9b25SBarry Smith    Synopsis:
193aaa7dc30SBarry Smith    #include <petscsys.h>
1943af045c5SBarry Smith    PetscErrorCode SETERRQ3(MPI_Comm comm,PetscErrorCode ierr,char *formatmessage,arg1,arg2,arg3)
19530de9b25SBarry Smith 
196d083f849SBarry Smith    Collective
19730de9b25SBarry Smith 
19830de9b25SBarry Smith    Input Parameters:
199fa190f98SMatthew G. Knepley +  comm - A communicator, so that the error can be collective
2003af045c5SBarry Smith .  ierr - nonzero error code, see the list of standard error codes in include/petscerror.h
20130de9b25SBarry Smith .  message - error message in the printf format
20230de9b25SBarry Smith .  arg1 - argument (for example an integer, string or double)
20330de9b25SBarry Smith .  arg2 - argument (for example an integer, string or double)
20430de9b25SBarry Smith -  arg3 - argument (for example an integer, string or double)
20530de9b25SBarry Smith 
20630de9b25SBarry Smith   Level: beginner
20730de9b25SBarry Smith 
20830de9b25SBarry Smith    Notes:
20930de9b25SBarry Smith     Once the error handler is called the calling function is then returned from with the given error code.
21030de9b25SBarry Smith 
211f621e05eSBarry Smith     There are also versions for 4, 5, 6 and 7 arguments.
212f621e05eSBarry Smith 
21330de9b25SBarry Smith    Experienced users can set the error handler with PetscPushErrorHandler().
21430de9b25SBarry Smith 
2156024bd2cSBarry Smith .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), CHKERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2()
21630de9b25SBarry Smith M*/
2173af045c5SBarry 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)
21830de9b25SBarry Smith 
219fa190f98SMatthew G. Knepley /*MC
220fa190f98SMatthew G. Knepley    SETERRQ4 - Macro that is called when an error has been detected,
221fa190f98SMatthew G. Knepley 
222fa190f98SMatthew G. Knepley    Synopsis:
223fa190f98SMatthew G. Knepley    #include <petscsys.h>
22431e9e36bSSatish Balay    PetscErrorCode SETERRQ4(MPI_Comm comm,PetscErrorCode ierr,char *formatmessage,arg1,arg2,arg3,arg4)
225fa190f98SMatthew G. Knepley 
226d083f849SBarry Smith    Collective
227fa190f98SMatthew G. Knepley 
228fa190f98SMatthew G. Knepley    Input Parameters:
229fa190f98SMatthew G. Knepley +  comm - A communicator, so that the error can be collective
2303af045c5SBarry Smith .  ierr - nonzero error code, see the list of standard error codes in include/petscerror.h
231fa190f98SMatthew G. Knepley .  message - error message in the printf format
232fa190f98SMatthew G. Knepley .  arg1 - argument (for example an integer, string or double)
233fa190f98SMatthew G. Knepley .  arg2 - argument (for example an integer, string or double)
234fa190f98SMatthew G. Knepley .  arg3 - argument (for example an integer, string or double)
235fa190f98SMatthew G. Knepley -  arg4 - argument (for example an integer, string or double)
236fa190f98SMatthew G. Knepley 
237fa190f98SMatthew G. Knepley   Level: beginner
238fa190f98SMatthew G. Knepley 
239fa190f98SMatthew G. Knepley    Notes:
240fa190f98SMatthew G. Knepley     Once the error handler is called the calling function is then returned from with the given error code.
241fa190f98SMatthew G. Knepley 
242fa190f98SMatthew G. Knepley     There are also versions for 4, 5, 6 and 7 arguments.
243fa190f98SMatthew G. Knepley 
244fa190f98SMatthew G. Knepley    Experienced users can set the error handler with PetscPushErrorHandler().
245fa190f98SMatthew G. Knepley 
246fa190f98SMatthew G. Knepley .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), CHKERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2()
247fa190f98SMatthew G. Knepley M*/
2483af045c5SBarry 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)
249fa190f98SMatthew G. Knepley 
250fa190f98SMatthew G. Knepley /*MC
251fa190f98SMatthew G. Knepley    SETERRQ5 - Macro that is called when an error has been detected,
252fa190f98SMatthew G. Knepley 
253fa190f98SMatthew G. Knepley    Synopsis:
254fa190f98SMatthew G. Knepley    #include <petscsys.h>
25531e9e36bSSatish Balay    PetscErrorCode SETERRQ5(MPI_Comm comm,PetscErrorCode ierr,char *formatmessage,arg1,arg2,arg3,arg4,arg5)
256fa190f98SMatthew G. Knepley 
257d083f849SBarry Smith    Collective
258fa190f98SMatthew G. Knepley 
259fa190f98SMatthew G. Knepley    Input Parameters:
260fa190f98SMatthew G. Knepley +  comm - A communicator, so that the error can be collective
2613af045c5SBarry Smith .  ierr - nonzero error code, see the list of standard error codes in include/petscerror.h
262fa190f98SMatthew G. Knepley .  message - error message in the printf format
263fa190f98SMatthew G. Knepley .  arg1 - argument (for example an integer, string or double)
264fa190f98SMatthew G. Knepley .  arg2 - argument (for example an integer, string or double)
265fa190f98SMatthew G. Knepley .  arg3 - argument (for example an integer, string or double)
266fa190f98SMatthew G. Knepley .  arg4 - argument (for example an integer, string or double)
267fa190f98SMatthew G. Knepley -  arg5 - argument (for example an integer, string or double)
268fa190f98SMatthew G. Knepley 
269fa190f98SMatthew G. Knepley   Level: beginner
270fa190f98SMatthew G. Knepley 
271fa190f98SMatthew G. Knepley    Notes:
272fa190f98SMatthew G. Knepley     Once the error handler is called the calling function is then returned from with the given error code.
273fa190f98SMatthew G. Knepley 
274fa190f98SMatthew G. Knepley     There are also versions for 4, 5, 6 and 7 arguments.
275fa190f98SMatthew G. Knepley 
276fa190f98SMatthew G. Knepley    Experienced users can set the error handler with PetscPushErrorHandler().
277fa190f98SMatthew G. Knepley 
278fa190f98SMatthew G. Knepley .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), CHKERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2()
279fa190f98SMatthew G. Knepley M*/
2803af045c5SBarry 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)
281fa190f98SMatthew G. Knepley 
282fa190f98SMatthew G. Knepley /*MC
283fa190f98SMatthew G. Knepley    SETERRQ6 - Macro that is called when an error has been detected,
284fa190f98SMatthew G. Knepley 
285fa190f98SMatthew G. Knepley    Synopsis:
286fa190f98SMatthew G. Knepley    #include <petscsys.h>
28731e9e36bSSatish Balay    PetscErrorCode SETERRQ6(MPI_Comm comm,PetscErrorCode ierr,char *formatmessage,arg1,arg2,arg3,arg4,arg5,arg6)
288fa190f98SMatthew G. Knepley 
289d083f849SBarry Smith    Collective
290fa190f98SMatthew G. Knepley 
291fa190f98SMatthew G. Knepley    Input Parameters:
292fa190f98SMatthew G. Knepley +  comm - A communicator, so that the error can be collective
2933af045c5SBarry Smith .  ierr - nonzero error code, see the list of standard error codes in include/petscerror.h
294fa190f98SMatthew G. Knepley .  message - error message in the printf format
295fa190f98SMatthew G. Knepley .  arg1 - argument (for example an integer, string or double)
296fa190f98SMatthew G. Knepley .  arg2 - argument (for example an integer, string or double)
297fa190f98SMatthew G. Knepley .  arg3 - argument (for example an integer, string or double)
298fa190f98SMatthew G. Knepley .  arg4 - argument (for example an integer, string or double)
299fa190f98SMatthew G. Knepley .  arg5 - argument (for example an integer, string or double)
300fa190f98SMatthew G. Knepley -  arg6 - argument (for example an integer, string or double)
301fa190f98SMatthew G. Knepley 
302fa190f98SMatthew G. Knepley   Level: beginner
303fa190f98SMatthew G. Knepley 
304fa190f98SMatthew G. Knepley    Notes:
305fa190f98SMatthew G. Knepley     Once the error handler is called the calling function is then returned from with the given error code.
306fa190f98SMatthew G. Knepley 
307fa190f98SMatthew G. Knepley     There are also versions for 4, 5, 6 and 7 arguments.
308fa190f98SMatthew G. Knepley 
309fa190f98SMatthew G. Knepley    Experienced users can set the error handler with PetscPushErrorHandler().
310fa190f98SMatthew G. Knepley 
311fa190f98SMatthew G. Knepley .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), CHKERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2()
312fa190f98SMatthew G. Knepley M*/
3133af045c5SBarry 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)
314fa190f98SMatthew G. Knepley 
315fa190f98SMatthew G. Knepley /*MC
316fa190f98SMatthew G. Knepley    SETERRQ7 - Macro that is called when an error has been detected,
317fa190f98SMatthew G. Knepley 
318fa190f98SMatthew G. Knepley    Synopsis:
319fa190f98SMatthew G. Knepley    #include <petscsys.h>
32031e9e36bSSatish Balay    PetscErrorCode SETERRQ7(MPI_Comm comm,PetscErrorCode ierr,char *formatmessage,arg1,arg2,arg3,arg4,arg5,arg6,arg7)
321fa190f98SMatthew G. Knepley 
322d083f849SBarry Smith    Collective
323fa190f98SMatthew G. Knepley 
324fa190f98SMatthew G. Knepley    Input Parameters:
325fa190f98SMatthew G. Knepley +  comm - A communicator, so that the error can be collective
3263af045c5SBarry Smith .  ierr - nonzero error code, see the list of standard error codes in include/petscerror.h
327fa190f98SMatthew G. Knepley .  message - error message in the printf format
328fa190f98SMatthew G. Knepley .  arg1 - argument (for example an integer, string or double)
329fa190f98SMatthew G. Knepley .  arg2 - argument (for example an integer, string or double)
330fa190f98SMatthew G. Knepley .  arg3 - argument (for example an integer, string or double)
331fa190f98SMatthew G. Knepley .  arg4 - argument (for example an integer, string or double)
332fa190f98SMatthew G. Knepley .  arg5 - argument (for example an integer, string or double)
333fa190f98SMatthew G. Knepley .  arg6 - argument (for example an integer, string or double)
334fa190f98SMatthew G. Knepley -  arg7 - argument (for example an integer, string or double)
335fa190f98SMatthew G. Knepley 
336fa190f98SMatthew G. Knepley   Level: beginner
337fa190f98SMatthew G. Knepley 
338fa190f98SMatthew G. Knepley    Notes:
339fa190f98SMatthew G. Knepley     Once the error handler is called the calling function is then returned from with the given error code.
340fa190f98SMatthew G. Knepley 
341fa190f98SMatthew G. Knepley     There are also versions for 4, 5, 6 and 7 arguments.
342fa190f98SMatthew G. Knepley 
343fa190f98SMatthew G. Knepley    Experienced users can set the error handler with PetscPushErrorHandler().
344fa190f98SMatthew G. Knepley 
345fa190f98SMatthew G. Knepley .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), CHKERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2()
346fa190f98SMatthew G. Knepley M*/
3473af045c5SBarry 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)
348fa190f98SMatthew G. Knepley 
349fa190f98SMatthew G. Knepley /*MC
350fa190f98SMatthew G. Knepley    SETERRQ8 - Macro that is called when an error has been detected,
351fa190f98SMatthew G. Knepley 
352fa190f98SMatthew G. Knepley    Synopsis:
353fa190f98SMatthew G. Knepley    #include <petscsys.h>
35431e9e36bSSatish Balay    PetscErrorCode SETERRQ8(MPI_Comm comm,PetscErrorCode ierr,char *formatmessage,arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8)
355fa190f98SMatthew G. Knepley 
356d083f849SBarry Smith    Collective
357fa190f98SMatthew G. Knepley 
358fa190f98SMatthew G. Knepley    Input Parameters:
359fa190f98SMatthew G. Knepley +  comm - A communicator, so that the error can be collective
3603af045c5SBarry Smith .  ierr - nonzero error code, see the list of standard error codes in include/petscerror.h
361fa190f98SMatthew G. Knepley .  message - error message in the printf format
362fa190f98SMatthew G. Knepley .  arg1 - argument (for example an integer, string or double)
363fa190f98SMatthew G. Knepley .  arg2 - argument (for example an integer, string or double)
364fa190f98SMatthew G. Knepley .  arg3 - argument (for example an integer, string or double)
365fa190f98SMatthew G. Knepley .  arg4 - argument (for example an integer, string or double)
366fa190f98SMatthew G. Knepley .  arg5 - argument (for example an integer, string or double)
367fa190f98SMatthew G. Knepley .  arg6 - argument (for example an integer, string or double)
368fa190f98SMatthew G. Knepley .  arg7 - argument (for example an integer, string or double)
369fa190f98SMatthew G. Knepley -  arg8 - argument (for example an integer, string or double)
370fa190f98SMatthew G. Knepley 
371fa190f98SMatthew G. Knepley   Level: beginner
372fa190f98SMatthew G. Knepley 
373fa190f98SMatthew G. Knepley    Notes:
374fa190f98SMatthew G. Knepley     Once the error handler is called the calling function is then returned from with the given error code.
375fa190f98SMatthew G. Knepley 
376fa190f98SMatthew G. Knepley     There are also versions for 4, 5, 6 and 7 arguments.
377fa190f98SMatthew G. Knepley 
378fa190f98SMatthew G. Knepley    Experienced users can set the error handler with PetscPushErrorHandler().
379fa190f98SMatthew G. Knepley 
380fa190f98SMatthew G. Knepley .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), CHKERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2()
381fa190f98SMatthew G. Knepley M*/
3823af045c5SBarry 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)
383fa190f98SMatthew G. Knepley 
384fa190f98SMatthew G. Knepley /*MC
385ee8199e6SMatthew G. Knepley    SETERRQ9 - Macro that is called when an error has been detected,
386ee8199e6SMatthew G. Knepley 
387ee8199e6SMatthew G. Knepley    Synopsis:
388ee8199e6SMatthew G. Knepley    #include <petscsys.h>
38931e9e36bSSatish Balay    PetscErrorCode SETERRQ9(MPI_Comm comm,PetscErrorCode ierr,char *formatmessage,arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9)
390ee8199e6SMatthew G. Knepley 
391d083f849SBarry Smith    Collective
392ee8199e6SMatthew G. Knepley 
393ee8199e6SMatthew G. Knepley    Input Parameters:
394ee8199e6SMatthew G. Knepley +  comm - A communicator, so that the error can be collective
395ee8199e6SMatthew G. Knepley .  ierr - nonzero error code, see the list of standard error codes in include/petscerror.h
396ee8199e6SMatthew G. Knepley .  message - error message in the printf format
397ee8199e6SMatthew G. Knepley .  arg1 - argument (for example an integer, string or double)
398ee8199e6SMatthew G. Knepley .  arg2 - argument (for example an integer, string or double)
399ee8199e6SMatthew G. Knepley .  arg3 - argument (for example an integer, string or double)
400ee8199e6SMatthew G. Knepley .  arg4 - argument (for example an integer, string or double)
401ee8199e6SMatthew G. Knepley .  arg5 - argument (for example an integer, string or double)
402ee8199e6SMatthew G. Knepley .  arg6 - argument (for example an integer, string or double)
403ee8199e6SMatthew G. Knepley .  arg7 - argument (for example an integer, string or double)
404ee8199e6SMatthew G. Knepley .  arg8 - argument (for example an integer, string or double)
405ee8199e6SMatthew G. Knepley -  arg9 - argument (for example an integer, string or double)
406ee8199e6SMatthew G. Knepley 
407ee8199e6SMatthew G. Knepley   Level: beginner
408ee8199e6SMatthew G. Knepley 
409ee8199e6SMatthew G. Knepley    Notes:
410ee8199e6SMatthew G. Knepley     Once the error handler is called the calling function is then returned from with the given error code.
411ee8199e6SMatthew G. Knepley 
412ee8199e6SMatthew G. Knepley     There are also versions for 0 to 9 arguments.
413ee8199e6SMatthew G. Knepley 
414ee8199e6SMatthew G. Knepley    Experienced users can set the error handler with PetscPushErrorHandler().
415ee8199e6SMatthew G. Knepley 
416ee8199e6SMatthew G. Knepley .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), CHKERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2()
417ee8199e6SMatthew G. Knepley M*/
418ee8199e6SMatthew 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)
419ee8199e6SMatthew G. Knepley 
420ee8199e6SMatthew G. Knepley /*MC
421fa190f98SMatthew G. Knepley    SETERRABORT - Macro that can be called when an error has been detected,
422fa190f98SMatthew G. Knepley 
423fa190f98SMatthew G. Knepley    Synopsis:
424fa190f98SMatthew G. Knepley    #include <petscsys.h>
4253af045c5SBarry Smith    PetscErrorCode SETERRABORT(MPI_Comm comm,PetscErrorCode ierr,char *message)
426fa190f98SMatthew G. Knepley 
427d083f849SBarry Smith    Collective
428fa190f98SMatthew G. Knepley 
429fa190f98SMatthew G. Knepley    Input Parameters:
430fa190f98SMatthew G. Knepley +  comm - A communicator, so that the error can be collective
4313af045c5SBarry Smith .  ierr - nonzero error code, see the list of standard error codes in include/petscerror.h
432fa190f98SMatthew G. Knepley -  message - error message in the printf format
433fa190f98SMatthew G. Knepley 
434fa190f98SMatthew G. Knepley   Level: beginner
435fa190f98SMatthew G. Knepley 
436fa190f98SMatthew G. Knepley    Notes:
437fa190f98SMatthew G. Knepley     This function just calls MPI_Abort().
438fa190f98SMatthew G. Knepley 
439fa190f98SMatthew G. Knepley .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), CHKERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2()
440fa190f98SMatthew G. Knepley M*/
4413af045c5SBarry 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)
4429a00fa46SSatish Balay 
44330de9b25SBarry Smith /*MC
444888a1fb3SBarry Smith    CHKERRQ - Checks error code returned from PETSc function, if non-zero it calls the error handler and then returns. Use CHKERRMPI() for checking errors from MPI calls
44530de9b25SBarry Smith 
44630de9b25SBarry Smith    Synopsis:
447aaa7dc30SBarry Smith    #include <petscsys.h>
4483af045c5SBarry Smith    PetscErrorCode CHKERRQ(PetscErrorCode ierr)
44930de9b25SBarry Smith 
450eca87e8dSBarry Smith    Not Collective
45130de9b25SBarry Smith 
45230de9b25SBarry Smith    Input Parameters:
4533af045c5SBarry Smith .  ierr - nonzero error code, see the list of standard error codes in include/petscerror.h
45430de9b25SBarry Smith 
45530de9b25SBarry Smith   Level: beginner
45630de9b25SBarry Smith 
45730de9b25SBarry Smith    Notes:
45830de9b25SBarry Smith     Once the error handler is called the calling function is then returned from with the given error code.
45930de9b25SBarry Smith 
46030de9b25SBarry Smith     Experienced users can set the error handler with PetscPushErrorHandler().
4615324ea47SKris Buschelman 
4623af045c5SBarry Smith     CHKERRQ(ierr) is fundamentally a macro replacement for
4633af045c5SBarry Smith          if (ierr) return(PetscError(...,ierr,...));
4645324ea47SKris Buschelman 
4655324ea47SKris Buschelman     Although typical usage resembles "void CHKERRQ(PetscErrorCode)" as described above, for certain uses it is
4665324ea47SKris Buschelman     highly inappropriate to use it in this manner as it invokes return(PetscErrorCode). In particular,
4675324ea47SKris Buschelman     it cannot be used in functions which return(void) or any other datatype.  In these types of functions,
46858ebbce7SBarry Smith     you can use CHKERRV() which returns without an error code (bad idea since the error is ignored or
4693af045c5SBarry Smith          if (ierr) {PetscError(....); return(YourReturnType);}
4700298fd71SBarry Smith     where you may pass back a NULL to indicate an error. You can also call CHKERRABORT(comm,n) to have
47158ebbce7SBarry Smith     MPI_Abort() returned immediately.
47258ebbce7SBarry Smith 
4737037b0edSPatrick Sanan    Fortran Notes:
4747037b0edSPatrick Sanan       CHKERRQ() may be called from Fortran subroutines but CHKERRA() must be called from the
4757037b0edSPatrick Sanan       Fortran main program.
4767037b0edSPatrick Sanan 
47791d3bdf4SKris Buschelman .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), SETERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2(), SETERRQ2()
47830de9b25SBarry Smith M*/
479*064a246eSJacob Faibussowitsch #if !defined(PETSC_CLANG_STATIC_ANALYZER)
480ee74f559SJed 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)
4810219f5dfSJed 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)
482*064a246eSJacob Faibussowitsch #else
483*064a246eSJacob Faibussowitsch #define CHKERRQ(ierr)
484*064a246eSJacob Faibussowitsch #define CHKERRV(ierr)
485*064a246eSJacob Faibussowitsch #endif
486*064a246eSJacob Faibussowitsch 
4877037b0edSPatrick Sanan 
4887037b0edSPatrick Sanan /*MC
4897037b0edSPatrick Sanan    CHKERRABORT - Checks error code returned from PETSc function. If non-zero it aborts immediately.
4907037b0edSPatrick Sanan 
4917037b0edSPatrick Sanan    Synopsis:
4927037b0edSPatrick Sanan    #include <petscsys.h>
4937037b0edSPatrick Sanan    PetscErrorCode CHKERRABORT(MPI_Comm comm,PetscErrorCode ierr)
4947037b0edSPatrick Sanan 
4957037b0edSPatrick Sanan    Not Collective
4967037b0edSPatrick Sanan 
4977037b0edSPatrick Sanan    Input Parameters:
4987037b0edSPatrick Sanan .  ierr - nonzero error code, see the list of standard error codes in include/petscerror.h
4997037b0edSPatrick Sanan 
5007037b0edSPatrick Sanan   Level: intermediate
5017037b0edSPatrick Sanan 
5027037b0edSPatrick Sanan .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), SETERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2(), SETERRQ2(), SETERRABORT(), CHKERRMPI()
5037037b0edSPatrick Sanan M*/
504*064a246eSJacob Faibussowitsch #if !defined(PETSC_CLANG_STATIC_ANALYZER)
505ee74f559SJed 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)
506ee74f559SJed 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)
507*064a246eSJacob Faibussowitsch #else
508*064a246eSJacob Faibussowitsch #define CHKERRABORT(comm,ierr)
509*064a246eSJacob Faibussowitsch #define CHKERRCONTINUE(ierr)
510*064a246eSJacob Faibussowitsch #endif
511986eef2eSBarry Smith 
5127c66cc67SJunchao Zhang PETSC_EXTERN PetscErrorCode PetscAbortFindSourceFile_Private(const char*,PetscInt*);
513baae8e41SSatish Balay PETSC_EXTERN PetscBool petscwaitonerrorflg,petscindebugger;
5147c66cc67SJunchao Zhang 
5157c66cc67SJunchao Zhang /*MC
5167c66cc67SJunchao Zhang    PETSCABORT - Call MPI_Abort with an informative error code
5177c66cc67SJunchao Zhang 
5187c66cc67SJunchao Zhang    Synopsis:
5197c66cc67SJunchao Zhang    #include <petscsys.h>
5207c66cc67SJunchao Zhang    PETSCABORT(MPI_Comm comm, PetscErrorCode ierr)
5217c66cc67SJunchao Zhang 
5227c66cc67SJunchao Zhang    Collective
5237c66cc67SJunchao Zhang 
5247c66cc67SJunchao Zhang    Input Parameters:
5257c66cc67SJunchao Zhang +  comm - A communicator, so that the error can be collective
5267c66cc67SJunchao Zhang -  ierr - nonzero error code, see the list of standard error codes in include/petscerror.h
5277c66cc67SJunchao Zhang 
528bf4d2887SBarry Smith    Level: advanced
5297c66cc67SJunchao Zhang 
530bf4d2887SBarry Smith    Notes:
531bf4d2887SBarry 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
5327233276eSBarry Smith    where PETSCABORT is called, respectively. ZZZ is the PETSc error code.
5337c66cc67SJunchao Zhang 
5347233276eSBarry Smith    If XX is zero, this means that the call was made in the routine main().
5357233276eSBarry 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[]
5367c66cc67SJunchao Zhang      is out of date. PETSc developers have to update it.
537a0760fecSJunchao 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.
5387233276eSBarry Smith 
539bf4d2887SBarry Smith    If the option -start_in_debugger was used then this calls abort() to stop the program in the debugger.
540bf4d2887SBarry Smith 
5417c66cc67SJunchao Zhang M*/
5427c66cc67SJunchao Zhang #define PETSCABORT(comm,ierr)  \
5437c66cc67SJunchao Zhang    do {                                                               \
5447c66cc67SJunchao Zhang       PetscInt       idx = 0;                                         \
5457c66cc67SJunchao Zhang       PetscMPIInt    errcode;                                         \
5467c66cc67SJunchao Zhang       PetscAbortFindSourceFile_Private(__FILE__,&idx);                \
54765f093c6SBarry Smith       errcode = (PetscMPIInt)(0*idx*10000000 + 0*__LINE__*1000 + ierr);   \
548baae8e41SSatish Balay       if (petscwaitonerrorflg) PetscSleep(1000);                      \
549bf4d2887SBarry Smith       if (petscindebugger) abort();                                   \
550bf4d2887SBarry Smith       else MPI_Abort(comm,errcode);                                   \
5517c66cc67SJunchao Zhang    } while (0)
552986eef2eSBarry Smith 
553986eef2eSBarry Smith /*MC
554888a1fb3SBarry Smith    CHKERRMPI - Checks error code returned from MPI calls, if non-zero it calls the error handler and then returns
555986eef2eSBarry Smith 
556986eef2eSBarry Smith    Synopsis:
557986eef2eSBarry Smith    #include <petscsys.h>
558986eef2eSBarry Smith    PetscErrorCode CHKERRMPI(PetscErrorCode ierr)
559986eef2eSBarry Smith 
560986eef2eSBarry Smith    Not Collective
561986eef2eSBarry Smith 
562986eef2eSBarry Smith    Input Parameters:
563986eef2eSBarry Smith .  ierr - nonzero error code, see the list of standard error codes in include/petscerror.h
564986eef2eSBarry Smith 
565888a1fb3SBarry Smith   Level: intermediate
566986eef2eSBarry Smith 
567986eef2eSBarry Smith    Notes:
568888a1fb3SBarry Smith     Always returns the error code PETSC_ERR_MPI; the MPI error code and string are embedded in the string error message
569986eef2eSBarry Smith 
5707037b0edSPatrick Sanan .seealso: CHKERRQ(), PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), SETERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2(), SETERRQ2(), SETERRMPI(), SETERRABORT(), CHKERRABORT()
571986eef2eSBarry Smith M*/
572*064a246eSJacob Faibussowitsch #if !defined(PETSC_CLANG_STATIC_ANALYZER)
573ffc4695bSBarry Smith #define CHKERRMPI(ierr) \
574ffc4695bSBarry Smith do { \
5753aa7491dSLisandro Dalcin   PetscErrorCode _7_errorcode = (ierr); \
5763aa7491dSLisandro Dalcin   if (PetscUnlikely(_7_errorcode)) { \
5773aa7491dSLisandro Dalcin     char _7_errorstring[MPI_MAX_ERROR_STRING]; \
5780ce65e24SLisandro Dalcin     PetscMPIInt _7_resultlen; \
5790ce65e24SLisandro Dalcin     MPI_Error_string(_7_errorcode,(char*)_7_errorstring,&_7_resultlen); (void)_7_resultlen; \
5803aa7491dSLisandro Dalcin     SETERRQ2(PETSC_COMM_SELF,PETSC_ERR_MPI,"MPI error %d %s",(int)_7_errorcode,_7_errorstring); \
581ffc4695bSBarry Smith   } \
582ffc4695bSBarry Smith } while (0)
583*064a246eSJacob Faibussowitsch #else
584*064a246eSJacob Faibussowitsch #define CHKERRMPI(ierr)
585*064a246eSJacob Faibussowitsch #endif
58685614651SBarry Smith 
587fd705b32SMatthew Knepley #ifdef PETSC_CLANGUAGE_CXX
588fd705b32SMatthew Knepley 
589cc26af49SMatthew Knepley /*MC
590cc26af49SMatthew Knepley    CHKERRXX - Checks error code, if non-zero it calls the C++ error handler which throws an exception
591cc26af49SMatthew Knepley 
592cc26af49SMatthew Knepley    Synopsis:
593aaa7dc30SBarry Smith    #include <petscsys.h>
5943af045c5SBarry Smith    void CHKERRXX(PetscErrorCode ierr)
595cc26af49SMatthew Knepley 
596eca87e8dSBarry Smith    Not Collective
597cc26af49SMatthew Knepley 
598cc26af49SMatthew Knepley    Input Parameters:
5993af045c5SBarry Smith .  ierr - nonzero error code, see the list of standard error codes in include/petscerror.h
600cc26af49SMatthew Knepley 
601cc26af49SMatthew Knepley   Level: beginner
602cc26af49SMatthew Knepley 
603cc26af49SMatthew Knepley    Notes:
604cc26af49SMatthew Knepley     Once the error handler throws a ??? exception.
605cc26af49SMatthew Knepley 
606cc26af49SMatthew Knepley     You can use CHKERRV() which returns without an error code (bad idea since the error is ignored)
607cc26af49SMatthew Knepley     or CHKERRABORT(comm,n) to have MPI_Abort() returned immediately.
608cc26af49SMatthew Knepley 
609cc26af49SMatthew Knepley .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), SETERRQ(), CHKERRQ(), CHKMEMQ
610cc26af49SMatthew Knepley M*/
6113af045c5SBarry 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)
612fd705b32SMatthew Knepley 
613fd705b32SMatthew Knepley #endif
614fd705b32SMatthew Knepley 
61559af0bd3SScott Kruger /* TODO: SEK:  Need to figure out the hipsolver issues */
61659af0bd3SScott Kruger #if defined(PETSC_HAVE_HIP)
61759af0bd3SScott Kruger #define CHKERRHIPSOLVER(err) do {if (PetscUnlikely(err)) SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_LIB,"HIPSOLVER error %d",err);} while (0)
61859af0bd3SScott Kruger #endif
61930de9b25SBarry Smith /*MC
62030de9b25SBarry Smith    CHKMEMQ - Checks the memory for corruption, calls error handler if any is detected
62130de9b25SBarry Smith 
62230de9b25SBarry Smith    Synopsis:
623aaa7dc30SBarry Smith    #include <petscsys.h>
62491d3bdf4SKris Buschelman    CHKMEMQ;
62530de9b25SBarry Smith 
626eca87e8dSBarry Smith    Not Collective
627eca87e8dSBarry Smith 
62830de9b25SBarry Smith   Level: beginner
62930de9b25SBarry Smith 
63030de9b25SBarry Smith    Notes:
631a8d69d7bSBarry Smith     We highly recommend using valgrind https://www.mcs.anl.gov/petsc/documentation/faq.html#valgrind for finding memory problems. This is useful
6321957e957SBarry Smith     on systems that do not have valgrind, but much much less useful.
6331957e957SBarry Smith 
63479dccf82SBarry Smith     Must run with the option -malloc_debug (-malloc_test in debug mode; or if PetscMallocSetDebug() called) to enable this option
63530de9b25SBarry Smith 
63630de9b25SBarry Smith     Once the error handler is called the calling function is then returned from with the given error code.
63730de9b25SBarry Smith 
63830de9b25SBarry Smith     By defaults prints location where memory that is corrupted was allocated.
63930de9b25SBarry Smith 
640f621e05eSBarry Smith     Use CHKMEMA for functions that return void
641f621e05eSBarry Smith 
6426024bd2cSBarry Smith .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), SETERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2(), SETERRQ3(),
643ff002950SBarry Smith           PetscMallocValidate()
64430de9b25SBarry Smith M*/
645*064a246eSJacob Faibussowitsch #if !defined(PETSC_CLANG_STATIC_ANALYZER)
646efca3c55SSatish Balay #define CHKMEMQ do {PetscErrorCode _7_ierr = PetscMallocValidate(__LINE__,PETSC_FUNCTION_NAME,__FILE__);CHKERRQ(_7_ierr);} while (0)
64785614651SBarry Smith 
648efca3c55SSatish Balay #define CHKMEMA PetscMallocValidate(__LINE__,PETSC_FUNCTION_NAME,__FILE__)
649*064a246eSJacob Faibussowitsch #else
650*064a246eSJacob Faibussowitsch #define CHKMEMQ
651*064a246eSJacob Faibussowitsch #define CHKMEMA
652*064a246eSJacob Faibussowitsch #endif
653668f157eSBarry Smith /*E
654668f157eSBarry Smith   PetscErrorType - passed to the PETSc error handling routines indicating if this is the first or a later call to the error handlers
655668f157eSBarry Smith 
656668f157eSBarry Smith   Level: advanced
657668f157eSBarry Smith 
658d736bfebSBarry Smith   PETSC_ERROR_IN_CXX indicates the error was detected in C++ and an exception should be generated
659d736bfebSBarry Smith 
66095452b02SPatrick Sanan   Developer Notes:
66195452b02SPatrick Sanan     This is currently used to decide when to print the detailed information about the run in PetscTraceBackErrorHandler()
662668f157eSBarry Smith 
663d736bfebSBarry Smith .seealso: PetscError(), SETERRXX()
664668f157eSBarry Smith E*/
665d736bfebSBarry Smith typedef enum {PETSC_ERROR_INITIAL=0,PETSC_ERROR_REPEAT=1,PETSC_ERROR_IN_CXX = 2} PetscErrorType;
6664b209cf6SBarry Smith 
667eb9e708aSLisandro Dalcin #if defined(__clang_analyzer__)
668eb9e708aSLisandro Dalcin __attribute__((analyzer_noreturn))
669eb9e708aSLisandro Dalcin #endif
670eb9e708aSLisandro Dalcin PETSC_EXTERN PetscErrorCode PetscError(MPI_Comm,int,const char*,const char*,PetscErrorCode,PetscErrorType,const char*,...);
671eb9e708aSLisandro Dalcin 
672014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscErrorPrintfInitialize(void);
673014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscErrorMessage(int,const char*[],char **);
674efca3c55SSatish Balay PETSC_EXTERN PetscErrorCode PetscTraceBackErrorHandler(MPI_Comm,int,const char*,const char*,PetscErrorCode,PetscErrorType,const char*,void*);
675efca3c55SSatish Balay PETSC_EXTERN PetscErrorCode PetscIgnoreErrorHandler(MPI_Comm,int,const char*,const char*,PetscErrorCode,PetscErrorType,const char*,void*);
676efca3c55SSatish Balay PETSC_EXTERN PetscErrorCode PetscEmacsClientErrorHandler(MPI_Comm,int,const char*,const char*,PetscErrorCode,PetscErrorType,const char*,void*);
677efca3c55SSatish Balay PETSC_EXTERN PetscErrorCode PetscMPIAbortErrorHandler(MPI_Comm,int,const char*,const char*,PetscErrorCode,PetscErrorType,const char*,void*);
678efca3c55SSatish Balay PETSC_EXTERN PetscErrorCode PetscAbortErrorHandler(MPI_Comm,int,const char*,const char*,PetscErrorCode,PetscErrorType,const char*,void*);
679efca3c55SSatish Balay PETSC_EXTERN PetscErrorCode PetscAttachDebuggerErrorHandler(MPI_Comm,int,const char*,const char*,PetscErrorCode,PetscErrorType,const char*,void*);
680efca3c55SSatish Balay PETSC_EXTERN PetscErrorCode PetscReturnErrorHandler(MPI_Comm,int,const char*,const char*,PetscErrorCode,PetscErrorType,const char*,void*);
681efca3c55SSatish Balay PETSC_EXTERN PetscErrorCode PetscPushErrorHandler(PetscErrorCode (*handler)(MPI_Comm,int,const char*,const char*,PetscErrorCode,PetscErrorType,const char*,void*),void*);
682014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscPopErrorHandler(void);
6838d359177SBarry Smith PETSC_EXTERN PetscErrorCode PetscSignalHandlerDefault(int,void*);
684014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscPushSignalHandler(PetscErrorCode (*)(int,void *),void*);
685014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscPopSignalHandler(void);
68628559dc8SJed Brown PETSC_EXTERN PetscErrorCode PetscCheckPointerSetIntensity(PetscInt);
687c2a741eeSJunchao Zhang PETSC_EXTERN void PetscSignalSegvCheckPointerOrMpi(void);
688c2a741eeSJunchao Zhang PETSC_DEPRECATED_FUNCTION("Use PetscSignalSegvCheckPointerOrMpi() (since version 3.13)") PETSC_STATIC_INLINE void PetscSignalSegvCheckPointer(void) {PetscSignalSegvCheckPointerOrMpi();}
689329f5518SBarry Smith 
690639ff905SBarry Smith /*MC
691639ff905SBarry Smith     PetscErrorPrintf - Prints error messages.
692639ff905SBarry Smith 
693639ff905SBarry Smith    Synopsis:
694aaa7dc30SBarry Smith     #include <petscsys.h>
695639ff905SBarry Smith      PetscErrorCode (*PetscErrorPrintf)(const char format[],...);
696639ff905SBarry Smith 
697639ff905SBarry Smith     Not Collective
698639ff905SBarry Smith 
699639ff905SBarry Smith     Input Parameters:
700639ff905SBarry Smith .   format - the usual printf() format string
701639ff905SBarry Smith 
702639ff905SBarry Smith    Options Database Keys:
7031957e957SBarry Smith +    -error_output_stdout - cause error messages to be printed to stdout instead of the  (default) stderr
704e1bc860dSBarry Smith -    -error_output_none - to turn off all printing of error messages (does not change the way the error is handled.)
705639ff905SBarry Smith 
70695452b02SPatrick Sanan    Notes:
70795452b02SPatrick Sanan     Use
708639ff905SBarry Smith $     PetscErrorPrintf = PetscErrorPrintfNone; to turn off all printing of error messages (does not change the way the
709639ff905SBarry Smith $                        error is handled.) and
7101957e957SBarry Smith $     PetscErrorPrintf = PetscErrorPrintfDefault; to turn it back on or you can use your own function
711639ff905SBarry Smith 
712639ff905SBarry Smith           Use
713639ff905SBarry Smith      PETSC_STDERR = FILE* obtained from a file open etc. to have stderr printed to the file.
714639ff905SBarry Smith      PETSC_STDOUT = FILE* obtained from a file open etc. to have stdout printed to the file.
715639ff905SBarry Smith 
716639ff905SBarry Smith           Use
717639ff905SBarry Smith       PetscPushErrorHandler() to provide your own error handler that determines what kind of messages to print
718639ff905SBarry Smith 
719639ff905SBarry Smith    Level: developer
720639ff905SBarry Smith 
721639ff905SBarry Smith     Fortran Note:
722639ff905SBarry Smith     This routine is not supported in Fortran.
723639ff905SBarry Smith 
724639ff905SBarry Smith 
7252b60790dSJed Brown .seealso: PetscFPrintf(), PetscSynchronizedPrintf(), PetscHelpPrintf(), PetscPrintf(), PetscPushErrorHandler(), PetscVFPrintf(), PetscHelpPrintf()
726639ff905SBarry Smith M*/
727639ff905SBarry Smith PETSC_EXTERN PetscErrorCode (*PetscErrorPrintf)(const char[],...);
728639ff905SBarry Smith 
729329f5518SBarry Smith typedef enum {PETSC_FP_TRAP_OFF=0,PETSC_FP_TRAP_ON=1} PetscFPTrap;
730014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSetFPTrap(PetscFPTrap);
731014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscFPTrapPush(PetscFPTrap);
732014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscFPTrapPop(void);
733aba4c478SBarry Smith PETSC_EXTERN PetscErrorCode PetscDetermineInitialFPTrap(void);
73454a8ef01SBarry Smith 
7353a40ed3dSBarry Smith /*
7363a40ed3dSBarry Smith       Allows the code to build a stack frame as it runs
7373a40ed3dSBarry Smith */
7383a40ed3dSBarry Smith 
73999cd645aSJed Brown #define PETSCSTACKSIZE 64
740184914b5SBarry Smith 
7413a40ed3dSBarry Smith typedef struct  {
7420e33f6ddSBarry Smith   const char      *function[PETSCSTACKSIZE];
7430e33f6ddSBarry Smith   const char      *file[PETSCSTACKSIZE];
744184914b5SBarry Smith         int       line[PETSCSTACKSIZE];
745a8d2bbe5SBarry Smith         PetscBool petscroutine[PETSCSTACKSIZE];
746184914b5SBarry Smith         int       currentsize;
747a2f94806SJed Brown         int       hotdepth;
7483a40ed3dSBarry Smith } PetscStack;
7493a40ed3dSBarry Smith 
7501f46d60fSShri Abhyankar PETSC_EXTERN PetscStack *petscstack;
751184914b5SBarry Smith 
7526f5c2d7aSBarry Smith PetscErrorCode  PetscStackCopy(PetscStack*,PetscStack*);
7536f5c2d7aSBarry Smith PetscErrorCode  PetscStackPrint(PetscStack *,FILE*);
7545d12eec7SSatish Balay #if defined(PETSC_SERIALIZE_FUNCTIONS)
7555d12eec7SSatish Balay #include <petsc/private/petscfptimpl.h>
7565d12eec7SSatish Balay /*
7575d12eec7SSatish Balay    Registers the current function into the global function pointer to function name table
7585d12eec7SSatish Balay 
7595d12eec7SSatish Balay    Have to fix this to handle errors but cannot return error since used in PETSC_VIEWER_DRAW_() etc
7605d12eec7SSatish Balay */
7615d12eec7SSatish Balay #define PetscRegister__FUNCT__() do { \
7625d12eec7SSatish Balay   static PetscBool __chked = PETSC_FALSE; \
7635d12eec7SSatish Balay   if (!__chked) {\
7645d12eec7SSatish Balay   void *ptr; PetscDLSym(NULL,PETSC_FUNCTION_NAME,&ptr);\
7655d12eec7SSatish Balay   __chked = PETSC_TRUE;\
7665d12eec7SSatish Balay   }} while (0)
7675d12eec7SSatish Balay #else
7685d12eec7SSatish Balay #define PetscRegister__FUNCT__()
7695d12eec7SSatish Balay #endif
7705d12eec7SSatish Balay 
771*064a246eSJacob Faibussowitsch #if !defined(PETSC_CLANG_STATIC_ANALYZER)
7722d7c6352SJed Brown #if defined(PETSC_USE_DEBUG)
773dbf62e16SBarry Smith PETSC_STATIC_INLINE PetscBool PetscStackActive(void)
774dbf62e16SBarry Smith {
7755c25fcd7SBarry Smith   return(petscstack ? PETSC_TRUE : PETSC_FALSE);
776dbf62e16SBarry Smith }
7773a40ed3dSBarry Smith 
778441dd030SJed Brown /* Stack handling is based on the following two "NoCheck" macros.  These should only be called directly by other error
779441dd030SJed Brown  * handling macros.  We record the line of the call, which may or may not be the location of the definition.  But is at
780441dd030SJed Brown  * least more useful than "unknown" because it can distinguish multiple calls from the same function.
781441dd030SJed Brown  */
782a2f94806SJed Brown #define PetscStackPushNoCheck(funct,petsc_routine,hot)                        \
783441dd030SJed Brown   do {                                                                        \
784e04113cfSBarry Smith     PetscStackSAWsTakeAccess();                                                \
7855c25fcd7SBarry Smith     if (petscstack && (petscstack->currentsize < PETSCSTACKSIZE)) {         \
7865c25fcd7SBarry Smith       petscstack->function[petscstack->currentsize]  = funct;               \
7875c25fcd7SBarry Smith       petscstack->file[petscstack->currentsize]      = __FILE__;            \
7885c25fcd7SBarry Smith       petscstack->line[petscstack->currentsize]      = __LINE__;            \
7895c25fcd7SBarry Smith       petscstack->petscroutine[petscstack->currentsize] = petsc_routine;    \
7905c25fcd7SBarry Smith       petscstack->currentsize++;                                             \
791441dd030SJed Brown     }                                                                         \
7925c25fcd7SBarry Smith     if (petscstack) {                                                        \
7935c25fcd7SBarry Smith       petscstack->hotdepth += (hot || petscstack->hotdepth);                \
794a2f94806SJed Brown     }                                                                         \
795e04113cfSBarry Smith     PetscStackSAWsGrantAccess();                                               \
796441dd030SJed Brown   } while (0)
797441dd030SJed Brown 
798441dd030SJed Brown #define PetscStackPopNoCheck                                            \
7995c25fcd7SBarry Smith   do {                                                                  \
800e04113cfSBarry Smith     PetscStackSAWsTakeAccess();                                          \
8015c25fcd7SBarry Smith     if (petscstack && petscstack->currentsize > 0) {                  \
8025c25fcd7SBarry Smith       petscstack->currentsize--;                                       \
803ffc31a0eSLisandro Dalcin       petscstack->function[petscstack->currentsize]  = NULL;             \
804ffc31a0eSLisandro Dalcin       petscstack->file[petscstack->currentsize]      = NULL;             \
8055c25fcd7SBarry Smith       petscstack->line[petscstack->currentsize]      = 0;             \
8065c25fcd7SBarry Smith       petscstack->petscroutine[petscstack->currentsize] = PETSC_FALSE;\
807441dd030SJed Brown     }                                                                   \
8085c25fcd7SBarry Smith     if (petscstack) {                                                  \
8095c25fcd7SBarry Smith       petscstack->hotdepth = PetscMax(petscstack->hotdepth-1,0);      \
810a2f94806SJed Brown     }                                                                   \
811e04113cfSBarry Smith     PetscStackSAWsGrantAccess();                                         \
812441dd030SJed Brown   } while (0)
813441dd030SJed Brown 
81430de9b25SBarry Smith /*MC
8151957e957SBarry Smith    PetscFunctionBegin - First executable line of each PETSc function,  used for error handling. Final
8161957e957SBarry Smith       line of PETSc functions should be PetscFunctionReturn(0);
81730de9b25SBarry Smith 
81830de9b25SBarry Smith    Synopsis:
819aaa7dc30SBarry Smith    #include <petscsys.h>
82030de9b25SBarry Smith    void PetscFunctionBegin;
82130de9b25SBarry Smith 
822eca87e8dSBarry Smith    Not Collective
823eca87e8dSBarry Smith 
82430de9b25SBarry Smith    Usage:
82530de9b25SBarry Smith .vb
82630de9b25SBarry Smith      int something;
82730de9b25SBarry Smith 
82830de9b25SBarry Smith      PetscFunctionBegin;
82930de9b25SBarry Smith .ve
83030de9b25SBarry Smith 
83130de9b25SBarry Smith    Notes:
8321957e957SBarry Smith      Use PetscFunctionBeginUser for application codes.
8331957e957SBarry Smith 
83430de9b25SBarry Smith      Not available in Fortran
83530de9b25SBarry Smith 
83630de9b25SBarry Smith    Level: developer
83730de9b25SBarry Smith 
8381957e957SBarry Smith .seealso: PetscFunctionReturn(), PetscFunctionBeginHot(), PetscFunctionBeginUser()
83930de9b25SBarry Smith 
84030de9b25SBarry Smith M*/
841441dd030SJed Brown #define PetscFunctionBegin do {                                        \
842a2f94806SJed Brown     PetscStackPushNoCheck(PETSC_FUNCTION_NAME,PETSC_TRUE,PETSC_FALSE); \
843a2f94806SJed Brown     PetscRegister__FUNCT__();                                          \
844a2f94806SJed Brown   } while (0)
845a2f94806SJed Brown 
846a2f94806SJed Brown /*MC
847a2f94806SJed Brown    PetscFunctionBeginHot - Substitute for PetscFunctionBegin to be used in functions that are called in
848a2f94806SJed Brown    performance-critical circumstances.  Use of this function allows for lighter profiling by default.
849a2f94806SJed Brown 
850a2f94806SJed Brown    Synopsis:
851aaa7dc30SBarry Smith    #include <petscsys.h>
852a2f94806SJed Brown    void PetscFunctionBeginHot;
853a2f94806SJed Brown 
854a2f94806SJed Brown    Not Collective
855a2f94806SJed Brown 
856a2f94806SJed Brown    Usage:
857a2f94806SJed Brown .vb
858a2f94806SJed Brown      int something;
859a2f94806SJed Brown 
860a2f94806SJed Brown      PetscFunctionBeginHot;
861a2f94806SJed Brown .ve
862a2f94806SJed Brown 
863a2f94806SJed Brown    Notes:
864a2f94806SJed Brown      Not available in Fortran
865a2f94806SJed Brown 
866a2f94806SJed Brown    Level: developer
867a2f94806SJed Brown 
868a2f94806SJed Brown .seealso: PetscFunctionBegin, PetscFunctionReturn()
869a2f94806SJed Brown 
870a2f94806SJed Brown M*/
871a2f94806SJed Brown #define PetscFunctionBeginHot do {                                     \
872a2f94806SJed Brown     PetscStackPushNoCheck(PETSC_FUNCTION_NAME,PETSC_TRUE,PETSC_TRUE);  \
8732d53ad75SBarry Smith     PetscRegister__FUNCT__();                                          \
87453c77d0aSJed Brown   } while (0)
87553c77d0aSJed Brown 
876a8d2bbe5SBarry Smith /*MC
877a8d2bbe5SBarry Smith    PetscFunctionBeginUser - First executable line of user provided PETSc routine
878a8d2bbe5SBarry Smith 
879a8d2bbe5SBarry Smith    Synopsis:
880aaa7dc30SBarry Smith    #include <petscsys.h>
881a8d2bbe5SBarry Smith    void PetscFunctionBeginUser;
882a8d2bbe5SBarry Smith 
883a8d2bbe5SBarry Smith    Not Collective
884a8d2bbe5SBarry Smith 
885a8d2bbe5SBarry Smith    Usage:
886a8d2bbe5SBarry Smith .vb
887a8d2bbe5SBarry Smith      int something;
888a8d2bbe5SBarry Smith 
889ac285190SBarry Smith      PetscFunctionBeginUser;
890a8d2bbe5SBarry Smith .ve
891a8d2bbe5SBarry Smith 
892a8d2bbe5SBarry Smith    Notes:
8931957e957SBarry Smith       Final line of PETSc functions should be PetscFunctionReturn(0) except for main().
8941957e957SBarry Smith 
895a8d2bbe5SBarry Smith       Not available in Fortran
896a8d2bbe5SBarry Smith 
897ac285190SBarry Smith       This is identical to PetscFunctionBegin except it labels the routine as a user
898ac285190SBarry Smith       routine instead of as a PETSc library routine.
899ac285190SBarry Smith 
900a2f94806SJed Brown    Level: intermediate
901a8d2bbe5SBarry Smith 
902a2f94806SJed Brown .seealso: PetscFunctionReturn(), PetscFunctionBegin, PetscFunctionBeginHot
903a8d2bbe5SBarry Smith 
904a8d2bbe5SBarry Smith M*/
905a8d2bbe5SBarry Smith #define PetscFunctionBeginUser                                          \
906a8d2bbe5SBarry Smith   do {                                                                  \
907a2f94806SJed Brown     PetscStackPushNoCheck(PETSC_FUNCTION_NAME,PETSC_FALSE,PETSC_FALSE); \
908a8d2bbe5SBarry Smith     PetscRegister__FUNCT__();                                           \
909a8d2bbe5SBarry Smith   } while (0)
910a8d2bbe5SBarry Smith 
911a8d2bbe5SBarry Smith 
9125cd90555SBarry Smith #define PetscStackPush(n) \
91361d886c9SShri Abhyankar   do {                                                                  \
914a2f94806SJed Brown     PetscStackPushNoCheck(n,PETSC_FALSE,PETSC_FALSE);                   \
91515681b3cSBarry Smith     CHKMEMQ;                                                            \
91615681b3cSBarry Smith   } while (0)
9173a40ed3dSBarry Smith 
918d64ed03dSBarry Smith #define PetscStackPop                           \
919441dd030SJed Brown     do {                                        \
920441dd030SJed Brown       CHKMEMQ;                                  \
921441dd030SJed Brown       PetscStackPopNoCheck;                     \
92215681b3cSBarry Smith     } while (0)
923d64ed03dSBarry Smith 
92430de9b25SBarry Smith /*MC
92530de9b25SBarry Smith    PetscFunctionReturn - Last executable line of each PETSc function
92630de9b25SBarry Smith         used for error handling. Replaces return()
92730de9b25SBarry Smith 
92830de9b25SBarry Smith    Synopsis:
929aaa7dc30SBarry Smith    #include <petscsys.h>
93030de9b25SBarry Smith    void PetscFunctionReturn(0);
93130de9b25SBarry Smith 
932eca87e8dSBarry Smith    Not Collective
933eca87e8dSBarry Smith 
93430de9b25SBarry Smith    Usage:
93530de9b25SBarry Smith .vb
93630de9b25SBarry Smith     ....
93730de9b25SBarry Smith      PetscFunctionReturn(0);
93830de9b25SBarry Smith    }
93930de9b25SBarry Smith .ve
94030de9b25SBarry Smith 
94130de9b25SBarry Smith    Notes:
94230de9b25SBarry Smith      Not available in Fortran
94330de9b25SBarry Smith 
94430de9b25SBarry Smith    Level: developer
94530de9b25SBarry Smith 
94630de9b25SBarry Smith .seealso: PetscFunctionBegin()
94730de9b25SBarry Smith 
94830de9b25SBarry Smith M*/
9495cd90555SBarry Smith #define PetscFunctionReturn(a) \
9508246ba0dSJed Brown   do {                                                                \
951441dd030SJed Brown     PetscStackPopNoCheck;                                             \
9528246ba0dSJed Brown     return(a);} while (0)
953d64ed03dSBarry Smith 
954ff94ddecSSatish Balay #define PetscFunctionReturnVoid() \
9558246ba0dSJed Brown   do {                                                                \
956441dd030SJed Brown     PetscStackPopNoCheck;                                             \
9578246ba0dSJed Brown     return;} while (0)
9586d385327SIbrahima Ba #else
9596d385327SIbrahima Ba 
960c82b4e47SJed Brown PETSC_STATIC_INLINE PetscBool PetscStackActive(void) {return PETSC_FALSE;}
961a2f94806SJed Brown #define PetscStackPushNoCheck(funct,petsc_routine,hot) do {} while (0)
962441dd030SJed Brown #define PetscStackPopNoCheck                           do {} while (0)
9633a40ed3dSBarry Smith #define PetscFunctionBegin
9640bdf7c52SPeter Brune #define PetscFunctionBeginUser
965a2f94806SJed Brown #define PetscFunctionBeginHot
9663a40ed3dSBarry Smith #define PetscFunctionReturn(a)    return(a)
9675665465eSBarry Smith #define PetscFunctionReturnVoid() return
968812af9f3SBarry Smith #define PetscStackPop             CHKMEMQ
969812af9f3SBarry Smith #define PetscStackPush(f)         CHKMEMQ
9703a40ed3dSBarry Smith 
9713a40ed3dSBarry Smith #endif
9723a40ed3dSBarry Smith 
973eb6b5d47SBarry Smith /*
974eb6b5d47SBarry Smith     PetscStackCall - Calls an external library routine or user function after pushing the name of the routine on the stack.
975eb6b5d47SBarry Smith 
976eb6b5d47SBarry Smith    Input Parameters:
977eb6b5d47SBarry Smith +   name - string that gives the name of the function being called
978fd3f9acdSBarry Smith -   routine - actual call to the routine, including ierr = and CHKERRQ(ierr);
979fd3f9acdSBarry Smith 
980dbf62e16SBarry Smith    Note: Often one should use PetscStackCallStandard() instead. This routine is intended for external library routines that DO NOT return error codes
981eb6b5d47SBarry Smith 
982eb6b5d47SBarry 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.
983eb6b5d47SBarry Smith 
984fd3f9acdSBarry Smith 
985fd3f9acdSBarry Smith 
986eb6b5d47SBarry Smith */
98730ecc5abSKarl Rupp #define PetscStackCall(name,routine) do { PetscStackPush(name);routine;PetscStackPop; } while (0)
988eb6b5d47SBarry Smith 
989fd3f9acdSBarry Smith /*
990fd3f9acdSBarry Smith     PetscStackCallStandard - Calls an external library routine after pushing the name of the routine on the stack.
991fd3f9acdSBarry Smith 
992fd3f9acdSBarry Smith    Input Parameters:
993fd3f9acdSBarry Smith +   func-  name of the routine
994fd3f9acdSBarry Smith -   args - arguments to the routine surrounded by ()
995fd3f9acdSBarry Smith 
99695452b02SPatrick Sanan    Notes:
99795452b02SPatrick Sanan     This is intended for external package routines that return error codes. Use PetscStackCall() for those that do not.
998dbf62e16SBarry Smith 
999dbf62e16SBarry 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.
1000fd3f9acdSBarry Smith 
1001fd3f9acdSBarry Smith */
1002fd3f9acdSBarry Smith #define PetscStackCallStandard(func,args) do {                                                            \
10031d4906efSStefano Zampini     PetscErrorCode __ierr;                                                                                \
10041d4906efSStefano Zampini     PetscStackPush(#func);                                                                                \
10051d4906efSStefano Zampini     __ierr = func args;                                                                                   \
10061d4906efSStefano Zampini     PetscStackPop;                                                                                        \
10071d4906efSStefano Zampini     if (__ierr) SETERRQ2(PETSC_COMM_SELF,PETSC_ERR_LIB,"Error in %s(): error code %d",#func,(int)__ierr); \
1008fd3f9acdSBarry Smith   } while (0)
1009fd3f9acdSBarry Smith 
1010*064a246eSJacob Faibussowitsch #else /* PETSC_CLANG_STATIC_ANALYZER */
1011*064a246eSJacob Faibussowitsch PETSC_STATIC_INLINE PetscBool PetscStackActive(void) {return PETSC_FALSE;}
1012*064a246eSJacob Faibussowitsch #define PetscStackPushNoCheck(funct,petsc_routine,hot) do {} while (0)
1013*064a246eSJacob Faibussowitsch #define PetscStackPopNoCheck                           do {} while (0)
1014*064a246eSJacob Faibussowitsch #define PetscFunctionBegin
1015*064a246eSJacob Faibussowitsch #define PetscFunctionBeginUser
1016*064a246eSJacob Faibussowitsch #define PetscFunctionBeginHot
1017*064a246eSJacob Faibussowitsch #define PetscFunctionReturn(a)    return(a)
1018*064a246eSJacob Faibussowitsch #define PetscFunctionReturnVoid() return
1019*064a246eSJacob Faibussowitsch #define PetscStackPop
1020*064a246eSJacob Faibussowitsch #define PetscStackPush(f)
1021*064a246eSJacob Faibussowitsch #define PetscStackCall(name,routine)
1022*064a246eSJacob Faibussowitsch #define PetscStackCallStandard(name,routine)
1023*064a246eSJacob Faibussowitsch #endif /* PETSC_CLANG_STATIC_ANALYZER */
1024*064a246eSJacob Faibussowitsch 
1025014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscStackCreate(void);
1026639ff905SBarry Smith PETSC_EXTERN PetscErrorCode PetscStackView(FILE*);
1027014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscStackDestroy(void);
102806d1fe2cSBarry Smith 
102906d1fe2cSBarry Smith #endif
1030