xref: /petsc/include/petscerror.h (revision 61d598d66ed1480d18d848f9a16b05c5941ea883)
154a8ef01SBarry Smith /*
2f621e05eSBarry Smith     Contains all error handling interfaces for PETSc.
354a8ef01SBarry Smith */
445d48df9SBarry Smith #if !defined(__PETSCERROR_H)
545d48df9SBarry 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 #if defined(PETSC_USE_ERRORCHECKING)
68e8b7e333SSatish Balay 
6930de9b25SBarry Smith /*MC
701957e957SBarry Smith    SETERRQ - Macro to be called when an error has been detected,
7130de9b25SBarry Smith 
7230de9b25SBarry Smith    Synopsis:
73aaa7dc30SBarry Smith    #include <petscsys.h>
743af045c5SBarry Smith    PetscErrorCode SETERRQ(MPI_Comm comm,PetscErrorCode ierr,char *message)
7530de9b25SBarry Smith 
763af045c5SBarry Smith    Collective on MPI_Comm
7730de9b25SBarry Smith 
7830de9b25SBarry Smith    Input Parameters:
793af045c5SBarry Smith +  comm - A communicator, use PETSC_COMM_SELF unless you know all ranks of another communicator will detect the error
803af045c5SBarry Smith .  ierr - nonzero error code, see the list of standard error codes in include/petscerror.h
8130de9b25SBarry Smith -  message - error message
8230de9b25SBarry Smith 
8330de9b25SBarry Smith   Level: beginner
8430de9b25SBarry Smith 
8530de9b25SBarry Smith    Notes:
8630de9b25SBarry Smith     Once the error handler is called the calling function is then returned from with the given error code.
8730de9b25SBarry Smith 
8830de9b25SBarry Smith     See SETERRQ1(), SETERRQ2(), SETERRQ3() for versions that take arguments
8930de9b25SBarry Smith 
9058ebbce7SBarry Smith     In Fortran MPI_Abort() is always called
9130de9b25SBarry Smith 
9230de9b25SBarry Smith     Experienced users can set the error handler with PetscPushErrorHandler().
9330de9b25SBarry Smith 
9430de9b25SBarry Smith    Concepts: error^setting condition
9530de9b25SBarry Smith 
9691d3bdf4SKris Buschelman .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), CHKERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2(), SETERRQ3()
9730de9b25SBarry Smith M*/
983af045c5SBarry Smith #define SETERRQ(comm,ierr,s) return PetscError(comm,__LINE__,PETSC_FUNCTION_NAME,__FILE__,ierr,PETSC_ERROR_INITIAL,s)
9912801b39SBarry Smith #define SETERRMPI(comm,ierr,s) return (PetscError(comm,__LINE__,PETSC_FUNCTION_NAME,__FILE__,ierr,PETSC_ERROR_INITIAL,s),PETSC_MPI_ERROR_CODE)
10030de9b25SBarry Smith 
10130de9b25SBarry Smith /*MC
10230de9b25SBarry Smith    SETERRQ1 - Macro that is called when an error has been detected,
10330de9b25SBarry Smith 
10430de9b25SBarry Smith    Synopsis:
105aaa7dc30SBarry Smith    #include <petscsys.h>
1063af045c5SBarry Smith    PetscErrorCode SETERRQ1(MPI_Comm comm,PetscErrorCode ierr,char *formatmessage,arg)
10730de9b25SBarry Smith 
1083af045c5SBarry Smith    Collective on MPI_Comm
10930de9b25SBarry Smith 
11030de9b25SBarry Smith    Input Parameters:
111fa190f98SMatthew G. Knepley +  comm - A communicator, so that the error can be collective
1123af045c5SBarry Smith .  ierr - nonzero error code, see the list of standard error codes in include/petscerror.h
11330de9b25SBarry Smith .  message - error message in the printf format
11430de9b25SBarry Smith -  arg - argument (for example an integer, string or double)
11530de9b25SBarry Smith 
11630de9b25SBarry Smith   Level: beginner
11730de9b25SBarry Smith 
11830de9b25SBarry Smith    Notes:
11930de9b25SBarry Smith     Once the error handler is called the calling function is then returned from with the given error code.
12030de9b25SBarry Smith 
12130de9b25SBarry Smith    Experienced users can set the error handler with PetscPushErrorHandler().
12230de9b25SBarry Smith 
12330de9b25SBarry Smith    Concepts: error^setting condition
12430de9b25SBarry Smith 
12591d3bdf4SKris Buschelman .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), CHKERRQ(), CHKMEMQ, SETERRQ(), SETERRQ2(), SETERRQ3()
12630de9b25SBarry Smith M*/
1273af045c5SBarry Smith #define SETERRQ1(comm,ierr,s,a1) return PetscError(comm,__LINE__,PETSC_FUNCTION_NAME,__FILE__,ierr,PETSC_ERROR_INITIAL,s,a1)
12830de9b25SBarry Smith 
12930de9b25SBarry Smith /*MC
13030de9b25SBarry Smith    SETERRQ2 - Macro that is called when an error has been detected,
13130de9b25SBarry Smith 
13230de9b25SBarry Smith    Synopsis:
133aaa7dc30SBarry Smith    #include <petscsys.h>
1343af045c5SBarry Smith    PetscErrorCode SETERRQ2(MPI_Comm comm,PetscErrorCode ierr,char *formatmessage,arg1,arg2)
13530de9b25SBarry Smith 
1363af045c5SBarry Smith    Collective on MPI_Comm
13730de9b25SBarry Smith 
13830de9b25SBarry Smith    Input Parameters:
139fa190f98SMatthew G. Knepley +  comm - A communicator, so that the error can be collective
1403af045c5SBarry Smith .  ierr - nonzero error code, see the list of standard error codes in include/petscerror.h
14130de9b25SBarry Smith .  message - error message in the printf format
14230de9b25SBarry Smith .  arg1 - argument (for example an integer, string or double)
14330de9b25SBarry Smith -  arg2 - argument (for example an integer, string or double)
14430de9b25SBarry Smith 
14530de9b25SBarry Smith   Level: beginner
14630de9b25SBarry Smith 
14730de9b25SBarry Smith    Notes:
14830de9b25SBarry Smith     Once the error handler is called the calling function is then returned from with the given error code.
14930de9b25SBarry Smith 
15030de9b25SBarry Smith    Experienced users can set the error handler with PetscPushErrorHandler().
15130de9b25SBarry Smith 
15230de9b25SBarry Smith    Concepts: error^setting condition
15330de9b25SBarry Smith 
1546024bd2cSBarry Smith .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), CHKERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ3()
15530de9b25SBarry Smith M*/
1563af045c5SBarry Smith #define SETERRQ2(comm,ierr,s,a1,a2) return PetscError(comm,__LINE__,PETSC_FUNCTION_NAME,__FILE__,ierr,PETSC_ERROR_INITIAL,s,a1,a2)
15730de9b25SBarry Smith 
15830de9b25SBarry Smith /*MC
15930de9b25SBarry Smith    SETERRQ3 - Macro that is called when an error has been detected,
16030de9b25SBarry Smith 
16130de9b25SBarry Smith    Synopsis:
162aaa7dc30SBarry Smith    #include <petscsys.h>
1633af045c5SBarry Smith    PetscErrorCode SETERRQ3(MPI_Comm comm,PetscErrorCode ierr,char *formatmessage,arg1,arg2,arg3)
16430de9b25SBarry Smith 
1653af045c5SBarry Smith    Collective on MPI_Comm
16630de9b25SBarry Smith 
16730de9b25SBarry Smith    Input Parameters:
168fa190f98SMatthew G. Knepley +  comm - A communicator, so that the error can be collective
1693af045c5SBarry Smith .  ierr - nonzero error code, see the list of standard error codes in include/petscerror.h
17030de9b25SBarry Smith .  message - error message in the printf format
17130de9b25SBarry Smith .  arg1 - argument (for example an integer, string or double)
17230de9b25SBarry Smith .  arg2 - argument (for example an integer, string or double)
17330de9b25SBarry Smith -  arg3 - argument (for example an integer, string or double)
17430de9b25SBarry Smith 
17530de9b25SBarry Smith   Level: beginner
17630de9b25SBarry Smith 
17730de9b25SBarry Smith    Notes:
17830de9b25SBarry Smith     Once the error handler is called the calling function is then returned from with the given error code.
17930de9b25SBarry Smith 
180f621e05eSBarry Smith     There are also versions for 4, 5, 6 and 7 arguments.
181f621e05eSBarry Smith 
18230de9b25SBarry Smith    Experienced users can set the error handler with PetscPushErrorHandler().
18330de9b25SBarry Smith 
18430de9b25SBarry Smith    Concepts: error^setting condition
18530de9b25SBarry Smith 
1866024bd2cSBarry Smith .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), CHKERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2()
18730de9b25SBarry Smith M*/
1883af045c5SBarry 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)
18930de9b25SBarry Smith 
190fa190f98SMatthew G. Knepley /*MC
191fa190f98SMatthew G. Knepley    SETERRQ4 - Macro that is called when an error has been detected,
192fa190f98SMatthew G. Knepley 
193fa190f98SMatthew G. Knepley    Synopsis:
194fa190f98SMatthew G. Knepley    #include <petscsys.h>
1953af045c5SBarry Smith    PetscErrorCode SETERRQ4(MPI_Comm comm,PetscErrorCode ierr,char *formatmessage,arg1,arg2,arg3)
196fa190f98SMatthew G. Knepley 
1973af045c5SBarry Smith    Collective on MPI_Comm
198fa190f98SMatthew G. Knepley 
199fa190f98SMatthew G. Knepley    Input Parameters:
200fa190f98SMatthew G. Knepley +  comm - A communicator, so that the error can be collective
2013af045c5SBarry Smith .  ierr - nonzero error code, see the list of standard error codes in include/petscerror.h
202fa190f98SMatthew G. Knepley .  message - error message in the printf format
203fa190f98SMatthew G. Knepley .  arg1 - argument (for example an integer, string or double)
204fa190f98SMatthew G. Knepley .  arg2 - argument (for example an integer, string or double)
205fa190f98SMatthew G. Knepley .  arg3 - argument (for example an integer, string or double)
206fa190f98SMatthew G. Knepley -  arg4 - argument (for example an integer, string or double)
207fa190f98SMatthew G. Knepley 
208fa190f98SMatthew G. Knepley   Level: beginner
209fa190f98SMatthew G. Knepley 
210fa190f98SMatthew G. Knepley    Notes:
211fa190f98SMatthew G. Knepley     Once the error handler is called the calling function is then returned from with the given error code.
212fa190f98SMatthew G. Knepley 
213fa190f98SMatthew G. Knepley     There are also versions for 4, 5, 6 and 7 arguments.
214fa190f98SMatthew G. Knepley 
215fa190f98SMatthew G. Knepley    Experienced users can set the error handler with PetscPushErrorHandler().
216fa190f98SMatthew G. Knepley 
217fa190f98SMatthew G. Knepley    Concepts: error^setting condition
218fa190f98SMatthew G. Knepley 
219fa190f98SMatthew G. Knepley .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), CHKERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2()
220fa190f98SMatthew G. Knepley M*/
2213af045c5SBarry 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)
222fa190f98SMatthew G. Knepley 
223fa190f98SMatthew G. Knepley /*MC
224fa190f98SMatthew G. Knepley    SETERRQ5 - Macro that is called when an error has been detected,
225fa190f98SMatthew G. Knepley 
226fa190f98SMatthew G. Knepley    Synopsis:
227fa190f98SMatthew G. Knepley    #include <petscsys.h>
2283af045c5SBarry Smith    PetscErrorCode SETERRQ5(MPI_Comm comm,PetscErrorCode ierr,char *formatmessage,arg1,arg2,arg3)
229fa190f98SMatthew G. Knepley 
2303af045c5SBarry Smith    Collective on MPI_COmm
231fa190f98SMatthew G. Knepley 
232fa190f98SMatthew G. Knepley    Input Parameters:
233fa190f98SMatthew G. Knepley +  comm - A communicator, so that the error can be collective
2343af045c5SBarry Smith .  ierr - nonzero error code, see the list of standard error codes in include/petscerror.h
235fa190f98SMatthew G. Knepley .  message - error message in the printf format
236fa190f98SMatthew G. Knepley .  arg1 - argument (for example an integer, string or double)
237fa190f98SMatthew G. Knepley .  arg2 - argument (for example an integer, string or double)
238fa190f98SMatthew G. Knepley .  arg3 - argument (for example an integer, string or double)
239fa190f98SMatthew G. Knepley .  arg4 - argument (for example an integer, string or double)
240fa190f98SMatthew G. Knepley -  arg5 - argument (for example an integer, string or double)
241fa190f98SMatthew G. Knepley 
242fa190f98SMatthew G. Knepley   Level: beginner
243fa190f98SMatthew G. Knepley 
244fa190f98SMatthew G. Knepley    Notes:
245fa190f98SMatthew G. Knepley     Once the error handler is called the calling function is then returned from with the given error code.
246fa190f98SMatthew G. Knepley 
247fa190f98SMatthew G. Knepley     There are also versions for 4, 5, 6 and 7 arguments.
248fa190f98SMatthew G. Knepley 
249fa190f98SMatthew G. Knepley    Experienced users can set the error handler with PetscPushErrorHandler().
250fa190f98SMatthew G. Knepley 
251fa190f98SMatthew G. Knepley    Concepts: error^setting condition
252fa190f98SMatthew G. Knepley 
253fa190f98SMatthew G. Knepley .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), CHKERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2()
254fa190f98SMatthew G. Knepley M*/
2553af045c5SBarry 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)
256fa190f98SMatthew G. Knepley 
257fa190f98SMatthew G. Knepley /*MC
258fa190f98SMatthew G. Knepley    SETERRQ6 - Macro that is called when an error has been detected,
259fa190f98SMatthew G. Knepley 
260fa190f98SMatthew G. Knepley    Synopsis:
261fa190f98SMatthew G. Knepley    #include <petscsys.h>
2623af045c5SBarry Smith    PetscErrorCode SETERRQ6(MPI_Comm comm,PetscErrorCode ierr,char *formatmessage,arg1,arg2,arg3)
263fa190f98SMatthew G. Knepley 
2643af045c5SBarry Smith    Collective on MPI_Comm
265fa190f98SMatthew G. Knepley 
266fa190f98SMatthew G. Knepley    Input Parameters:
267fa190f98SMatthew G. Knepley +  comm - A communicator, so that the error can be collective
2683af045c5SBarry Smith .  ierr - nonzero error code, see the list of standard error codes in include/petscerror.h
269fa190f98SMatthew G. Knepley .  message - error message in the printf format
270fa190f98SMatthew G. Knepley .  arg1 - argument (for example an integer, string or double)
271fa190f98SMatthew G. Knepley .  arg2 - argument (for example an integer, string or double)
272fa190f98SMatthew G. Knepley .  arg3 - argument (for example an integer, string or double)
273fa190f98SMatthew G. Knepley .  arg4 - argument (for example an integer, string or double)
274fa190f98SMatthew G. Knepley .  arg5 - argument (for example an integer, string or double)
275fa190f98SMatthew G. Knepley -  arg6 - argument (for example an integer, string or double)
276fa190f98SMatthew G. Knepley 
277fa190f98SMatthew G. Knepley   Level: beginner
278fa190f98SMatthew G. Knepley 
279fa190f98SMatthew G. Knepley    Notes:
280fa190f98SMatthew G. Knepley     Once the error handler is called the calling function is then returned from with the given error code.
281fa190f98SMatthew G. Knepley 
282fa190f98SMatthew G. Knepley     There are also versions for 4, 5, 6 and 7 arguments.
283fa190f98SMatthew G. Knepley 
284fa190f98SMatthew G. Knepley    Experienced users can set the error handler with PetscPushErrorHandler().
285fa190f98SMatthew G. Knepley 
286fa190f98SMatthew G. Knepley    Concepts: error^setting condition
287fa190f98SMatthew G. Knepley 
288fa190f98SMatthew G. Knepley .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), CHKERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2()
289fa190f98SMatthew G. Knepley M*/
2903af045c5SBarry 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)
291fa190f98SMatthew G. Knepley 
292fa190f98SMatthew G. Knepley /*MC
293fa190f98SMatthew G. Knepley    SETERRQ7 - Macro that is called when an error has been detected,
294fa190f98SMatthew G. Knepley 
295fa190f98SMatthew G. Knepley    Synopsis:
296fa190f98SMatthew G. Knepley    #include <petscsys.h>
2973af045c5SBarry Smith    PetscErrorCode SETERRQ7(MPI_Comm comm,PetscErrorCode ierr,char *formatmessage,arg1,arg2,arg3)
298fa190f98SMatthew G. Knepley 
2993af045c5SBarry Smith    Collective on MPI_Comm
300fa190f98SMatthew G. Knepley 
301fa190f98SMatthew G. Knepley    Input Parameters:
302fa190f98SMatthew G. Knepley +  comm - A communicator, so that the error can be collective
3033af045c5SBarry Smith .  ierr - nonzero error code, see the list of standard error codes in include/petscerror.h
304fa190f98SMatthew G. Knepley .  message - error message in the printf format
305fa190f98SMatthew G. Knepley .  arg1 - argument (for example an integer, string or double)
306fa190f98SMatthew G. Knepley .  arg2 - argument (for example an integer, string or double)
307fa190f98SMatthew G. Knepley .  arg3 - argument (for example an integer, string or double)
308fa190f98SMatthew G. Knepley .  arg4 - argument (for example an integer, string or double)
309fa190f98SMatthew G. Knepley .  arg5 - argument (for example an integer, string or double)
310fa190f98SMatthew G. Knepley .  arg6 - argument (for example an integer, string or double)
311fa190f98SMatthew G. Knepley -  arg7 - argument (for example an integer, string or double)
312fa190f98SMatthew G. Knepley 
313fa190f98SMatthew G. Knepley   Level: beginner
314fa190f98SMatthew G. Knepley 
315fa190f98SMatthew G. Knepley    Notes:
316fa190f98SMatthew G. Knepley     Once the error handler is called the calling function is then returned from with the given error code.
317fa190f98SMatthew G. Knepley 
318fa190f98SMatthew G. Knepley     There are also versions for 4, 5, 6 and 7 arguments.
319fa190f98SMatthew G. Knepley 
320fa190f98SMatthew G. Knepley    Experienced users can set the error handler with PetscPushErrorHandler().
321fa190f98SMatthew G. Knepley 
322fa190f98SMatthew G. Knepley    Concepts: error^setting condition
323fa190f98SMatthew G. Knepley 
324fa190f98SMatthew G. Knepley .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), CHKERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2()
325fa190f98SMatthew G. Knepley M*/
3263af045c5SBarry 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)
327fa190f98SMatthew G. Knepley 
328fa190f98SMatthew G. Knepley /*MC
329fa190f98SMatthew G. Knepley    SETERRQ8 - Macro that is called when an error has been detected,
330fa190f98SMatthew G. Knepley 
331fa190f98SMatthew G. Knepley    Synopsis:
332fa190f98SMatthew G. Knepley    #include <petscsys.h>
3333af045c5SBarry Smith    PetscErrorCode SETERRQ8(MPI_Comm comm,PetscErrorCode ierr,char *formatmessage,arg1,arg2,arg3)
334fa190f98SMatthew G. Knepley 
3353af045c5SBarry Smith    Collective on MPI_Comm
336fa190f98SMatthew G. Knepley 
337fa190f98SMatthew G. Knepley    Input Parameters:
338fa190f98SMatthew G. Knepley +  comm - A communicator, so that the error can be collective
3393af045c5SBarry Smith .  ierr - nonzero error code, see the list of standard error codes in include/petscerror.h
340fa190f98SMatthew G. Knepley .  message - error message in the printf format
341fa190f98SMatthew G. Knepley .  arg1 - argument (for example an integer, string or double)
342fa190f98SMatthew G. Knepley .  arg2 - argument (for example an integer, string or double)
343fa190f98SMatthew G. Knepley .  arg3 - argument (for example an integer, string or double)
344fa190f98SMatthew G. Knepley .  arg4 - argument (for example an integer, string or double)
345fa190f98SMatthew G. Knepley .  arg5 - argument (for example an integer, string or double)
346fa190f98SMatthew G. Knepley .  arg6 - argument (for example an integer, string or double)
347fa190f98SMatthew G. Knepley .  arg7 - argument (for example an integer, string or double)
348fa190f98SMatthew G. Knepley -  arg8 - argument (for example an integer, string or double)
349fa190f98SMatthew G. Knepley 
350fa190f98SMatthew G. Knepley   Level: beginner
351fa190f98SMatthew G. Knepley 
352fa190f98SMatthew G. Knepley    Notes:
353fa190f98SMatthew G. Knepley     Once the error handler is called the calling function is then returned from with the given error code.
354fa190f98SMatthew G. Knepley 
355fa190f98SMatthew G. Knepley     There are also versions for 4, 5, 6 and 7 arguments.
356fa190f98SMatthew G. Knepley 
357fa190f98SMatthew G. Knepley    Experienced users can set the error handler with PetscPushErrorHandler().
358fa190f98SMatthew G. Knepley 
359fa190f98SMatthew G. Knepley    Concepts: error^setting condition
360fa190f98SMatthew G. Knepley 
361fa190f98SMatthew G. Knepley .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), CHKERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2()
362fa190f98SMatthew G. Knepley M*/
3633af045c5SBarry 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)
364fa190f98SMatthew G. Knepley 
365fa190f98SMatthew G. Knepley /*MC
366fa190f98SMatthew G. Knepley    SETERRABORT - Macro that can be called when an error has been detected,
367fa190f98SMatthew G. Knepley 
368fa190f98SMatthew G. Knepley    Synopsis:
369fa190f98SMatthew G. Knepley    #include <petscsys.h>
3703af045c5SBarry Smith    PetscErrorCode SETERRABORT(MPI_Comm comm,PetscErrorCode ierr,char *message)
371fa190f98SMatthew G. Knepley 
3723af045c5SBarry Smith    Collective on MPI_Comm
373fa190f98SMatthew G. Knepley 
374fa190f98SMatthew G. Knepley    Input Parameters:
375fa190f98SMatthew G. Knepley +  comm - A communicator, so that the error can be collective
3763af045c5SBarry Smith .  ierr - nonzero error code, see the list of standard error codes in include/petscerror.h
377fa190f98SMatthew G. Knepley -  message - error message in the printf format
378fa190f98SMatthew G. Knepley 
379fa190f98SMatthew G. Knepley   Level: beginner
380fa190f98SMatthew G. Knepley 
381fa190f98SMatthew G. Knepley    Notes:
382fa190f98SMatthew G. Knepley     This function just calls MPI_Abort().
383fa190f98SMatthew G. Knepley 
384fa190f98SMatthew G. Knepley    Concepts: error^setting condition
385fa190f98SMatthew G. Knepley 
386fa190f98SMatthew G. Knepley .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), CHKERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2()
387fa190f98SMatthew G. Knepley M*/
3883af045c5SBarry 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)
3899a00fa46SSatish Balay 
39030de9b25SBarry Smith /*MC
39130de9b25SBarry Smith    CHKERRQ - Checks error code, if non-zero it calls the error handler and then returns
39230de9b25SBarry Smith 
39330de9b25SBarry Smith    Synopsis:
394aaa7dc30SBarry Smith    #include <petscsys.h>
3953af045c5SBarry Smith    PetscErrorCode CHKERRQ(PetscErrorCode ierr)
39630de9b25SBarry Smith 
397eca87e8dSBarry Smith    Not Collective
39830de9b25SBarry Smith 
39930de9b25SBarry Smith    Input Parameters:
4003af045c5SBarry Smith .  ierr - nonzero error code, see the list of standard error codes in include/petscerror.h
40130de9b25SBarry Smith 
40230de9b25SBarry Smith   Level: beginner
40330de9b25SBarry Smith 
40430de9b25SBarry Smith    Notes:
40530de9b25SBarry Smith     Once the error handler is called the calling function is then returned from with the given error code.
40630de9b25SBarry Smith 
40730de9b25SBarry Smith     Experienced users can set the error handler with PetscPushErrorHandler().
4085324ea47SKris Buschelman 
4093af045c5SBarry Smith     CHKERRQ(ierr) is fundamentally a macro replacement for
4103af045c5SBarry Smith          if (ierr) return(PetscError(...,ierr,...));
4115324ea47SKris Buschelman 
4125324ea47SKris Buschelman     Although typical usage resembles "void CHKERRQ(PetscErrorCode)" as described above, for certain uses it is
4135324ea47SKris Buschelman     highly inappropriate to use it in this manner as it invokes return(PetscErrorCode). In particular,
4145324ea47SKris Buschelman     it cannot be used in functions which return(void) or any other datatype.  In these types of functions,
41558ebbce7SBarry Smith     you can use CHKERRV() which returns without an error code (bad idea since the error is ignored or
4163af045c5SBarry Smith          if (ierr) {PetscError(....); return(YourReturnType);}
4170298fd71SBarry Smith     where you may pass back a NULL to indicate an error. You can also call CHKERRABORT(comm,n) to have
41858ebbce7SBarry Smith     MPI_Abort() returned immediately.
41958ebbce7SBarry Smith 
42058ebbce7SBarry Smith     In Fortran MPI_Abort() is always called
42130de9b25SBarry Smith 
42230de9b25SBarry Smith    Concepts: error^setting condition
42330de9b25SBarry Smith 
42491d3bdf4SKris Buschelman .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), SETERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2(), SETERRQ2()
42530de9b25SBarry Smith M*/
4263af045c5SBarry Smith #define CHKERRQ(ierr)          do {if (PetscUnlikely(ierr)) return PetscError(PETSC_COMM_SELF,__LINE__,PETSC_FUNCTION_NAME,__FILE__,ierr,PETSC_ERROR_REPEAT," ");} while (0)
427f01fac0dSBarry 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)
4283af045c5SBarry 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)
4293af045c5SBarry Smith #define CHKERRCONTINUE(ierr)   do {if (PetscUnlikely(ierr)) {PetscError(PETSC_COMM_SELF,__LINE__,PETSC_FUNCTION_NAME,__FILE__,ierr,PETSC_ERROR_REPEAT," ");}} while (0)
43012801b39SBarry 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)
43185614651SBarry Smith 
432fd705b32SMatthew Knepley #ifdef PETSC_CLANGUAGE_CXX
433fd705b32SMatthew Knepley 
434cc26af49SMatthew Knepley /*MC
435cc26af49SMatthew Knepley    CHKERRXX - Checks error code, if non-zero it calls the C++ error handler which throws an exception
436cc26af49SMatthew Knepley 
437cc26af49SMatthew Knepley    Synopsis:
438aaa7dc30SBarry Smith    #include <petscsys.h>
4393af045c5SBarry Smith    void CHKERRXX(PetscErrorCode ierr)
440cc26af49SMatthew Knepley 
441eca87e8dSBarry Smith    Not Collective
442cc26af49SMatthew Knepley 
443cc26af49SMatthew Knepley    Input Parameters:
4443af045c5SBarry Smith .  ierr - nonzero error code, see the list of standard error codes in include/petscerror.h
445cc26af49SMatthew Knepley 
446cc26af49SMatthew Knepley   Level: beginner
447cc26af49SMatthew Knepley 
448cc26af49SMatthew Knepley    Notes:
449cc26af49SMatthew Knepley     Once the error handler throws a ??? exception.
450cc26af49SMatthew Knepley 
451cc26af49SMatthew Knepley     You can use CHKERRV() which returns without an error code (bad idea since the error is ignored)
452cc26af49SMatthew Knepley     or CHKERRABORT(comm,n) to have MPI_Abort() returned immediately.
453cc26af49SMatthew Knepley 
454cc26af49SMatthew Knepley    Concepts: error^setting condition
455cc26af49SMatthew Knepley 
456cc26af49SMatthew Knepley .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), SETERRQ(), CHKERRQ(), CHKMEMQ
457cc26af49SMatthew Knepley M*/
4583af045c5SBarry 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)
459fd705b32SMatthew Knepley 
460fd705b32SMatthew Knepley #endif
461fd705b32SMatthew Knepley 
4625be1650bSAlejandro Lamas Daviña #define CHKERRCUDA(err)   do {if (PetscUnlikely(err)) SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_LIB,"CUDA error %d",err);} while(0)
4635be1650bSAlejandro Lamas Daviña #define CHKERRCUBLAS(err) do {if (PetscUnlikely(err)) SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_LIB,"CUBLAS error %d",err);} while(0)
46482f73ecaSAlejandro Lamas Daviña 
46530de9b25SBarry Smith /*MC
46630de9b25SBarry Smith    CHKMEMQ - Checks the memory for corruption, calls error handler if any is detected
46730de9b25SBarry Smith 
46830de9b25SBarry Smith    Synopsis:
469aaa7dc30SBarry Smith    #include <petscsys.h>
47091d3bdf4SKris Buschelman    CHKMEMQ;
47130de9b25SBarry Smith 
472eca87e8dSBarry Smith    Not Collective
473eca87e8dSBarry Smith 
47430de9b25SBarry Smith   Level: beginner
47530de9b25SBarry Smith 
47630de9b25SBarry Smith    Notes:
4771957e957SBarry Smith     We highly recommend using valgrind http://www.mcs.anl.gov/petsc/documentation/faq.html#valgrind for finding memory problems. This is useful
4781957e957SBarry Smith     on systems that do not have valgrind, but much much less useful.
4791957e957SBarry Smith 
480ff002950SBarry Smith     Must run with the option -malloc_debug to enable this option
48130de9b25SBarry Smith 
48230de9b25SBarry Smith     Once the error handler is called the calling function is then returned from with the given error code.
48330de9b25SBarry Smith 
48430de9b25SBarry Smith     By defaults prints location where memory that is corrupted was allocated.
48530de9b25SBarry Smith 
486f621e05eSBarry Smith     Use CHKMEMA for functions that return void
487f621e05eSBarry Smith 
48830de9b25SBarry Smith    Concepts: memory corruption
48930de9b25SBarry Smith 
4906024bd2cSBarry Smith .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), SETERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2(), SETERRQ3(),
491ff002950SBarry Smith           PetscMallocValidate()
49230de9b25SBarry Smith M*/
493efca3c55SSatish Balay #define CHKMEMQ do {PetscErrorCode _7_ierr = PetscMallocValidate(__LINE__,PETSC_FUNCTION_NAME,__FILE__);CHKERRQ(_7_ierr);} while(0)
49485614651SBarry Smith 
495efca3c55SSatish Balay #define CHKMEMA PetscMallocValidate(__LINE__,PETSC_FUNCTION_NAME,__FILE__)
496e68848bdSBarry Smith 
497f8e50935SSatish Balay #else /* PETSC_USE_ERRORCHECKING */
498f621e05eSBarry Smith 
499f621e05eSBarry Smith /*
500e2e64c6bSBarry Smith     These are defined to be empty for when error checking is turned off, with ./configure --with-errorchecking=0
501f621e05eSBarry Smith */
502f621e05eSBarry Smith 
5033af045c5SBarry Smith #define SETERRQ(c,ierr,s)
504*61d598d6SSatish Balay #define SETERRMPI(comm,ierr,s)
5053af045c5SBarry Smith #define SETERRQ1(c,ierr,s,a1)
5063af045c5SBarry Smith #define SETERRQ2(c,ierr,s,a1,a2)
5073af045c5SBarry Smith #define SETERRQ3(c,ierr,s,a1,a2,a3)
5083af045c5SBarry Smith #define SETERRQ4(c,ierr,s,a1,a2,a3,a4)
5093af045c5SBarry Smith #define SETERRQ5(c,ierr,s,a1,a2,a3,a4,a5)
5103af045c5SBarry Smith #define SETERRQ6(c,ierr,s,a1,a2,a3,a4,a5,a6)
5113af045c5SBarry Smith #define SETERRQ7(c,ierr,s,a1,a2,a3,a4,a5,a6,a7)
5123af045c5SBarry Smith #define SETERRQ8(c,ierr,s,a1,a2,a3,a4,a5,a6,a7,a8)
5133af045c5SBarry Smith #define SETERRABORT(comm,ierr,s)
51485614651SBarry Smith 
5153af045c5SBarry Smith #define CHKERRQ(ierr)     ;
5163af045c5SBarry Smith #define CHKERRV(ierr)     ;
5171ee4faa0SMatthew Knepley #define CHKERRABORT(comm,n) ;
5183af045c5SBarry Smith #define CHKERRCONTINUE(ierr) ;
519*61d598d6SSatish Balay #define CHKERRMPI(ierr) ;
52085614651SBarry Smith #define CHKMEMQ        ;
52182f73ecaSAlejandro Lamas Daviña #define CHKERRCUDA(err) ;
52282f73ecaSAlejandro Lamas Daviña #define CHKERRCUBLAS(err) ;
52385614651SBarry Smith 
5248cabf42eSMatthew G Knepley #ifdef PETSC_CLANGUAGE_CXX
5253af045c5SBarry Smith #define CHKERRXX(ierr) ;
5268cabf42eSMatthew G Knepley #endif
5278cabf42eSMatthew G Knepley 
528f8e50935SSatish Balay #endif /* PETSC_USE_ERRORCHECKING */
52954a8ef01SBarry Smith 
530668f157eSBarry Smith /*E
531668f157eSBarry Smith   PetscErrorType - passed to the PETSc error handling routines indicating if this is the first or a later call to the error handlers
532668f157eSBarry Smith 
533668f157eSBarry Smith   Level: advanced
534668f157eSBarry Smith 
535d736bfebSBarry Smith   PETSC_ERROR_IN_CXX indicates the error was detected in C++ and an exception should be generated
536d736bfebSBarry Smith 
53761b0d812SBarry Smith   Developer Notes: This is currently used to decide when to print the detailed information about the run in PetscTraceBackErrorHandler()
538668f157eSBarry Smith 
539d736bfebSBarry Smith .seealso: PetscError(), SETERRXX()
540668f157eSBarry Smith E*/
541d736bfebSBarry Smith typedef enum {PETSC_ERROR_INITIAL=0,PETSC_ERROR_REPEAT=1,PETSC_ERROR_IN_CXX = 2} PetscErrorType;
5424b209cf6SBarry Smith 
543eb9e708aSLisandro Dalcin #if defined(__clang_analyzer__)
544eb9e708aSLisandro Dalcin __attribute__((analyzer_noreturn))
545eb9e708aSLisandro Dalcin #endif
546eb9e708aSLisandro Dalcin PETSC_EXTERN PetscErrorCode PetscError(MPI_Comm,int,const char*,const char*,PetscErrorCode,PetscErrorType,const char*,...);
547eb9e708aSLisandro Dalcin 
548014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscErrorPrintfInitialize(void);
549014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscErrorMessage(int,const char*[],char **);
550efca3c55SSatish Balay PETSC_EXTERN PetscErrorCode PetscTraceBackErrorHandler(MPI_Comm,int,const char*,const char*,PetscErrorCode,PetscErrorType,const char*,void*);
551efca3c55SSatish Balay PETSC_EXTERN PetscErrorCode PetscIgnoreErrorHandler(MPI_Comm,int,const char*,const char*,PetscErrorCode,PetscErrorType,const char*,void*);
552efca3c55SSatish Balay PETSC_EXTERN PetscErrorCode PetscEmacsClientErrorHandler(MPI_Comm,int,const char*,const char*,PetscErrorCode,PetscErrorType,const char*,void*);
553efca3c55SSatish Balay PETSC_EXTERN PetscErrorCode PetscMPIAbortErrorHandler(MPI_Comm,int,const char*,const char*,PetscErrorCode,PetscErrorType,const char*,void*);
554efca3c55SSatish Balay PETSC_EXTERN PetscErrorCode PetscAbortErrorHandler(MPI_Comm,int,const char*,const char*,PetscErrorCode,PetscErrorType,const char*,void*);
555efca3c55SSatish Balay PETSC_EXTERN PetscErrorCode PetscAttachDebuggerErrorHandler(MPI_Comm,int,const char*,const char*,PetscErrorCode,PetscErrorType,const char*,void*);
556efca3c55SSatish Balay PETSC_EXTERN PetscErrorCode PetscReturnErrorHandler(MPI_Comm,int,const char*,const char*,PetscErrorCode,PetscErrorType,const char*,void*);
557efca3c55SSatish Balay PETSC_EXTERN PetscErrorCode PetscPushErrorHandler(PetscErrorCode (*handler)(MPI_Comm,int,const char*,const char*,PetscErrorCode,PetscErrorType,const char*,void*),void*);
558014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscPopErrorHandler(void);
5598d359177SBarry Smith PETSC_EXTERN PetscErrorCode PetscSignalHandlerDefault(int,void*);
560014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscPushSignalHandler(PetscErrorCode (*)(int,void *),void*);
561014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscPopSignalHandler(void);
56228559dc8SJed Brown PETSC_EXTERN PetscErrorCode PetscCheckPointerSetIntensity(PetscInt);
563329f5518SBarry Smith 
564639ff905SBarry Smith /*MC
565639ff905SBarry Smith     PetscErrorPrintf - Prints error messages.
566639ff905SBarry Smith 
567639ff905SBarry Smith    Synopsis:
568aaa7dc30SBarry Smith     #include <petscsys.h>
569639ff905SBarry Smith      PetscErrorCode (*PetscErrorPrintf)(const char format[],...);
570639ff905SBarry Smith 
571639ff905SBarry Smith     Not Collective
572639ff905SBarry Smith 
573639ff905SBarry Smith     Input Parameters:
574639ff905SBarry Smith .   format - the usual printf() format string
575639ff905SBarry Smith 
576639ff905SBarry Smith    Options Database Keys:
5771957e957SBarry Smith +    -error_output_stdout - cause error messages to be printed to stdout instead of the  (default) stderr
578e1bc860dSBarry Smith -    -error_output_none - to turn off all printing of error messages (does not change the way the error is handled.)
579639ff905SBarry Smith 
580639ff905SBarry Smith    Notes: Use
581639ff905SBarry Smith $     PetscErrorPrintf = PetscErrorPrintfNone; to turn off all printing of error messages (does not change the way the
582639ff905SBarry Smith $                        error is handled.) and
5831957e957SBarry Smith $     PetscErrorPrintf = PetscErrorPrintfDefault; to turn it back on or you can use your own function
584639ff905SBarry Smith 
585639ff905SBarry Smith           Use
586639ff905SBarry Smith      PETSC_STDERR = FILE* obtained from a file open etc. to have stderr printed to the file.
587639ff905SBarry Smith      PETSC_STDOUT = FILE* obtained from a file open etc. to have stdout printed to the file.
588639ff905SBarry Smith 
589639ff905SBarry Smith           Use
590639ff905SBarry Smith       PetscPushErrorHandler() to provide your own error handler that determines what kind of messages to print
591639ff905SBarry Smith 
592639ff905SBarry Smith    Level: developer
593639ff905SBarry Smith 
594639ff905SBarry Smith     Fortran Note:
595639ff905SBarry Smith     This routine is not supported in Fortran.
596639ff905SBarry Smith 
597639ff905SBarry Smith     Concepts: error messages^printing
598639ff905SBarry Smith     Concepts: printing^error messages
599639ff905SBarry Smith 
600639ff905SBarry Smith .seealso: PetscFPrintf(), PetscSynchronizedPrintf(), PetscHelpPrintf(), PetscPrintf(), PetscErrorHandlerPush(), PetscVFPrintf(), PetscHelpPrintf()
601639ff905SBarry Smith M*/
602639ff905SBarry Smith PETSC_EXTERN PetscErrorCode (*PetscErrorPrintf)(const char[],...);
603639ff905SBarry Smith 
604329f5518SBarry Smith typedef enum {PETSC_FP_TRAP_OFF=0,PETSC_FP_TRAP_ON=1} PetscFPTrap;
605014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSetFPTrap(PetscFPTrap);
606014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscFPTrapPush(PetscFPTrap);
607014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscFPTrapPop(void);
60854a8ef01SBarry Smith 
6093a40ed3dSBarry Smith /*
6103a40ed3dSBarry Smith       Allows the code to build a stack frame as it runs
6113a40ed3dSBarry Smith */
6123a40ed3dSBarry Smith 
61399cd645aSJed Brown #define PETSCSTACKSIZE 64
614184914b5SBarry Smith 
6153a40ed3dSBarry Smith typedef struct  {
6160e33f6ddSBarry Smith   const char      *function[PETSCSTACKSIZE];
6170e33f6ddSBarry Smith   const char      *file[PETSCSTACKSIZE];
618184914b5SBarry Smith         int       line[PETSCSTACKSIZE];
619a8d2bbe5SBarry Smith         PetscBool petscroutine[PETSCSTACKSIZE];
620184914b5SBarry Smith         int       currentsize;
621a2f94806SJed Brown         int       hotdepth;
6223a40ed3dSBarry Smith } PetscStack;
6233a40ed3dSBarry Smith 
6241f46d60fSShri Abhyankar PETSC_EXTERN PetscStack *petscstack;
625184914b5SBarry Smith 
6266f5c2d7aSBarry Smith PetscErrorCode  PetscStackCopy(PetscStack*,PetscStack*);
6276f5c2d7aSBarry Smith PetscErrorCode  PetscStackPrint(PetscStack *,FILE*);
6285d12eec7SSatish Balay #if defined(PETSC_SERIALIZE_FUNCTIONS)
6295d12eec7SSatish Balay #include <petsc/private/petscfptimpl.h>
6305d12eec7SSatish Balay /*
6315d12eec7SSatish Balay    Registers the current function into the global function pointer to function name table
6325d12eec7SSatish Balay 
6335d12eec7SSatish Balay    Have to fix this to handle errors but cannot return error since used in PETSC_VIEWER_DRAW_() etc
6345d12eec7SSatish Balay */
6355d12eec7SSatish Balay #define PetscRegister__FUNCT__() do { \
6365d12eec7SSatish Balay   static PetscBool __chked = PETSC_FALSE; \
6375d12eec7SSatish Balay   if (!__chked) {\
6385d12eec7SSatish Balay   void *ptr; PetscDLSym(NULL,PETSC_FUNCTION_NAME,&ptr);\
6395d12eec7SSatish Balay   __chked = PETSC_TRUE;\
6405d12eec7SSatish Balay   }} while (0)
6415d12eec7SSatish Balay #else
6425d12eec7SSatish Balay #define PetscRegister__FUNCT__()
6435d12eec7SSatish Balay #endif
6445d12eec7SSatish Balay 
6452d7c6352SJed Brown #if defined(PETSC_USE_DEBUG)
646dbf62e16SBarry Smith PETSC_STATIC_INLINE PetscBool PetscStackActive(void)
647dbf62e16SBarry Smith {
6485c25fcd7SBarry Smith   return(petscstack ? PETSC_TRUE : PETSC_FALSE);
649dbf62e16SBarry Smith }
6503a40ed3dSBarry Smith 
651441dd030SJed Brown /* Stack handling is based on the following two "NoCheck" macros.  These should only be called directly by other error
652441dd030SJed Brown  * handling macros.  We record the line of the call, which may or may not be the location of the definition.  But is at
653441dd030SJed Brown  * least more useful than "unknown" because it can distinguish multiple calls from the same function.
654441dd030SJed Brown  */
655441dd030SJed Brown 
656a2f94806SJed Brown #define PetscStackPushNoCheck(funct,petsc_routine,hot)                        \
657441dd030SJed Brown   do {                                                                        \
658e04113cfSBarry Smith     PetscStackSAWsTakeAccess();                                                \
6595c25fcd7SBarry Smith     if (petscstack && (petscstack->currentsize < PETSCSTACKSIZE)) {         \
6605c25fcd7SBarry Smith       petscstack->function[petscstack->currentsize]  = funct;               \
6615c25fcd7SBarry Smith       petscstack->file[petscstack->currentsize]      = __FILE__;            \
6625c25fcd7SBarry Smith       petscstack->line[petscstack->currentsize]      = __LINE__;            \
6635c25fcd7SBarry Smith       petscstack->petscroutine[petscstack->currentsize] = petsc_routine;    \
6645c25fcd7SBarry Smith       petscstack->currentsize++;                                             \
665441dd030SJed Brown     }                                                                         \
6665c25fcd7SBarry Smith     if (petscstack) {                                                        \
6675c25fcd7SBarry Smith       petscstack->hotdepth += (hot || petscstack->hotdepth);                \
668a2f94806SJed Brown     }                                                                         \
669e04113cfSBarry Smith     PetscStackSAWsGrantAccess();                                               \
670441dd030SJed Brown   } while (0)
671441dd030SJed Brown 
672441dd030SJed Brown #define PetscStackPopNoCheck                                            \
6735c25fcd7SBarry Smith   do {                                                                  \
674e04113cfSBarry Smith     PetscStackSAWsTakeAccess();                                          \
6755c25fcd7SBarry Smith     if (petscstack && petscstack->currentsize > 0) {                  \
6765c25fcd7SBarry Smith       petscstack->currentsize--;                                       \
6775c25fcd7SBarry Smith       petscstack->function[petscstack->currentsize]  = 0;             \
6785c25fcd7SBarry Smith       petscstack->file[petscstack->currentsize]      = 0;             \
6795c25fcd7SBarry Smith       petscstack->line[petscstack->currentsize]      = 0;             \
6805c25fcd7SBarry Smith       petscstack->petscroutine[petscstack->currentsize] = PETSC_FALSE;\
681441dd030SJed Brown     }                                                                   \
6825c25fcd7SBarry Smith     if (petscstack) {                                                  \
6835c25fcd7SBarry Smith       petscstack->hotdepth = PetscMax(petscstack->hotdepth-1,0);      \
684a2f94806SJed Brown     }                                                                   \
685e04113cfSBarry Smith     PetscStackSAWsGrantAccess();                                         \
686441dd030SJed Brown   } while (0)
687441dd030SJed Brown 
68830de9b25SBarry Smith /*MC
6891957e957SBarry Smith    PetscFunctionBegin - First executable line of each PETSc function,  used for error handling. Final
6901957e957SBarry Smith       line of PETSc functions should be PetscFunctionReturn(0);
69130de9b25SBarry Smith 
69230de9b25SBarry Smith    Synopsis:
693aaa7dc30SBarry Smith    #include <petscsys.h>
69430de9b25SBarry Smith    void PetscFunctionBegin;
69530de9b25SBarry Smith 
696eca87e8dSBarry Smith    Not Collective
697eca87e8dSBarry Smith 
69830de9b25SBarry Smith    Usage:
69930de9b25SBarry Smith .vb
70030de9b25SBarry Smith      int something;
70130de9b25SBarry Smith 
70230de9b25SBarry Smith      PetscFunctionBegin;
70330de9b25SBarry Smith .ve
70430de9b25SBarry Smith 
70530de9b25SBarry Smith    Notes:
7061957e957SBarry Smith      Use PetscFunctionBeginUser for application codes.
7071957e957SBarry Smith 
70830de9b25SBarry Smith      Not available in Fortran
70930de9b25SBarry Smith 
71030de9b25SBarry Smith    Level: developer
71130de9b25SBarry Smith 
7121957e957SBarry Smith .seealso: PetscFunctionReturn(), PetscFunctionBeginHot(), PetscFunctionBeginUser()
71330de9b25SBarry Smith 
71430de9b25SBarry Smith .keywords: traceback, error handling
71530de9b25SBarry Smith M*/
716441dd030SJed Brown #define PetscFunctionBegin do {                                        \
717a2f94806SJed Brown     PetscStackPushNoCheck(PETSC_FUNCTION_NAME,PETSC_TRUE,PETSC_FALSE); \
718a2f94806SJed Brown     PetscRegister__FUNCT__();                                          \
719a2f94806SJed Brown   } while (0)
720a2f94806SJed Brown 
721a2f94806SJed Brown /*MC
722a2f94806SJed Brown    PetscFunctionBeginHot - Substitute for PetscFunctionBegin to be used in functions that are called in
723a2f94806SJed Brown    performance-critical circumstances.  Use of this function allows for lighter profiling by default.
724a2f94806SJed Brown 
725a2f94806SJed Brown    Synopsis:
726aaa7dc30SBarry Smith    #include <petscsys.h>
727a2f94806SJed Brown    void PetscFunctionBeginHot;
728a2f94806SJed Brown 
729a2f94806SJed Brown    Not Collective
730a2f94806SJed Brown 
731a2f94806SJed Brown    Usage:
732a2f94806SJed Brown .vb
733a2f94806SJed Brown      int something;
734a2f94806SJed Brown 
735a2f94806SJed Brown      PetscFunctionBeginHot;
736a2f94806SJed Brown .ve
737a2f94806SJed Brown 
738a2f94806SJed Brown    Notes:
739a2f94806SJed Brown      Not available in Fortran
740a2f94806SJed Brown 
741a2f94806SJed Brown    Level: developer
742a2f94806SJed Brown 
743a2f94806SJed Brown .seealso: PetscFunctionBegin, PetscFunctionReturn()
744a2f94806SJed Brown 
745a2f94806SJed Brown .keywords: traceback, error handling
746a2f94806SJed Brown M*/
747a2f94806SJed Brown #define PetscFunctionBeginHot do {                                     \
748a2f94806SJed Brown     PetscStackPushNoCheck(PETSC_FUNCTION_NAME,PETSC_TRUE,PETSC_TRUE);  \
7492d53ad75SBarry Smith     PetscRegister__FUNCT__();                                          \
75053c77d0aSJed Brown   } while (0)
75153c77d0aSJed Brown 
752a8d2bbe5SBarry Smith /*MC
753a8d2bbe5SBarry Smith    PetscFunctionBeginUser - First executable line of user provided PETSc routine
754a8d2bbe5SBarry Smith 
755a8d2bbe5SBarry Smith    Synopsis:
756aaa7dc30SBarry Smith    #include <petscsys.h>
757a8d2bbe5SBarry Smith    void PetscFunctionBeginUser;
758a8d2bbe5SBarry Smith 
759a8d2bbe5SBarry Smith    Not Collective
760a8d2bbe5SBarry Smith 
761a8d2bbe5SBarry Smith    Usage:
762a8d2bbe5SBarry Smith .vb
763a8d2bbe5SBarry Smith      int something;
764a8d2bbe5SBarry Smith 
765ac285190SBarry Smith      PetscFunctionBeginUser;
766a8d2bbe5SBarry Smith .ve
767a8d2bbe5SBarry Smith 
768a8d2bbe5SBarry Smith    Notes:
7691957e957SBarry Smith       Final line of PETSc functions should be PetscFunctionReturn(0) except for main().
7701957e957SBarry Smith 
771a8d2bbe5SBarry Smith       Not available in Fortran
772a8d2bbe5SBarry Smith 
773ac285190SBarry Smith       This is identical to PetscFunctionBegin except it labels the routine as a user
774ac285190SBarry Smith       routine instead of as a PETSc library routine.
775ac285190SBarry Smith 
776a2f94806SJed Brown    Level: intermediate
777a8d2bbe5SBarry Smith 
778a2f94806SJed Brown .seealso: PetscFunctionReturn(), PetscFunctionBegin, PetscFunctionBeginHot
779a8d2bbe5SBarry Smith 
780a8d2bbe5SBarry Smith .keywords: traceback, error handling
781a8d2bbe5SBarry Smith M*/
782a8d2bbe5SBarry Smith #define PetscFunctionBeginUser                                          \
783a8d2bbe5SBarry Smith   do {                                                                  \
784a2f94806SJed Brown     PetscStackPushNoCheck(PETSC_FUNCTION_NAME,PETSC_FALSE,PETSC_FALSE); \
785a8d2bbe5SBarry Smith     PetscRegister__FUNCT__();                                           \
786a8d2bbe5SBarry Smith   } while (0)
787a8d2bbe5SBarry Smith 
788a8d2bbe5SBarry Smith 
7895cd90555SBarry Smith #define PetscStackPush(n) \
79061d886c9SShri Abhyankar   do {                                                                  \
791a2f94806SJed Brown     PetscStackPushNoCheck(n,PETSC_FALSE,PETSC_FALSE);                   \
79215681b3cSBarry Smith     CHKMEMQ;                                                            \
79315681b3cSBarry Smith   } while (0)
7943a40ed3dSBarry Smith 
795d64ed03dSBarry Smith #define PetscStackPop                           \
796441dd030SJed Brown     do {                                        \
797441dd030SJed Brown       CHKMEMQ;                                  \
798441dd030SJed Brown       PetscStackPopNoCheck;                     \
79915681b3cSBarry Smith     } while (0)
800d64ed03dSBarry Smith 
80130de9b25SBarry Smith /*MC
80230de9b25SBarry Smith    PetscFunctionReturn - Last executable line of each PETSc function
80330de9b25SBarry Smith         used for error handling. Replaces return()
80430de9b25SBarry Smith 
80530de9b25SBarry Smith    Synopsis:
806aaa7dc30SBarry Smith    #include <petscsys.h>
80730de9b25SBarry Smith    void PetscFunctionReturn(0);
80830de9b25SBarry Smith 
809eca87e8dSBarry Smith    Not Collective
810eca87e8dSBarry Smith 
81130de9b25SBarry Smith    Usage:
81230de9b25SBarry Smith .vb
81330de9b25SBarry Smith     ....
81430de9b25SBarry Smith      PetscFunctionReturn(0);
81530de9b25SBarry Smith    }
81630de9b25SBarry Smith .ve
81730de9b25SBarry Smith 
81830de9b25SBarry Smith    Notes:
81930de9b25SBarry Smith      Not available in Fortran
82030de9b25SBarry Smith 
82130de9b25SBarry Smith    Level: developer
82230de9b25SBarry Smith 
82330de9b25SBarry Smith .seealso: PetscFunctionBegin()
82430de9b25SBarry Smith 
82530de9b25SBarry Smith .keywords: traceback, error handling
82630de9b25SBarry Smith M*/
8275cd90555SBarry Smith #define PetscFunctionReturn(a) \
8288246ba0dSJed Brown   do {                                                                \
829441dd030SJed Brown     PetscStackPopNoCheck;                                             \
8308246ba0dSJed Brown     return(a);} while (0)
831d64ed03dSBarry Smith 
832ff94ddecSSatish Balay #define PetscFunctionReturnVoid() \
8338246ba0dSJed Brown   do {                                                                \
834441dd030SJed Brown     PetscStackPopNoCheck;                                             \
8358246ba0dSJed Brown     return;} while (0)
83676386721SLisandro Dalcin 
8376d385327SIbrahima Ba #else
8386d385327SIbrahima Ba 
839c82b4e47SJed Brown PETSC_STATIC_INLINE PetscBool PetscStackActive(void) {return PETSC_FALSE;}
840a2f94806SJed Brown #define PetscStackPushNoCheck(funct,petsc_routine,hot) do {} while (0)
841441dd030SJed Brown #define PetscStackPopNoCheck                           do {} while (0)
8423a40ed3dSBarry Smith #define PetscFunctionBegin
8430bdf7c52SPeter Brune #define PetscFunctionBeginUser
844a2f94806SJed Brown #define PetscFunctionBeginHot
8453a40ed3dSBarry Smith #define PetscFunctionReturn(a)    return(a)
8465665465eSBarry Smith #define PetscFunctionReturnVoid() return
847812af9f3SBarry Smith #define PetscStackPop             CHKMEMQ
848812af9f3SBarry Smith #define PetscStackPush(f)         CHKMEMQ
8493a40ed3dSBarry Smith 
8503a40ed3dSBarry Smith #endif
8513a40ed3dSBarry Smith 
852eb6b5d47SBarry Smith /*
853eb6b5d47SBarry Smith     PetscStackCall - Calls an external library routine or user function after pushing the name of the routine on the stack.
854eb6b5d47SBarry Smith 
855eb6b5d47SBarry Smith    Input Parameters:
856eb6b5d47SBarry Smith +   name - string that gives the name of the function being called
857fd3f9acdSBarry Smith -   routine - actual call to the routine, including ierr = and CHKERRQ(ierr);
858fd3f9acdSBarry Smith 
859dbf62e16SBarry Smith    Note: Often one should use PetscStackCallStandard() instead. This routine is intended for external library routines that DO NOT return error codes
860eb6b5d47SBarry Smith 
861eb6b5d47SBarry 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.
862eb6b5d47SBarry Smith 
863fd3f9acdSBarry Smith 
864fd3f9acdSBarry Smith 
865eb6b5d47SBarry Smith */
86630ecc5abSKarl Rupp #define PetscStackCall(name,routine) do { PetscStackPush(name);routine;PetscStackPop; } while(0)
867eb6b5d47SBarry Smith 
868fd3f9acdSBarry Smith /*
869fd3f9acdSBarry Smith     PetscStackCallStandard - Calls an external library routine after pushing the name of the routine on the stack.
870fd3f9acdSBarry Smith 
871fd3f9acdSBarry Smith    Input Parameters:
872fd3f9acdSBarry Smith +   func-  name of the routine
873fd3f9acdSBarry Smith -   args - arguments to the routine surrounded by ()
874fd3f9acdSBarry Smith 
875dbf62e16SBarry Smith    Notes: This is intended for external package routines that return error codes. Use PetscStackCall() for those that do not.
876dbf62e16SBarry Smith 
877dbf62e16SBarry 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.
878fd3f9acdSBarry Smith 
879fd3f9acdSBarry Smith */
880fd3f9acdSBarry Smith #define PetscStackCallStandard(func,args) do {                        \
8817afcd97cSStefano Zampini     PetscStackPush(#func);ierr = func args;PetscStackPop; if (ierr) SETERRQ2(PETSC_COMM_SELF,PETSC_ERR_LIB,"Error in %s(): error code %d",#func,(int)ierr); \
882fd3f9acdSBarry Smith   } while (0)
883fd3f9acdSBarry Smith 
884014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscStackCreate(void);
885639ff905SBarry Smith PETSC_EXTERN PetscErrorCode PetscStackView(FILE*);
886014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscStackDestroy(void);
88706d1fe2cSBarry Smith 
88806d1fe2cSBarry Smith #endif
889