xref: /petsc/include/petscerror.h (revision 7fd2f6260fd3df1a815e75c0fc9579f1a7bbfb3a)
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
11af0996ceSBarry Smith      These are also define in include/petsc/finclude/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 */
60c5a392abSBarry Smith #define PETSC_ERR_OPT_OVERWRITE    93  /* attempted to over wrote options which should not be changed */
612a6744ebSBarry Smith 
62c5a392abSBarry Smith #define PETSC_ERR_MAX_VALUE        94  /* this is always the one more than the largest error code */
63b9eb5ee8SHong Zhang 
6459aaf355SLisandro Dalcin #define PetscStringizeArg(a) #a
6559aaf355SLisandro Dalcin #define PetscStringize(a) PetscStringizeArg(a)
66330cf3c9SBarry Smith 
67e8b7e333SSatish Balay 
6830de9b25SBarry Smith /*MC
691957e957SBarry Smith    SETERRQ - Macro to be called when an error has been detected,
7030de9b25SBarry Smith 
7130de9b25SBarry Smith    Synopsis:
72aaa7dc30SBarry Smith    #include <petscsys.h>
733af045c5SBarry Smith    PetscErrorCode SETERRQ(MPI_Comm comm,PetscErrorCode ierr,char *message)
7430de9b25SBarry Smith 
75d083f849SBarry Smith    Collective
7630de9b25SBarry Smith 
7730de9b25SBarry Smith    Input Parameters:
783af045c5SBarry Smith +  comm - A communicator, use PETSC_COMM_SELF unless you know all ranks of another communicator will detect the error
793af045c5SBarry Smith .  ierr - nonzero error code, see the list of standard error codes in include/petscerror.h
8030de9b25SBarry Smith -  message - error message
8130de9b25SBarry Smith 
8230de9b25SBarry Smith   Level: beginner
8330de9b25SBarry Smith 
8430de9b25SBarry Smith    Notes:
8530de9b25SBarry Smith     Once the error handler is called the calling function is then returned from with the given error code.
8630de9b25SBarry Smith 
8730de9b25SBarry Smith     See SETERRQ1(), SETERRQ2(), SETERRQ3() for versions that take arguments
8830de9b25SBarry Smith 
8930de9b25SBarry Smith     Experienced users can set the error handler with PetscPushErrorHandler().
9030de9b25SBarry Smith 
9191d3bdf4SKris Buschelman .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), CHKERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2(), SETERRQ3()
9230de9b25SBarry Smith M*/
933af045c5SBarry Smith #define SETERRQ(comm,ierr,s) return PetscError(comm,__LINE__,PETSC_FUNCTION_NAME,__FILE__,ierr,PETSC_ERROR_INITIAL,s)
94986eef2eSBarry Smith 
95986eef2eSBarry Smith /*MC
96986eef2eSBarry Smith    SETERRMPI - Macro to be called when an error has been detected within an MPI callback function
97986eef2eSBarry Smith 
98986eef2eSBarry Smith    Synopsis:
99986eef2eSBarry Smith    #include <petscsys.h>
100986eef2eSBarry Smith    PetscErrorCode SETERRMPI(MPI_Comm comm,PetscErrorCode ierr,char *message)
101986eef2eSBarry Smith 
102d083f849SBarry Smith    Collective
103986eef2eSBarry Smith 
104986eef2eSBarry Smith    Input Parameters:
105986eef2eSBarry Smith +  comm - A communicator, use PETSC_COMM_SELF unless you know all ranks of another communicator will detect the error
106986eef2eSBarry Smith .  ierr - nonzero error code, see the list of standard error codes in include/petscerror.h
107986eef2eSBarry Smith -  message - error message
108986eef2eSBarry Smith 
109986eef2eSBarry Smith   Level: developer
110986eef2eSBarry Smith 
111986eef2eSBarry Smith    Notes:
112986eef2eSBarry 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
113986eef2eSBarry Smith     which is registered with MPI_Add_error_code() when PETSc is initialized.
114986eef2eSBarry Smith 
115986eef2eSBarry Smith .seealso: SETERRQ(), CHKERRQ(), CHKERRMPI(), PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), CHKERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2(), SETERRQ3()
116986eef2eSBarry Smith M*/
11712801b39SBarry Smith #define SETERRMPI(comm,ierr,s) return (PetscError(comm,__LINE__,PETSC_FUNCTION_NAME,__FILE__,ierr,PETSC_ERROR_INITIAL,s),PETSC_MPI_ERROR_CODE)
11830de9b25SBarry Smith 
11930de9b25SBarry Smith /*MC
12030de9b25SBarry Smith    SETERRQ1 - Macro that is called when an error has been detected,
12130de9b25SBarry Smith 
12230de9b25SBarry Smith    Synopsis:
123aaa7dc30SBarry Smith    #include <petscsys.h>
1243af045c5SBarry Smith    PetscErrorCode SETERRQ1(MPI_Comm comm,PetscErrorCode ierr,char *formatmessage,arg)
12530de9b25SBarry Smith 
126d083f849SBarry Smith    Collective
12730de9b25SBarry Smith 
12830de9b25SBarry Smith    Input Parameters:
129fa190f98SMatthew G. Knepley +  comm - A communicator, so that the error can be collective
1303af045c5SBarry Smith .  ierr - nonzero error code, see the list of standard error codes in include/petscerror.h
13130de9b25SBarry Smith .  message - error message in the printf format
13230de9b25SBarry Smith -  arg - argument (for example an integer, string or double)
13330de9b25SBarry Smith 
13430de9b25SBarry Smith   Level: beginner
13530de9b25SBarry Smith 
13630de9b25SBarry Smith    Notes:
13730de9b25SBarry Smith     Once the error handler is called the calling function is then returned from with the given error code.
13830de9b25SBarry Smith 
13930de9b25SBarry Smith    Experienced users can set the error handler with PetscPushErrorHandler().
14030de9b25SBarry Smith 
14191d3bdf4SKris Buschelman .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), CHKERRQ(), CHKMEMQ, SETERRQ(), SETERRQ2(), SETERRQ3()
14230de9b25SBarry Smith M*/
1433af045c5SBarry Smith #define SETERRQ1(comm,ierr,s,a1) return PetscError(comm,__LINE__,PETSC_FUNCTION_NAME,__FILE__,ierr,PETSC_ERROR_INITIAL,s,a1)
14430de9b25SBarry Smith 
14530de9b25SBarry Smith /*MC
14630de9b25SBarry Smith    SETERRQ2 - Macro that is called when an error has been detected,
14730de9b25SBarry Smith 
14830de9b25SBarry Smith    Synopsis:
149aaa7dc30SBarry Smith    #include <petscsys.h>
1503af045c5SBarry Smith    PetscErrorCode SETERRQ2(MPI_Comm comm,PetscErrorCode ierr,char *formatmessage,arg1,arg2)
15130de9b25SBarry Smith 
152d083f849SBarry Smith    Collective
15330de9b25SBarry Smith 
15430de9b25SBarry Smith    Input Parameters:
155fa190f98SMatthew G. Knepley +  comm - A communicator, so that the error can be collective
1563af045c5SBarry Smith .  ierr - nonzero error code, see the list of standard error codes in include/petscerror.h
15730de9b25SBarry Smith .  message - error message in the printf format
15830de9b25SBarry Smith .  arg1 - argument (for example an integer, string or double)
15930de9b25SBarry Smith -  arg2 - argument (for example an integer, string or double)
16030de9b25SBarry Smith 
16130de9b25SBarry Smith   Level: beginner
16230de9b25SBarry Smith 
16330de9b25SBarry Smith    Notes:
16430de9b25SBarry Smith     Once the error handler is called the calling function is then returned from with the given error code.
16530de9b25SBarry Smith 
16630de9b25SBarry Smith    Experienced users can set the error handler with PetscPushErrorHandler().
16730de9b25SBarry Smith 
1686024bd2cSBarry Smith .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), CHKERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ3()
16930de9b25SBarry Smith M*/
1703af045c5SBarry Smith #define SETERRQ2(comm,ierr,s,a1,a2) return PetscError(comm,__LINE__,PETSC_FUNCTION_NAME,__FILE__,ierr,PETSC_ERROR_INITIAL,s,a1,a2)
17130de9b25SBarry Smith 
17230de9b25SBarry Smith /*MC
17330de9b25SBarry Smith    SETERRQ3 - Macro that is called when an error has been detected,
17430de9b25SBarry Smith 
17530de9b25SBarry Smith    Synopsis:
176aaa7dc30SBarry Smith    #include <petscsys.h>
1773af045c5SBarry Smith    PetscErrorCode SETERRQ3(MPI_Comm comm,PetscErrorCode ierr,char *formatmessage,arg1,arg2,arg3)
17830de9b25SBarry Smith 
179d083f849SBarry Smith    Collective
18030de9b25SBarry Smith 
18130de9b25SBarry Smith    Input Parameters:
182fa190f98SMatthew G. Knepley +  comm - A communicator, so that the error can be collective
1833af045c5SBarry Smith .  ierr - nonzero error code, see the list of standard error codes in include/petscerror.h
18430de9b25SBarry Smith .  message - error message in the printf format
18530de9b25SBarry Smith .  arg1 - argument (for example an integer, string or double)
18630de9b25SBarry Smith .  arg2 - argument (for example an integer, string or double)
18730de9b25SBarry Smith -  arg3 - argument (for example an integer, string or double)
18830de9b25SBarry Smith 
18930de9b25SBarry Smith   Level: beginner
19030de9b25SBarry Smith 
19130de9b25SBarry Smith    Notes:
19230de9b25SBarry Smith     Once the error handler is called the calling function is then returned from with the given error code.
19330de9b25SBarry Smith 
194f621e05eSBarry Smith     There are also versions for 4, 5, 6 and 7 arguments.
195f621e05eSBarry Smith 
19630de9b25SBarry Smith    Experienced users can set the error handler with PetscPushErrorHandler().
19730de9b25SBarry Smith 
1986024bd2cSBarry Smith .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), CHKERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2()
19930de9b25SBarry Smith M*/
2003af045c5SBarry 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)
20130de9b25SBarry Smith 
202fa190f98SMatthew G. Knepley /*MC
203fa190f98SMatthew G. Knepley    SETERRQ4 - Macro that is called when an error has been detected,
204fa190f98SMatthew G. Knepley 
205fa190f98SMatthew G. Knepley    Synopsis:
206fa190f98SMatthew G. Knepley    #include <petscsys.h>
2073af045c5SBarry Smith    PetscErrorCode SETERRQ4(MPI_Comm comm,PetscErrorCode ierr,char *formatmessage,arg1,arg2,arg3)
208fa190f98SMatthew G. Knepley 
209d083f849SBarry Smith    Collective
210fa190f98SMatthew G. Knepley 
211fa190f98SMatthew G. Knepley    Input Parameters:
212fa190f98SMatthew G. Knepley +  comm - A communicator, so that the error can be collective
2133af045c5SBarry Smith .  ierr - nonzero error code, see the list of standard error codes in include/petscerror.h
214fa190f98SMatthew G. Knepley .  message - error message in the printf format
215fa190f98SMatthew G. Knepley .  arg1 - argument (for example an integer, string or double)
216fa190f98SMatthew G. Knepley .  arg2 - argument (for example an integer, string or double)
217fa190f98SMatthew G. Knepley .  arg3 - argument (for example an integer, string or double)
218fa190f98SMatthew G. Knepley -  arg4 - argument (for example an integer, string or double)
219fa190f98SMatthew G. Knepley 
220fa190f98SMatthew G. Knepley   Level: beginner
221fa190f98SMatthew G. Knepley 
222fa190f98SMatthew G. Knepley    Notes:
223fa190f98SMatthew G. Knepley     Once the error handler is called the calling function is then returned from with the given error code.
224fa190f98SMatthew G. Knepley 
225fa190f98SMatthew G. Knepley     There are also versions for 4, 5, 6 and 7 arguments.
226fa190f98SMatthew G. Knepley 
227fa190f98SMatthew G. Knepley    Experienced users can set the error handler with PetscPushErrorHandler().
228fa190f98SMatthew G. Knepley 
229fa190f98SMatthew G. Knepley .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), CHKERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2()
230fa190f98SMatthew G. Knepley M*/
2313af045c5SBarry 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)
232fa190f98SMatthew G. Knepley 
233fa190f98SMatthew G. Knepley /*MC
234fa190f98SMatthew G. Knepley    SETERRQ5 - Macro that is called when an error has been detected,
235fa190f98SMatthew G. Knepley 
236fa190f98SMatthew G. Knepley    Synopsis:
237fa190f98SMatthew G. Knepley    #include <petscsys.h>
2383af045c5SBarry Smith    PetscErrorCode SETERRQ5(MPI_Comm comm,PetscErrorCode ierr,char *formatmessage,arg1,arg2,arg3)
239fa190f98SMatthew G. Knepley 
240d083f849SBarry Smith    Collective
241fa190f98SMatthew G. Knepley 
242fa190f98SMatthew G. Knepley    Input Parameters:
243fa190f98SMatthew G. Knepley +  comm - A communicator, so that the error can be collective
2443af045c5SBarry Smith .  ierr - nonzero error code, see the list of standard error codes in include/petscerror.h
245fa190f98SMatthew G. Knepley .  message - error message in the printf format
246fa190f98SMatthew G. Knepley .  arg1 - argument (for example an integer, string or double)
247fa190f98SMatthew G. Knepley .  arg2 - argument (for example an integer, string or double)
248fa190f98SMatthew G. Knepley .  arg3 - argument (for example an integer, string or double)
249fa190f98SMatthew G. Knepley .  arg4 - argument (for example an integer, string or double)
250fa190f98SMatthew G. Knepley -  arg5 - argument (for example an integer, string or double)
251fa190f98SMatthew G. Knepley 
252fa190f98SMatthew G. Knepley   Level: beginner
253fa190f98SMatthew G. Knepley 
254fa190f98SMatthew G. Knepley    Notes:
255fa190f98SMatthew G. Knepley     Once the error handler is called the calling function is then returned from with the given error code.
256fa190f98SMatthew G. Knepley 
257fa190f98SMatthew G. Knepley     There are also versions for 4, 5, 6 and 7 arguments.
258fa190f98SMatthew G. Knepley 
259fa190f98SMatthew G. Knepley    Experienced users can set the error handler with PetscPushErrorHandler().
260fa190f98SMatthew G. Knepley 
261fa190f98SMatthew G. Knepley .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), CHKERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2()
262fa190f98SMatthew G. Knepley M*/
2633af045c5SBarry 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)
264fa190f98SMatthew G. Knepley 
265fa190f98SMatthew G. Knepley /*MC
266fa190f98SMatthew G. Knepley    SETERRQ6 - Macro that is called when an error has been detected,
267fa190f98SMatthew G. Knepley 
268fa190f98SMatthew G. Knepley    Synopsis:
269fa190f98SMatthew G. Knepley    #include <petscsys.h>
2703af045c5SBarry Smith    PetscErrorCode SETERRQ6(MPI_Comm comm,PetscErrorCode ierr,char *formatmessage,arg1,arg2,arg3)
271fa190f98SMatthew G. Knepley 
272d083f849SBarry Smith    Collective
273fa190f98SMatthew G. Knepley 
274fa190f98SMatthew G. Knepley    Input Parameters:
275fa190f98SMatthew G. Knepley +  comm - A communicator, so that the error can be collective
2763af045c5SBarry Smith .  ierr - nonzero error code, see the list of standard error codes in include/petscerror.h
277fa190f98SMatthew G. Knepley .  message - error message in the printf format
278fa190f98SMatthew G. Knepley .  arg1 - argument (for example an integer, string or double)
279fa190f98SMatthew G. Knepley .  arg2 - argument (for example an integer, string or double)
280fa190f98SMatthew G. Knepley .  arg3 - argument (for example an integer, string or double)
281fa190f98SMatthew G. Knepley .  arg4 - argument (for example an integer, string or double)
282fa190f98SMatthew G. Knepley .  arg5 - argument (for example an integer, string or double)
283fa190f98SMatthew G. Knepley -  arg6 - argument (for example an integer, string or double)
284fa190f98SMatthew G. Knepley 
285fa190f98SMatthew G. Knepley   Level: beginner
286fa190f98SMatthew G. Knepley 
287fa190f98SMatthew G. Knepley    Notes:
288fa190f98SMatthew G. Knepley     Once the error handler is called the calling function is then returned from with the given error code.
289fa190f98SMatthew G. Knepley 
290fa190f98SMatthew G. Knepley     There are also versions for 4, 5, 6 and 7 arguments.
291fa190f98SMatthew G. Knepley 
292fa190f98SMatthew G. Knepley    Experienced users can set the error handler with PetscPushErrorHandler().
293fa190f98SMatthew G. Knepley 
294fa190f98SMatthew G. Knepley .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), CHKERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2()
295fa190f98SMatthew G. Knepley M*/
2963af045c5SBarry 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)
297fa190f98SMatthew G. Knepley 
298fa190f98SMatthew G. Knepley /*MC
299fa190f98SMatthew G. Knepley    SETERRQ7 - Macro that is called when an error has been detected,
300fa190f98SMatthew G. Knepley 
301fa190f98SMatthew G. Knepley    Synopsis:
302fa190f98SMatthew G. Knepley    #include <petscsys.h>
3033af045c5SBarry Smith    PetscErrorCode SETERRQ7(MPI_Comm comm,PetscErrorCode ierr,char *formatmessage,arg1,arg2,arg3)
304fa190f98SMatthew G. Knepley 
305d083f849SBarry Smith    Collective
306fa190f98SMatthew G. Knepley 
307fa190f98SMatthew G. Knepley    Input Parameters:
308fa190f98SMatthew G. Knepley +  comm - A communicator, so that the error can be collective
3093af045c5SBarry Smith .  ierr - nonzero error code, see the list of standard error codes in include/petscerror.h
310fa190f98SMatthew G. Knepley .  message - error message in the printf format
311fa190f98SMatthew G. Knepley .  arg1 - argument (for example an integer, string or double)
312fa190f98SMatthew G. Knepley .  arg2 - argument (for example an integer, string or double)
313fa190f98SMatthew G. Knepley .  arg3 - argument (for example an integer, string or double)
314fa190f98SMatthew G. Knepley .  arg4 - argument (for example an integer, string or double)
315fa190f98SMatthew G. Knepley .  arg5 - argument (for example an integer, string or double)
316fa190f98SMatthew G. Knepley .  arg6 - argument (for example an integer, string or double)
317fa190f98SMatthew G. Knepley -  arg7 - argument (for example an integer, string or double)
318fa190f98SMatthew G. Knepley 
319fa190f98SMatthew G. Knepley   Level: beginner
320fa190f98SMatthew G. Knepley 
321fa190f98SMatthew G. Knepley    Notes:
322fa190f98SMatthew G. Knepley     Once the error handler is called the calling function is then returned from with the given error code.
323fa190f98SMatthew G. Knepley 
324fa190f98SMatthew G. Knepley     There are also versions for 4, 5, 6 and 7 arguments.
325fa190f98SMatthew G. Knepley 
326fa190f98SMatthew G. Knepley    Experienced users can set the error handler with PetscPushErrorHandler().
327fa190f98SMatthew G. Knepley 
328fa190f98SMatthew G. Knepley .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), CHKERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2()
329fa190f98SMatthew G. Knepley M*/
3303af045c5SBarry 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)
331fa190f98SMatthew G. Knepley 
332fa190f98SMatthew G. Knepley /*MC
333fa190f98SMatthew G. Knepley    SETERRQ8 - Macro that is called when an error has been detected,
334fa190f98SMatthew G. Knepley 
335fa190f98SMatthew G. Knepley    Synopsis:
336fa190f98SMatthew G. Knepley    #include <petscsys.h>
3373af045c5SBarry Smith    PetscErrorCode SETERRQ8(MPI_Comm comm,PetscErrorCode ierr,char *formatmessage,arg1,arg2,arg3)
338fa190f98SMatthew G. Knepley 
339d083f849SBarry Smith    Collective
340fa190f98SMatthew G. Knepley 
341fa190f98SMatthew G. Knepley    Input Parameters:
342fa190f98SMatthew G. Knepley +  comm - A communicator, so that the error can be collective
3433af045c5SBarry Smith .  ierr - nonzero error code, see the list of standard error codes in include/petscerror.h
344fa190f98SMatthew G. Knepley .  message - error message in the printf format
345fa190f98SMatthew G. Knepley .  arg1 - argument (for example an integer, string or double)
346fa190f98SMatthew G. Knepley .  arg2 - argument (for example an integer, string or double)
347fa190f98SMatthew G. Knepley .  arg3 - argument (for example an integer, string or double)
348fa190f98SMatthew G. Knepley .  arg4 - argument (for example an integer, string or double)
349fa190f98SMatthew G. Knepley .  arg5 - argument (for example an integer, string or double)
350fa190f98SMatthew G. Knepley .  arg6 - argument (for example an integer, string or double)
351fa190f98SMatthew G. Knepley .  arg7 - argument (for example an integer, string or double)
352fa190f98SMatthew G. Knepley -  arg8 - argument (for example an integer, string or double)
353fa190f98SMatthew G. Knepley 
354fa190f98SMatthew G. Knepley   Level: beginner
355fa190f98SMatthew G. Knepley 
356fa190f98SMatthew G. Knepley    Notes:
357fa190f98SMatthew G. Knepley     Once the error handler is called the calling function is then returned from with the given error code.
358fa190f98SMatthew G. Knepley 
359fa190f98SMatthew G. Knepley     There are also versions for 4, 5, 6 and 7 arguments.
360fa190f98SMatthew G. Knepley 
361fa190f98SMatthew G. Knepley    Experienced users can set the error handler with PetscPushErrorHandler().
362fa190f98SMatthew G. Knepley 
363fa190f98SMatthew G. Knepley .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), CHKERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2()
364fa190f98SMatthew G. Knepley M*/
3653af045c5SBarry 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)
366fa190f98SMatthew G. Knepley 
367fa190f98SMatthew G. Knepley /*MC
368ee8199e6SMatthew G. Knepley    SETERRQ9 - Macro that is called when an error has been detected,
369ee8199e6SMatthew G. Knepley 
370ee8199e6SMatthew G. Knepley    Synopsis:
371ee8199e6SMatthew G. Knepley    #include <petscsys.h>
372ee8199e6SMatthew G. Knepley    PetscErrorCode SETERRQ9(MPI_Comm comm,PetscErrorCode ierr,char *formatmessage,arg1,arg2,arg3)
373ee8199e6SMatthew G. Knepley 
374d083f849SBarry Smith    Collective
375ee8199e6SMatthew G. Knepley 
376ee8199e6SMatthew G. Knepley    Input Parameters:
377ee8199e6SMatthew G. Knepley +  comm - A communicator, so that the error can be collective
378ee8199e6SMatthew G. Knepley .  ierr - nonzero error code, see the list of standard error codes in include/petscerror.h
379ee8199e6SMatthew G. Knepley .  message - error message in the printf format
380ee8199e6SMatthew G. Knepley .  arg1 - argument (for example an integer, string or double)
381ee8199e6SMatthew G. Knepley .  arg2 - argument (for example an integer, string or double)
382ee8199e6SMatthew G. Knepley .  arg3 - argument (for example an integer, string or double)
383ee8199e6SMatthew G. Knepley .  arg4 - argument (for example an integer, string or double)
384ee8199e6SMatthew G. Knepley .  arg5 - argument (for example an integer, string or double)
385ee8199e6SMatthew G. Knepley .  arg6 - argument (for example an integer, string or double)
386ee8199e6SMatthew G. Knepley .  arg7 - argument (for example an integer, string or double)
387ee8199e6SMatthew G. Knepley .  arg8 - argument (for example an integer, string or double)
388ee8199e6SMatthew G. Knepley -  arg9 - argument (for example an integer, string or double)
389ee8199e6SMatthew G. Knepley 
390ee8199e6SMatthew G. Knepley   Level: beginner
391ee8199e6SMatthew G. Knepley 
392ee8199e6SMatthew G. Knepley    Notes:
393ee8199e6SMatthew G. Knepley     Once the error handler is called the calling function is then returned from with the given error code.
394ee8199e6SMatthew G. Knepley 
395ee8199e6SMatthew G. Knepley     There are also versions for 0 to 9 arguments.
396ee8199e6SMatthew G. Knepley 
397ee8199e6SMatthew G. Knepley    Experienced users can set the error handler with PetscPushErrorHandler().
398ee8199e6SMatthew G. Knepley 
399ee8199e6SMatthew G. Knepley .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), CHKERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2()
400ee8199e6SMatthew G. Knepley M*/
401ee8199e6SMatthew 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)
402ee8199e6SMatthew G. Knepley 
403ee8199e6SMatthew G. Knepley /*MC
404fa190f98SMatthew G. Knepley    SETERRABORT - Macro that can be called when an error has been detected,
405fa190f98SMatthew G. Knepley 
406fa190f98SMatthew G. Knepley    Synopsis:
407fa190f98SMatthew G. Knepley    #include <petscsys.h>
4083af045c5SBarry Smith    PetscErrorCode SETERRABORT(MPI_Comm comm,PetscErrorCode ierr,char *message)
409fa190f98SMatthew G. Knepley 
410d083f849SBarry Smith    Collective
411fa190f98SMatthew G. Knepley 
412fa190f98SMatthew G. Knepley    Input Parameters:
413fa190f98SMatthew G. Knepley +  comm - A communicator, so that the error can be collective
4143af045c5SBarry Smith .  ierr - nonzero error code, see the list of standard error codes in include/petscerror.h
415fa190f98SMatthew G. Knepley -  message - error message in the printf format
416fa190f98SMatthew G. Knepley 
417fa190f98SMatthew G. Knepley   Level: beginner
418fa190f98SMatthew G. Knepley 
419fa190f98SMatthew G. Knepley    Notes:
420fa190f98SMatthew G. Knepley     This function just calls MPI_Abort().
421fa190f98SMatthew G. Knepley 
422fa190f98SMatthew G. Knepley .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), CHKERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2()
423fa190f98SMatthew G. Knepley M*/
4243af045c5SBarry 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)
4259a00fa46SSatish Balay 
42630de9b25SBarry Smith /*MC
42730de9b25SBarry Smith    CHKERRQ - Checks error code, if non-zero it calls the error handler and then returns
42830de9b25SBarry Smith 
42930de9b25SBarry Smith    Synopsis:
430aaa7dc30SBarry Smith    #include <petscsys.h>
4313af045c5SBarry Smith    PetscErrorCode CHKERRQ(PetscErrorCode ierr)
43230de9b25SBarry Smith 
433eca87e8dSBarry Smith    Not Collective
43430de9b25SBarry Smith 
43530de9b25SBarry Smith    Input Parameters:
4363af045c5SBarry Smith .  ierr - nonzero error code, see the list of standard error codes in include/petscerror.h
43730de9b25SBarry Smith 
43830de9b25SBarry Smith   Level: beginner
43930de9b25SBarry Smith 
44030de9b25SBarry Smith    Notes:
44130de9b25SBarry Smith     Once the error handler is called the calling function is then returned from with the given error code.
44230de9b25SBarry Smith 
44330de9b25SBarry Smith     Experienced users can set the error handler with PetscPushErrorHandler().
4445324ea47SKris Buschelman 
4453af045c5SBarry Smith     CHKERRQ(ierr) is fundamentally a macro replacement for
4463af045c5SBarry Smith          if (ierr) return(PetscError(...,ierr,...));
4475324ea47SKris Buschelman 
4485324ea47SKris Buschelman     Although typical usage resembles "void CHKERRQ(PetscErrorCode)" as described above, for certain uses it is
4495324ea47SKris Buschelman     highly inappropriate to use it in this manner as it invokes return(PetscErrorCode). In particular,
4505324ea47SKris Buschelman     it cannot be used in functions which return(void) or any other datatype.  In these types of functions,
45158ebbce7SBarry Smith     you can use CHKERRV() which returns without an error code (bad idea since the error is ignored or
4523af045c5SBarry Smith          if (ierr) {PetscError(....); return(YourReturnType);}
4530298fd71SBarry Smith     where you may pass back a NULL to indicate an error. You can also call CHKERRABORT(comm,n) to have
45458ebbce7SBarry Smith     MPI_Abort() returned immediately.
45558ebbce7SBarry Smith 
45691d3bdf4SKris Buschelman .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), SETERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2(), SETERRQ2()
45730de9b25SBarry Smith M*/
4583af045c5SBarry Smith #define CHKERRQ(ierr)          do {if (PetscUnlikely(ierr)) return PetscError(PETSC_COMM_SELF,__LINE__,PETSC_FUNCTION_NAME,__FILE__,ierr,PETSC_ERROR_REPEAT," ");} while (0)
459f01fac0dSBarry Smith #define CHKERRV(ierr)          do {if (PetscUnlikely(ierr)) {ierr = PetscError(PETSC_COMM_SELF,__LINE__,PETSC_FUNCTION_NAME,__FILE__,ierr,PETSC_ERROR_REPEAT," ");return;}} while(0)
4603af045c5SBarry Smith #define CHKERRABORT(comm,ierr) do {if (PetscUnlikely(ierr)) {PetscError(PETSC_COMM_SELF,__LINE__,PETSC_FUNCTION_NAME,__FILE__,ierr,PETSC_ERROR_REPEAT," ");MPI_Abort(comm,ierr);}} while (0)
4617f022bafSSatish Balay #define CHKERRCONTINUE(ierr)   do {if (PetscUnlikely(ierr)) {PetscError(PETSC_COMM_SELF,__LINE__,PETSC_FUNCTION_NAME,__FILE__,ierr,PETSC_ERROR_REPEAT," ");}} while (0)
462986eef2eSBarry Smith 
463986eef2eSBarry Smith 
464986eef2eSBarry Smith /*MC
465986eef2eSBarry Smith    CHKERRMPI - Checks error code, if non-zero it calls the error handler and then returns
466986eef2eSBarry Smith 
467986eef2eSBarry Smith    Synopsis:
468986eef2eSBarry Smith    #include <petscsys.h>
469986eef2eSBarry Smith    PetscErrorCode CHKERRMPI(PetscErrorCode ierr)
470986eef2eSBarry Smith 
471986eef2eSBarry Smith    Not Collective
472986eef2eSBarry Smith 
473986eef2eSBarry Smith    Input Parameters:
474986eef2eSBarry Smith .  ierr - nonzero error code, see the list of standard error codes in include/petscerror.h
475986eef2eSBarry Smith 
476986eef2eSBarry Smith   Level: developer
477986eef2eSBarry Smith 
478986eef2eSBarry Smith    Notes:
479986eef2eSBarry 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
480986eef2eSBarry Smith     which is registered with MPI_Add_error_code() when PETSc is initialized.
481986eef2eSBarry Smith 
482986eef2eSBarry Smith .seealso: CHKERRQ(), PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), SETERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2(), SETERRQ2()
483986eef2eSBarry Smith M*/
48412801b39SBarry 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)
48585614651SBarry Smith 
486fd705b32SMatthew Knepley #ifdef PETSC_CLANGUAGE_CXX
487fd705b32SMatthew Knepley 
488cc26af49SMatthew Knepley /*MC
489cc26af49SMatthew Knepley    CHKERRXX - Checks error code, if non-zero it calls the C++ error handler which throws an exception
490cc26af49SMatthew Knepley 
491cc26af49SMatthew Knepley    Synopsis:
492aaa7dc30SBarry Smith    #include <petscsys.h>
4933af045c5SBarry Smith    void CHKERRXX(PetscErrorCode ierr)
494cc26af49SMatthew Knepley 
495eca87e8dSBarry Smith    Not Collective
496cc26af49SMatthew Knepley 
497cc26af49SMatthew Knepley    Input Parameters:
4983af045c5SBarry Smith .  ierr - nonzero error code, see the list of standard error codes in include/petscerror.h
499cc26af49SMatthew Knepley 
500cc26af49SMatthew Knepley   Level: beginner
501cc26af49SMatthew Knepley 
502cc26af49SMatthew Knepley    Notes:
503cc26af49SMatthew Knepley     Once the error handler throws a ??? exception.
504cc26af49SMatthew Knepley 
505cc26af49SMatthew Knepley     You can use CHKERRV() which returns without an error code (bad idea since the error is ignored)
506cc26af49SMatthew Knepley     or CHKERRABORT(comm,n) to have MPI_Abort() returned immediately.
507cc26af49SMatthew Knepley 
508cc26af49SMatthew Knepley .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), SETERRQ(), CHKERRQ(), CHKMEMQ
509cc26af49SMatthew Knepley M*/
5103af045c5SBarry 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)
511fd705b32SMatthew Knepley 
512fd705b32SMatthew Knepley #endif
513fd705b32SMatthew Knepley 
514*7fd2f626SJose E. Roman #if defined(PETSC_HAVE_CUDA)
5155be1650bSAlejandro Lamas Daviña #define CHKERRCUDA(err)   do {if (PetscUnlikely(err)) SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_LIB,"CUDA error %d",err);} while(0)
5165be1650bSAlejandro Lamas Daviña #define CHKERRCUBLAS(err) do {if (PetscUnlikely(err)) SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_LIB,"CUBLAS error %d",err);} while(0)
517*7fd2f626SJose E. Roman #define CHKERRCUSOLVER(err) do {if (PetscUnlikely(err)) SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_LIB,"CUSOLVER error %d",err);} while(0)
518*7fd2f626SJose E. Roman #endif
51982f73ecaSAlejandro Lamas Daviña 
52030de9b25SBarry Smith /*MC
52130de9b25SBarry Smith    CHKMEMQ - Checks the memory for corruption, calls error handler if any is detected
52230de9b25SBarry Smith 
52330de9b25SBarry Smith    Synopsis:
524aaa7dc30SBarry Smith    #include <petscsys.h>
52591d3bdf4SKris Buschelman    CHKMEMQ;
52630de9b25SBarry Smith 
527eca87e8dSBarry Smith    Not Collective
528eca87e8dSBarry Smith 
52930de9b25SBarry Smith   Level: beginner
53030de9b25SBarry Smith 
53130de9b25SBarry Smith    Notes:
532a8d69d7bSBarry Smith     We highly recommend using valgrind https://www.mcs.anl.gov/petsc/documentation/faq.html#valgrind for finding memory problems. This is useful
5331957e957SBarry Smith     on systems that do not have valgrind, but much much less useful.
5341957e957SBarry Smith 
53579dccf82SBarry Smith     Must run with the option -malloc_debug (-malloc_test in debug mode; or if PetscMallocSetDebug() called) to enable this option
53630de9b25SBarry Smith 
53730de9b25SBarry Smith     Once the error handler is called the calling function is then returned from with the given error code.
53830de9b25SBarry Smith 
53930de9b25SBarry Smith     By defaults prints location where memory that is corrupted was allocated.
54030de9b25SBarry Smith 
541f621e05eSBarry Smith     Use CHKMEMA for functions that return void
542f621e05eSBarry Smith 
5436024bd2cSBarry Smith .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), SETERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2(), SETERRQ3(),
544ff002950SBarry Smith           PetscMallocValidate()
54530de9b25SBarry Smith M*/
546efca3c55SSatish Balay #define CHKMEMQ do {PetscErrorCode _7_ierr = PetscMallocValidate(__LINE__,PETSC_FUNCTION_NAME,__FILE__);CHKERRQ(_7_ierr);} while(0)
54785614651SBarry Smith 
548efca3c55SSatish Balay #define CHKMEMA PetscMallocValidate(__LINE__,PETSC_FUNCTION_NAME,__FILE__)
549e68848bdSBarry Smith 
550668f157eSBarry Smith /*E
551668f157eSBarry Smith   PetscErrorType - passed to the PETSc error handling routines indicating if this is the first or a later call to the error handlers
552668f157eSBarry Smith 
553668f157eSBarry Smith   Level: advanced
554668f157eSBarry Smith 
555d736bfebSBarry Smith   PETSC_ERROR_IN_CXX indicates the error was detected in C++ and an exception should be generated
556d736bfebSBarry Smith 
55795452b02SPatrick Sanan   Developer Notes:
55895452b02SPatrick Sanan     This is currently used to decide when to print the detailed information about the run in PetscTraceBackErrorHandler()
559668f157eSBarry Smith 
560d736bfebSBarry Smith .seealso: PetscError(), SETERRXX()
561668f157eSBarry Smith E*/
562d736bfebSBarry Smith typedef enum {PETSC_ERROR_INITIAL=0,PETSC_ERROR_REPEAT=1,PETSC_ERROR_IN_CXX = 2} PetscErrorType;
5634b209cf6SBarry Smith 
564eb9e708aSLisandro Dalcin #if defined(__clang_analyzer__)
565eb9e708aSLisandro Dalcin __attribute__((analyzer_noreturn))
566eb9e708aSLisandro Dalcin #endif
567eb9e708aSLisandro Dalcin PETSC_EXTERN PetscErrorCode PetscError(MPI_Comm,int,const char*,const char*,PetscErrorCode,PetscErrorType,const char*,...);
568eb9e708aSLisandro Dalcin 
569014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscErrorPrintfInitialize(void);
570014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscErrorMessage(int,const char*[],char **);
571efca3c55SSatish Balay PETSC_EXTERN PetscErrorCode PetscTraceBackErrorHandler(MPI_Comm,int,const char*,const char*,PetscErrorCode,PetscErrorType,const char*,void*);
572efca3c55SSatish Balay PETSC_EXTERN PetscErrorCode PetscIgnoreErrorHandler(MPI_Comm,int,const char*,const char*,PetscErrorCode,PetscErrorType,const char*,void*);
573efca3c55SSatish Balay PETSC_EXTERN PetscErrorCode PetscEmacsClientErrorHandler(MPI_Comm,int,const char*,const char*,PetscErrorCode,PetscErrorType,const char*,void*);
574efca3c55SSatish Balay PETSC_EXTERN PetscErrorCode PetscMPIAbortErrorHandler(MPI_Comm,int,const char*,const char*,PetscErrorCode,PetscErrorType,const char*,void*);
575efca3c55SSatish Balay PETSC_EXTERN PetscErrorCode PetscAbortErrorHandler(MPI_Comm,int,const char*,const char*,PetscErrorCode,PetscErrorType,const char*,void*);
576efca3c55SSatish Balay PETSC_EXTERN PetscErrorCode PetscAttachDebuggerErrorHandler(MPI_Comm,int,const char*,const char*,PetscErrorCode,PetscErrorType,const char*,void*);
577efca3c55SSatish Balay PETSC_EXTERN PetscErrorCode PetscReturnErrorHandler(MPI_Comm,int,const char*,const char*,PetscErrorCode,PetscErrorType,const char*,void*);
578efca3c55SSatish Balay PETSC_EXTERN PetscErrorCode PetscPushErrorHandler(PetscErrorCode (*handler)(MPI_Comm,int,const char*,const char*,PetscErrorCode,PetscErrorType,const char*,void*),void*);
579014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscPopErrorHandler(void);
5808d359177SBarry Smith PETSC_EXTERN PetscErrorCode PetscSignalHandlerDefault(int,void*);
581014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscPushSignalHandler(PetscErrorCode (*)(int,void *),void*);
582014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscPopSignalHandler(void);
58328559dc8SJed Brown PETSC_EXTERN PetscErrorCode PetscCheckPointerSetIntensity(PetscInt);
584f8a67e6dSJed Brown PETSC_EXTERN void PetscSignalSegvCheckPointer(void);
585329f5518SBarry Smith 
586639ff905SBarry Smith /*MC
587639ff905SBarry Smith     PetscErrorPrintf - Prints error messages.
588639ff905SBarry Smith 
589639ff905SBarry Smith    Synopsis:
590aaa7dc30SBarry Smith     #include <petscsys.h>
591639ff905SBarry Smith      PetscErrorCode (*PetscErrorPrintf)(const char format[],...);
592639ff905SBarry Smith 
593639ff905SBarry Smith     Not Collective
594639ff905SBarry Smith 
595639ff905SBarry Smith     Input Parameters:
596639ff905SBarry Smith .   format - the usual printf() format string
597639ff905SBarry Smith 
598639ff905SBarry Smith    Options Database Keys:
5991957e957SBarry Smith +    -error_output_stdout - cause error messages to be printed to stdout instead of the  (default) stderr
600e1bc860dSBarry Smith -    -error_output_none - to turn off all printing of error messages (does not change the way the error is handled.)
601639ff905SBarry Smith 
60295452b02SPatrick Sanan    Notes:
60395452b02SPatrick Sanan     Use
604639ff905SBarry Smith $     PetscErrorPrintf = PetscErrorPrintfNone; to turn off all printing of error messages (does not change the way the
605639ff905SBarry Smith $                        error is handled.) and
6061957e957SBarry Smith $     PetscErrorPrintf = PetscErrorPrintfDefault; to turn it back on or you can use your own function
607639ff905SBarry Smith 
608639ff905SBarry Smith           Use
609639ff905SBarry Smith      PETSC_STDERR = FILE* obtained from a file open etc. to have stderr printed to the file.
610639ff905SBarry Smith      PETSC_STDOUT = FILE* obtained from a file open etc. to have stdout printed to the file.
611639ff905SBarry Smith 
612639ff905SBarry Smith           Use
613639ff905SBarry Smith       PetscPushErrorHandler() to provide your own error handler that determines what kind of messages to print
614639ff905SBarry Smith 
615639ff905SBarry Smith    Level: developer
616639ff905SBarry Smith 
617639ff905SBarry Smith     Fortran Note:
618639ff905SBarry Smith     This routine is not supported in Fortran.
619639ff905SBarry Smith 
620639ff905SBarry Smith 
6212b60790dSJed Brown .seealso: PetscFPrintf(), PetscSynchronizedPrintf(), PetscHelpPrintf(), PetscPrintf(), PetscPushErrorHandler(), PetscVFPrintf(), PetscHelpPrintf()
622639ff905SBarry Smith M*/
623639ff905SBarry Smith PETSC_EXTERN PetscErrorCode (*PetscErrorPrintf)(const char[],...);
624639ff905SBarry Smith 
625329f5518SBarry Smith typedef enum {PETSC_FP_TRAP_OFF=0,PETSC_FP_TRAP_ON=1} PetscFPTrap;
626014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSetFPTrap(PetscFPTrap);
627014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscFPTrapPush(PetscFPTrap);
628014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscFPTrapPop(void);
62954a8ef01SBarry Smith 
6303a40ed3dSBarry Smith /*
6313a40ed3dSBarry Smith       Allows the code to build a stack frame as it runs
6323a40ed3dSBarry Smith */
6333a40ed3dSBarry Smith 
63499cd645aSJed Brown #define PETSCSTACKSIZE 64
635184914b5SBarry Smith 
6363a40ed3dSBarry Smith typedef struct  {
6370e33f6ddSBarry Smith   const char      *function[PETSCSTACKSIZE];
6380e33f6ddSBarry Smith   const char      *file[PETSCSTACKSIZE];
639184914b5SBarry Smith         int       line[PETSCSTACKSIZE];
640a8d2bbe5SBarry Smith         PetscBool petscroutine[PETSCSTACKSIZE];
641184914b5SBarry Smith         int       currentsize;
642a2f94806SJed Brown         int       hotdepth;
6433a40ed3dSBarry Smith } PetscStack;
6443a40ed3dSBarry Smith 
6451f46d60fSShri Abhyankar PETSC_EXTERN PetscStack *petscstack;
646184914b5SBarry Smith 
6476f5c2d7aSBarry Smith PetscErrorCode  PetscStackCopy(PetscStack*,PetscStack*);
6486f5c2d7aSBarry Smith PetscErrorCode  PetscStackPrint(PetscStack *,FILE*);
6495d12eec7SSatish Balay #if defined(PETSC_SERIALIZE_FUNCTIONS)
6505d12eec7SSatish Balay #include <petsc/private/petscfptimpl.h>
6515d12eec7SSatish Balay /*
6525d12eec7SSatish Balay    Registers the current function into the global function pointer to function name table
6535d12eec7SSatish Balay 
6545d12eec7SSatish Balay    Have to fix this to handle errors but cannot return error since used in PETSC_VIEWER_DRAW_() etc
6555d12eec7SSatish Balay */
6565d12eec7SSatish Balay #define PetscRegister__FUNCT__() do { \
6575d12eec7SSatish Balay   static PetscBool __chked = PETSC_FALSE; \
6585d12eec7SSatish Balay   if (!__chked) {\
6595d12eec7SSatish Balay   void *ptr; PetscDLSym(NULL,PETSC_FUNCTION_NAME,&ptr);\
6605d12eec7SSatish Balay   __chked = PETSC_TRUE;\
6615d12eec7SSatish Balay   }} while (0)
6625d12eec7SSatish Balay #else
6635d12eec7SSatish Balay #define PetscRegister__FUNCT__()
6645d12eec7SSatish Balay #endif
6655d12eec7SSatish Balay 
6662d7c6352SJed Brown #if defined(PETSC_USE_DEBUG)
667dbf62e16SBarry Smith PETSC_STATIC_INLINE PetscBool PetscStackActive(void)
668dbf62e16SBarry Smith {
6695c25fcd7SBarry Smith   return(petscstack ? PETSC_TRUE : PETSC_FALSE);
670dbf62e16SBarry Smith }
6713a40ed3dSBarry Smith 
672441dd030SJed Brown /* Stack handling is based on the following two "NoCheck" macros.  These should only be called directly by other error
673441dd030SJed Brown  * handling macros.  We record the line of the call, which may or may not be the location of the definition.  But is at
674441dd030SJed Brown  * least more useful than "unknown" because it can distinguish multiple calls from the same function.
675441dd030SJed Brown  */
676441dd030SJed Brown 
677a2f94806SJed Brown #define PetscStackPushNoCheck(funct,petsc_routine,hot)                        \
678441dd030SJed Brown   do {                                                                        \
679e04113cfSBarry Smith     PetscStackSAWsTakeAccess();                                                \
6805c25fcd7SBarry Smith     if (petscstack && (petscstack->currentsize < PETSCSTACKSIZE)) {         \
6815c25fcd7SBarry Smith       petscstack->function[petscstack->currentsize]  = funct;               \
6825c25fcd7SBarry Smith       petscstack->file[petscstack->currentsize]      = __FILE__;            \
6835c25fcd7SBarry Smith       petscstack->line[petscstack->currentsize]      = __LINE__;            \
6845c25fcd7SBarry Smith       petscstack->petscroutine[petscstack->currentsize] = petsc_routine;    \
6855c25fcd7SBarry Smith       petscstack->currentsize++;                                             \
686441dd030SJed Brown     }                                                                         \
6875c25fcd7SBarry Smith     if (petscstack) {                                                        \
6885c25fcd7SBarry Smith       petscstack->hotdepth += (hot || petscstack->hotdepth);                \
689a2f94806SJed Brown     }                                                                         \
690e04113cfSBarry Smith     PetscStackSAWsGrantAccess();                                               \
691441dd030SJed Brown   } while (0)
692441dd030SJed Brown 
693441dd030SJed Brown #define PetscStackPopNoCheck                                            \
6945c25fcd7SBarry Smith   do {                                                                  \
695e04113cfSBarry Smith     PetscStackSAWsTakeAccess();                                          \
6965c25fcd7SBarry Smith     if (petscstack && petscstack->currentsize > 0) {                  \
6975c25fcd7SBarry Smith       petscstack->currentsize--;                                       \
6985c25fcd7SBarry Smith       petscstack->function[petscstack->currentsize]  = 0;             \
6995c25fcd7SBarry Smith       petscstack->file[petscstack->currentsize]      = 0;             \
7005c25fcd7SBarry Smith       petscstack->line[petscstack->currentsize]      = 0;             \
7015c25fcd7SBarry Smith       petscstack->petscroutine[petscstack->currentsize] = PETSC_FALSE;\
702441dd030SJed Brown     }                                                                   \
7035c25fcd7SBarry Smith     if (petscstack) {                                                  \
7045c25fcd7SBarry Smith       petscstack->hotdepth = PetscMax(petscstack->hotdepth-1,0);      \
705a2f94806SJed Brown     }                                                                   \
706e04113cfSBarry Smith     PetscStackSAWsGrantAccess();                                         \
707441dd030SJed Brown   } while (0)
708441dd030SJed Brown 
70930de9b25SBarry Smith /*MC
7101957e957SBarry Smith    PetscFunctionBegin - First executable line of each PETSc function,  used for error handling. Final
7111957e957SBarry Smith       line of PETSc functions should be PetscFunctionReturn(0);
71230de9b25SBarry Smith 
71330de9b25SBarry Smith    Synopsis:
714aaa7dc30SBarry Smith    #include <petscsys.h>
71530de9b25SBarry Smith    void PetscFunctionBegin;
71630de9b25SBarry Smith 
717eca87e8dSBarry Smith    Not Collective
718eca87e8dSBarry Smith 
71930de9b25SBarry Smith    Usage:
72030de9b25SBarry Smith .vb
72130de9b25SBarry Smith      int something;
72230de9b25SBarry Smith 
72330de9b25SBarry Smith      PetscFunctionBegin;
72430de9b25SBarry Smith .ve
72530de9b25SBarry Smith 
72630de9b25SBarry Smith    Notes:
7271957e957SBarry Smith      Use PetscFunctionBeginUser for application codes.
7281957e957SBarry Smith 
72930de9b25SBarry Smith      Not available in Fortran
73030de9b25SBarry Smith 
73130de9b25SBarry Smith    Level: developer
73230de9b25SBarry Smith 
7331957e957SBarry Smith .seealso: PetscFunctionReturn(), PetscFunctionBeginHot(), PetscFunctionBeginUser()
73430de9b25SBarry Smith 
73530de9b25SBarry Smith M*/
736441dd030SJed Brown #define PetscFunctionBegin do {                                        \
737a2f94806SJed Brown     PetscStackPushNoCheck(PETSC_FUNCTION_NAME,PETSC_TRUE,PETSC_FALSE); \
738a2f94806SJed Brown     PetscRegister__FUNCT__();                                          \
739a2f94806SJed Brown   } while (0)
740a2f94806SJed Brown 
741a2f94806SJed Brown /*MC
742a2f94806SJed Brown    PetscFunctionBeginHot - Substitute for PetscFunctionBegin to be used in functions that are called in
743a2f94806SJed Brown    performance-critical circumstances.  Use of this function allows for lighter profiling by default.
744a2f94806SJed Brown 
745a2f94806SJed Brown    Synopsis:
746aaa7dc30SBarry Smith    #include <petscsys.h>
747a2f94806SJed Brown    void PetscFunctionBeginHot;
748a2f94806SJed Brown 
749a2f94806SJed Brown    Not Collective
750a2f94806SJed Brown 
751a2f94806SJed Brown    Usage:
752a2f94806SJed Brown .vb
753a2f94806SJed Brown      int something;
754a2f94806SJed Brown 
755a2f94806SJed Brown      PetscFunctionBeginHot;
756a2f94806SJed Brown .ve
757a2f94806SJed Brown 
758a2f94806SJed Brown    Notes:
759a2f94806SJed Brown      Not available in Fortran
760a2f94806SJed Brown 
761a2f94806SJed Brown    Level: developer
762a2f94806SJed Brown 
763a2f94806SJed Brown .seealso: PetscFunctionBegin, PetscFunctionReturn()
764a2f94806SJed Brown 
765a2f94806SJed Brown M*/
766a2f94806SJed Brown #define PetscFunctionBeginHot do {                                     \
767a2f94806SJed Brown     PetscStackPushNoCheck(PETSC_FUNCTION_NAME,PETSC_TRUE,PETSC_TRUE);  \
7682d53ad75SBarry Smith     PetscRegister__FUNCT__();                                          \
76953c77d0aSJed Brown   } while (0)
77053c77d0aSJed Brown 
771a8d2bbe5SBarry Smith /*MC
772a8d2bbe5SBarry Smith    PetscFunctionBeginUser - First executable line of user provided PETSc routine
773a8d2bbe5SBarry Smith 
774a8d2bbe5SBarry Smith    Synopsis:
775aaa7dc30SBarry Smith    #include <petscsys.h>
776a8d2bbe5SBarry Smith    void PetscFunctionBeginUser;
777a8d2bbe5SBarry Smith 
778a8d2bbe5SBarry Smith    Not Collective
779a8d2bbe5SBarry Smith 
780a8d2bbe5SBarry Smith    Usage:
781a8d2bbe5SBarry Smith .vb
782a8d2bbe5SBarry Smith      int something;
783a8d2bbe5SBarry Smith 
784ac285190SBarry Smith      PetscFunctionBeginUser;
785a8d2bbe5SBarry Smith .ve
786a8d2bbe5SBarry Smith 
787a8d2bbe5SBarry Smith    Notes:
7881957e957SBarry Smith       Final line of PETSc functions should be PetscFunctionReturn(0) except for main().
7891957e957SBarry Smith 
790a8d2bbe5SBarry Smith       Not available in Fortran
791a8d2bbe5SBarry Smith 
792ac285190SBarry Smith       This is identical to PetscFunctionBegin except it labels the routine as a user
793ac285190SBarry Smith       routine instead of as a PETSc library routine.
794ac285190SBarry Smith 
795a2f94806SJed Brown    Level: intermediate
796a8d2bbe5SBarry Smith 
797a2f94806SJed Brown .seealso: PetscFunctionReturn(), PetscFunctionBegin, PetscFunctionBeginHot
798a8d2bbe5SBarry Smith 
799a8d2bbe5SBarry Smith M*/
800a8d2bbe5SBarry Smith #define PetscFunctionBeginUser                                          \
801a8d2bbe5SBarry Smith   do {                                                                  \
802a2f94806SJed Brown     PetscStackPushNoCheck(PETSC_FUNCTION_NAME,PETSC_FALSE,PETSC_FALSE); \
803a8d2bbe5SBarry Smith     PetscRegister__FUNCT__();                                           \
804a8d2bbe5SBarry Smith   } while (0)
805a8d2bbe5SBarry Smith 
806a8d2bbe5SBarry Smith 
8075cd90555SBarry Smith #define PetscStackPush(n) \
80861d886c9SShri Abhyankar   do {                                                                  \
809a2f94806SJed Brown     PetscStackPushNoCheck(n,PETSC_FALSE,PETSC_FALSE);                   \
81015681b3cSBarry Smith     CHKMEMQ;                                                            \
81115681b3cSBarry Smith   } while (0)
8123a40ed3dSBarry Smith 
813d64ed03dSBarry Smith #define PetscStackPop                           \
814441dd030SJed Brown     do {                                        \
815441dd030SJed Brown       CHKMEMQ;                                  \
816441dd030SJed Brown       PetscStackPopNoCheck;                     \
81715681b3cSBarry Smith     } while (0)
818d64ed03dSBarry Smith 
81930de9b25SBarry Smith /*MC
82030de9b25SBarry Smith    PetscFunctionReturn - Last executable line of each PETSc function
82130de9b25SBarry Smith         used for error handling. Replaces return()
82230de9b25SBarry Smith 
82330de9b25SBarry Smith    Synopsis:
824aaa7dc30SBarry Smith    #include <petscsys.h>
82530de9b25SBarry Smith    void PetscFunctionReturn(0);
82630de9b25SBarry Smith 
827eca87e8dSBarry Smith    Not Collective
828eca87e8dSBarry Smith 
82930de9b25SBarry Smith    Usage:
83030de9b25SBarry Smith .vb
83130de9b25SBarry Smith     ....
83230de9b25SBarry Smith      PetscFunctionReturn(0);
83330de9b25SBarry Smith    }
83430de9b25SBarry Smith .ve
83530de9b25SBarry Smith 
83630de9b25SBarry Smith    Notes:
83730de9b25SBarry Smith      Not available in Fortran
83830de9b25SBarry Smith 
83930de9b25SBarry Smith    Level: developer
84030de9b25SBarry Smith 
84130de9b25SBarry Smith .seealso: PetscFunctionBegin()
84230de9b25SBarry Smith 
84330de9b25SBarry Smith M*/
8445cd90555SBarry Smith #define PetscFunctionReturn(a) \
8458246ba0dSJed Brown   do {                                                                \
846441dd030SJed Brown     PetscStackPopNoCheck;                                             \
8478246ba0dSJed Brown     return(a);} while (0)
848d64ed03dSBarry Smith 
849ff94ddecSSatish Balay #define PetscFunctionReturnVoid() \
8508246ba0dSJed Brown   do {                                                                \
851441dd030SJed Brown     PetscStackPopNoCheck;                                             \
8528246ba0dSJed Brown     return;} while (0)
85376386721SLisandro Dalcin 
8546d385327SIbrahima Ba #else
8556d385327SIbrahima Ba 
856c82b4e47SJed Brown PETSC_STATIC_INLINE PetscBool PetscStackActive(void) {return PETSC_FALSE;}
857a2f94806SJed Brown #define PetscStackPushNoCheck(funct,petsc_routine,hot) do {} while (0)
858441dd030SJed Brown #define PetscStackPopNoCheck                           do {} while (0)
8593a40ed3dSBarry Smith #define PetscFunctionBegin
8600bdf7c52SPeter Brune #define PetscFunctionBeginUser
861a2f94806SJed Brown #define PetscFunctionBeginHot
8623a40ed3dSBarry Smith #define PetscFunctionReturn(a)    return(a)
8635665465eSBarry Smith #define PetscFunctionReturnVoid() return
864812af9f3SBarry Smith #define PetscStackPop             CHKMEMQ
865812af9f3SBarry Smith #define PetscStackPush(f)         CHKMEMQ
8663a40ed3dSBarry Smith 
8673a40ed3dSBarry Smith #endif
8683a40ed3dSBarry Smith 
869eb6b5d47SBarry Smith /*
870eb6b5d47SBarry Smith     PetscStackCall - Calls an external library routine or user function after pushing the name of the routine on the stack.
871eb6b5d47SBarry Smith 
872eb6b5d47SBarry Smith    Input Parameters:
873eb6b5d47SBarry Smith +   name - string that gives the name of the function being called
874fd3f9acdSBarry Smith -   routine - actual call to the routine, including ierr = and CHKERRQ(ierr);
875fd3f9acdSBarry Smith 
876dbf62e16SBarry Smith    Note: Often one should use PetscStackCallStandard() instead. This routine is intended for external library routines that DO NOT return error codes
877eb6b5d47SBarry Smith 
878eb6b5d47SBarry 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.
879eb6b5d47SBarry Smith 
880fd3f9acdSBarry Smith 
881fd3f9acdSBarry Smith 
882eb6b5d47SBarry Smith */
88330ecc5abSKarl Rupp #define PetscStackCall(name,routine) do { PetscStackPush(name);routine;PetscStackPop; } while(0)
884eb6b5d47SBarry Smith 
885fd3f9acdSBarry Smith /*
886fd3f9acdSBarry Smith     PetscStackCallStandard - Calls an external library routine after pushing the name of the routine on the stack.
887fd3f9acdSBarry Smith 
888fd3f9acdSBarry Smith    Input Parameters:
889fd3f9acdSBarry Smith +   func-  name of the routine
890fd3f9acdSBarry Smith -   args - arguments to the routine surrounded by ()
891fd3f9acdSBarry Smith 
89295452b02SPatrick Sanan    Notes:
89395452b02SPatrick Sanan     This is intended for external package routines that return error codes. Use PetscStackCall() for those that do not.
894dbf62e16SBarry Smith 
895dbf62e16SBarry 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.
896fd3f9acdSBarry Smith 
897fd3f9acdSBarry Smith */
898fd3f9acdSBarry Smith #define PetscStackCallStandard(func,args) do {                                                            \
8991d4906efSStefano Zampini     PetscErrorCode __ierr;                                                                                \
9001d4906efSStefano Zampini     PetscStackPush(#func);                                                                                \
9011d4906efSStefano Zampini     __ierr = func args;                                                                                   \
9021d4906efSStefano Zampini     PetscStackPop;                                                                                        \
9031d4906efSStefano Zampini     if (__ierr) SETERRQ2(PETSC_COMM_SELF,PETSC_ERR_LIB,"Error in %s(): error code %d",#func,(int)__ierr); \
904fd3f9acdSBarry Smith   } while (0)
905fd3f9acdSBarry Smith 
906014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscStackCreate(void);
907639ff905SBarry Smith PETSC_EXTERN PetscErrorCode PetscStackView(FILE*);
908014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscStackDestroy(void);
90906d1fe2cSBarry Smith 
91006d1fe2cSBarry Smith #endif
911