xref: /petsc/include/petscerror.h (revision 6d210af2382a00b1a02d711a6dcd0f5a4c620b01)
154a8ef01SBarry Smith /*
2f621e05eSBarry Smith     Contains all error handling interfaces for PETSc.
354a8ef01SBarry Smith */
426bd1501SBarry Smith #if !defined(PETSCERROR_H)
526bd1501SBarry Smith #define PETSCERROR_H
66c7e564aSBarry Smith 
754a8ef01SBarry Smith /*
8329ffe3dSLois Curfman McInnes      These are the generic error codes. These error codes are used
9e2d1d2b7SBarry Smith      many different places in the PETSc source code. The string versions are
100e5e90baSSatish Balay      at src/sys/error/err.c any changes here must also be made there
11e951c290SBarry Smith      These are also define in src/sys/f90-mod/petscerror.h any CHANGES here
120f9cf654SBarry Smith      must be also made there.
1345d48df9SBarry Smith 
1454a8ef01SBarry Smith */
152a6744ebSBarry Smith #define PETSC_ERR_MIN_VALUE        54   /* should always be one less then the smallest value */
162a6744ebSBarry Smith 
1745d48df9SBarry Smith #define PETSC_ERR_MEM              55   /* unable to allocate requested memory */
1847794344SBarry Smith #define PETSC_ERR_SUP              56   /* no support for requested operation */
19e2d1d2b7SBarry Smith #define PETSC_ERR_SUP_SYS          57   /* no support for requested operation on this computer system */
20e2d1d2b7SBarry Smith #define PETSC_ERR_ORDER            58   /* operation done in wrong order */
2145d48df9SBarry Smith #define PETSC_ERR_SIG              59   /* signal received */
22f1caa5a4SBarry Smith #define PETSC_ERR_FP               72   /* floating point exception */
23a8c6a408SBarry Smith #define PETSC_ERR_COR              74   /* corrupted PETSc object */
24a8c6a408SBarry Smith #define PETSC_ERR_LIB              76   /* error in library called by PETSc */
25329ffe3dSLois Curfman McInnes #define PETSC_ERR_PLIB             77   /* PETSc library generated inconsistent data */
26329ffe3dSLois Curfman McInnes #define PETSC_ERR_MEMC             78   /* memory corruption */
27b3cc6726SBarry Smith #define PETSC_ERR_CONV_FAILED      82   /* iterative method (KSP or SNES) failed */
281302d50aSBarry Smith #define PETSC_ERR_USER             83   /* user has not provided needed function */
294e2ffeddSBarry Smith #define PETSC_ERR_SYS              88   /* error in system call */
30a8b45ee7SBarry Smith #define PETSC_ERR_POINTER          70   /* pointer does not point to valid address */
313d96e996SBarry Smith #define PETSC_ERR_MPI_LIB_INCOMP   87   /* MPI library at runtime is not compatible with MPI user compiled with */
3245d48df9SBarry Smith 
3345d48df9SBarry Smith #define PETSC_ERR_ARG_SIZ          60   /* nonconforming object sizes used in operation */
3445d48df9SBarry Smith #define PETSC_ERR_ARG_IDN          61   /* two arguments not allowed to be the same */
35a8c6a408SBarry Smith #define PETSC_ERR_ARG_WRONG        62   /* wrong argument (but object probably ok) */
3645d48df9SBarry Smith #define PETSC_ERR_ARG_CORRUPT      64   /* null or corrupted PETSc object as argument */
3745d48df9SBarry Smith #define PETSC_ERR_ARG_OUTOFRANGE   63   /* input argument, out of range */
384f227f7cSBarry Smith #define PETSC_ERR_ARG_BADPTR       68   /* invalid pointer argument */
394f227f7cSBarry Smith #define PETSC_ERR_ARG_NOTSAMETYPE  69   /* two args must be same object type */
406831982aSBarry Smith #define PETSC_ERR_ARG_NOTSAMECOMM  80   /* two args must be same communicators */
41d252947aSBarry Smith #define PETSC_ERR_ARG_WRONGSTATE   73   /* object in argument is in wrong state, e.g. unassembled mat */
428cda6cd7SBarry Smith #define PETSC_ERR_ARG_TYPENOTSET   89   /* the type of the object has not yet been set */
43a8c6a408SBarry Smith #define PETSC_ERR_ARG_INCOMP       75   /* two arguments are incompatible */
444482741eSBarry Smith #define PETSC_ERR_ARG_NULL         85   /* argument is null that should not be */
45958c9bccSBarry Smith #define PETSC_ERR_ARG_UNKNOWN_TYPE 86   /* type name doesn't match any registered type */
464f227f7cSBarry Smith 
474f227f7cSBarry Smith #define PETSC_ERR_FILE_OPEN        65   /* unable to open file */
484f227f7cSBarry Smith #define PETSC_ERR_FILE_READ        66   /* unable to read from file */
494f227f7cSBarry Smith #define PETSC_ERR_FILE_WRITE       67   /* unable to write to file */
50a8c6a408SBarry Smith #define PETSC_ERR_FILE_UNEXPECTED  79   /* unexpected data in file */
5145d48df9SBarry Smith 
52329ffe3dSLois Curfman McInnes #define PETSC_ERR_MAT_LU_ZRPVT     71   /* detected a zero pivot during LU factorization */
539e3b2f23SBarry Smith #define PETSC_ERR_MAT_CH_ZRPVT     81   /* detected a zero pivot during Cholesky factorization */
5454a8ef01SBarry Smith 
5568e69593SBarry Smith #define PETSC_ERR_INT_OVERFLOW     84
563855c12bSBarry Smith 
57bf3909cdSBarry Smith #define PETSC_ERR_FLOP_COUNT       90
58e113a28aSBarry Smith #define PETSC_ERR_NOT_CONVERGED    91  /* solver did not converge */
5992e8f287SBarry Smith #define PETSC_ERR_MISSING_FACTOR   92  /* MatGetFactor() failed */
60691b26d3SBarry Smith #define PETSC_ERR_OPT_OVERWRITE    93  /* attempted to over write options which should not be changed */
61691b26d3SBarry Smith #define PETSC_ERR_WRONG_MPI_SIZE   94  /* example/application run with number of MPI ranks it does not support */
62691b26d3SBarry Smith #define PETSC_ERR_USER_INPUT       95  /* missing or incorrect user input */
63589f383fSBarry Smith #define PETSC_ERR_GPU_RESOURCE     96  /* unable to load a GPU resource, for example cuBLAS */
64589f383fSBarry Smith #define PETSC_ERR_GPU              97  /* An error from a GPU call, this may be due to lack of resources on the GPU or a true error in the call */
65ffc4695bSBarry Smith #define PETSC_ERR_MPI              98  /* general MPI error */
66ffc4695bSBarry Smith #define PETSC_ERR_MAX_VALUE        99  /* this is always the one more than the largest error code */
67b9eb5ee8SHong Zhang 
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 
913b1008b8SBarry Smith    Fortran Notes:
923b1008b8SBarry Smith       SETERRQ() may be called from Fortran subroutines but SETERRA() must be called from the
933b1008b8SBarry Smith       Fortran main program.
943b1008b8SBarry Smith 
95f388eb8bSPatrick Sanan .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), CHKERRQ(), CHKMEMQ, SETERRA(), SETERRQ1(), SETERRQ2(), SETERRQ3(), CHKERRMPI()
9630de9b25SBarry Smith M*/
973af045c5SBarry Smith #define SETERRQ(comm,ierr,s) return PetscError(comm,__LINE__,PETSC_FUNCTION_NAME,__FILE__,ierr,PETSC_ERROR_INITIAL,s)
98986eef2eSBarry Smith 
99ffc4695bSBarry Smith /*
100ffc4695bSBarry Smith     Returned from PETSc functions that are called from MPI, such as related to attributes
101ffc4695bSBarry Smith       Do not confuse PETSC_MPI_ERROR_CODE and PETSC_ERR_MPI, the first is registered with MPI and returned to MPI as
102888a1fb3SBarry Smith       an error code, the latter is a regular PETSc error code passed within PETSc code indicating an error was detected in an MPI call.
103ffc4695bSBarry Smith */
104ffc4695bSBarry Smith PETSC_EXTERN PetscMPIInt PETSC_MPI_ERROR_CLASS;
105ffc4695bSBarry Smith PETSC_EXTERN PetscMPIInt PETSC_MPI_ERROR_CODE;
106ffc4695bSBarry Smith 
107986eef2eSBarry Smith /*MC
108986eef2eSBarry Smith    SETERRMPI - Macro to be called when an error has been detected within an MPI callback function
109986eef2eSBarry Smith 
110986eef2eSBarry Smith    Synopsis:
111986eef2eSBarry Smith    #include <petscsys.h>
112986eef2eSBarry Smith    PetscErrorCode SETERRMPI(MPI_Comm comm,PetscErrorCode ierr,char *message)
113986eef2eSBarry Smith 
114d083f849SBarry Smith    Collective
115986eef2eSBarry Smith 
116986eef2eSBarry Smith    Input Parameters:
117986eef2eSBarry Smith +  comm - A communicator, use PETSC_COMM_SELF unless you know all ranks of another communicator will detect the error
118986eef2eSBarry Smith .  ierr - nonzero error code, see the list of standard error codes in include/petscerror.h
119986eef2eSBarry Smith -  message - error message
120986eef2eSBarry Smith 
121986eef2eSBarry Smith   Level: developer
122986eef2eSBarry Smith 
123986eef2eSBarry Smith    Notes:
124888a1fb3SBarry 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
125986eef2eSBarry Smith     which is registered with MPI_Add_error_code() when PETSc is initialized.
126986eef2eSBarry Smith 
127986eef2eSBarry Smith .seealso: SETERRQ(), CHKERRQ(), CHKERRMPI(), PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), CHKERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2(), SETERRQ3()
128986eef2eSBarry Smith M*/
12912801b39SBarry Smith #define SETERRMPI(comm,ierr,s) return (PetscError(comm,__LINE__,PETSC_FUNCTION_NAME,__FILE__,ierr,PETSC_ERROR_INITIAL,s),PETSC_MPI_ERROR_CODE)
13030de9b25SBarry Smith 
13130de9b25SBarry Smith /*MC
13230de9b25SBarry Smith    SETERRQ1 - Macro that is called when an error has been detected,
13330de9b25SBarry Smith 
13430de9b25SBarry Smith    Synopsis:
135aaa7dc30SBarry Smith    #include <petscsys.h>
1363af045c5SBarry Smith    PetscErrorCode SETERRQ1(MPI_Comm comm,PetscErrorCode ierr,char *formatmessage,arg)
13730de9b25SBarry Smith 
138d083f849SBarry Smith    Collective
13930de9b25SBarry Smith 
14030de9b25SBarry Smith    Input Parameters:
141fa190f98SMatthew G. Knepley +  comm - A communicator, so that the error can be collective
1423af045c5SBarry Smith .  ierr - nonzero error code, see the list of standard error codes in include/petscerror.h
14330de9b25SBarry Smith .  message - error message in the printf format
14430de9b25SBarry Smith -  arg - argument (for example an integer, string or double)
14530de9b25SBarry Smith 
14630de9b25SBarry Smith   Level: beginner
14730de9b25SBarry Smith 
14830de9b25SBarry Smith    Notes:
14930de9b25SBarry Smith     Once the error handler is called the calling function is then returned from with the given error code.
15030de9b25SBarry Smith 
15130de9b25SBarry Smith    Experienced users can set the error handler with PetscPushErrorHandler().
15230de9b25SBarry Smith 
15391d3bdf4SKris Buschelman .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), CHKERRQ(), CHKMEMQ, SETERRQ(), SETERRQ2(), SETERRQ3()
15430de9b25SBarry Smith M*/
1553af045c5SBarry Smith #define SETERRQ1(comm,ierr,s,a1) return PetscError(comm,__LINE__,PETSC_FUNCTION_NAME,__FILE__,ierr,PETSC_ERROR_INITIAL,s,a1)
15630de9b25SBarry Smith 
15730de9b25SBarry Smith /*MC
15830de9b25SBarry Smith    SETERRQ2 - Macro that is called when an error has been detected,
15930de9b25SBarry Smith 
16030de9b25SBarry Smith    Synopsis:
161aaa7dc30SBarry Smith    #include <petscsys.h>
1623af045c5SBarry Smith    PetscErrorCode SETERRQ2(MPI_Comm comm,PetscErrorCode ierr,char *formatmessage,arg1,arg2)
16330de9b25SBarry Smith 
164d083f849SBarry Smith    Collective
16530de9b25SBarry Smith 
16630de9b25SBarry Smith    Input Parameters:
167fa190f98SMatthew G. Knepley +  comm - A communicator, so that the error can be collective
1683af045c5SBarry Smith .  ierr - nonzero error code, see the list of standard error codes in include/petscerror.h
16930de9b25SBarry Smith .  message - error message in the printf format
17030de9b25SBarry Smith .  arg1 - argument (for example an integer, string or double)
17130de9b25SBarry Smith -  arg2 - argument (for example an integer, string or double)
17230de9b25SBarry Smith 
17330de9b25SBarry Smith   Level: beginner
17430de9b25SBarry Smith 
17530de9b25SBarry Smith    Notes:
17630de9b25SBarry Smith     Once the error handler is called the calling function is then returned from with the given error code.
17730de9b25SBarry Smith 
17830de9b25SBarry Smith    Experienced users can set the error handler with PetscPushErrorHandler().
17930de9b25SBarry Smith 
1806024bd2cSBarry Smith .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), CHKERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ3()
18130de9b25SBarry Smith M*/
1823af045c5SBarry Smith #define SETERRQ2(comm,ierr,s,a1,a2) return PetscError(comm,__LINE__,PETSC_FUNCTION_NAME,__FILE__,ierr,PETSC_ERROR_INITIAL,s,a1,a2)
18330de9b25SBarry Smith 
18430de9b25SBarry Smith /*MC
18530de9b25SBarry Smith    SETERRQ3 - Macro that is called when an error has been detected,
18630de9b25SBarry Smith 
18730de9b25SBarry Smith    Synopsis:
188aaa7dc30SBarry Smith    #include <petscsys.h>
1893af045c5SBarry Smith    PetscErrorCode SETERRQ3(MPI_Comm comm,PetscErrorCode ierr,char *formatmessage,arg1,arg2,arg3)
19030de9b25SBarry Smith 
191d083f849SBarry Smith    Collective
19230de9b25SBarry Smith 
19330de9b25SBarry Smith    Input Parameters:
194fa190f98SMatthew G. Knepley +  comm - A communicator, so that the error can be collective
1953af045c5SBarry Smith .  ierr - nonzero error code, see the list of standard error codes in include/petscerror.h
19630de9b25SBarry Smith .  message - error message in the printf format
19730de9b25SBarry Smith .  arg1 - argument (for example an integer, string or double)
19830de9b25SBarry Smith .  arg2 - argument (for example an integer, string or double)
19930de9b25SBarry Smith -  arg3 - argument (for example an integer, string or double)
20030de9b25SBarry Smith 
20130de9b25SBarry Smith   Level: beginner
20230de9b25SBarry Smith 
20330de9b25SBarry Smith    Notes:
20430de9b25SBarry Smith     Once the error handler is called the calling function is then returned from with the given error code.
20530de9b25SBarry Smith 
206f621e05eSBarry Smith     There are also versions for 4, 5, 6 and 7 arguments.
207f621e05eSBarry Smith 
20830de9b25SBarry Smith    Experienced users can set the error handler with PetscPushErrorHandler().
20930de9b25SBarry Smith 
2106024bd2cSBarry Smith .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), CHKERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2()
21130de9b25SBarry Smith M*/
2123af045c5SBarry 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)
21330de9b25SBarry Smith 
214fa190f98SMatthew G. Knepley /*MC
215fa190f98SMatthew G. Knepley    SETERRQ4 - Macro that is called when an error has been detected,
216fa190f98SMatthew G. Knepley 
217fa190f98SMatthew G. Knepley    Synopsis:
218fa190f98SMatthew G. Knepley    #include <petscsys.h>
21931e9e36bSSatish Balay    PetscErrorCode SETERRQ4(MPI_Comm comm,PetscErrorCode ierr,char *formatmessage,arg1,arg2,arg3,arg4)
220fa190f98SMatthew G. Knepley 
221d083f849SBarry Smith    Collective
222fa190f98SMatthew G. Knepley 
223fa190f98SMatthew G. Knepley    Input Parameters:
224fa190f98SMatthew G. Knepley +  comm - A communicator, so that the error can be collective
2253af045c5SBarry Smith .  ierr - nonzero error code, see the list of standard error codes in include/petscerror.h
226fa190f98SMatthew G. Knepley .  message - error message in the printf format
227fa190f98SMatthew G. Knepley .  arg1 - argument (for example an integer, string or double)
228fa190f98SMatthew G. Knepley .  arg2 - argument (for example an integer, string or double)
229fa190f98SMatthew G. Knepley .  arg3 - argument (for example an integer, string or double)
230fa190f98SMatthew G. Knepley -  arg4 - argument (for example an integer, string or double)
231fa190f98SMatthew G. Knepley 
232fa190f98SMatthew G. Knepley   Level: beginner
233fa190f98SMatthew G. Knepley 
234fa190f98SMatthew G. Knepley    Notes:
235fa190f98SMatthew G. Knepley     Once the error handler is called the calling function is then returned from with the given error code.
236fa190f98SMatthew G. Knepley 
237fa190f98SMatthew G. Knepley     There are also versions for 4, 5, 6 and 7 arguments.
238fa190f98SMatthew G. Knepley 
239fa190f98SMatthew G. Knepley    Experienced users can set the error handler with PetscPushErrorHandler().
240fa190f98SMatthew G. Knepley 
241fa190f98SMatthew G. Knepley .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), CHKERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2()
242fa190f98SMatthew G. Knepley M*/
2433af045c5SBarry 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)
244fa190f98SMatthew G. Knepley 
245fa190f98SMatthew G. Knepley /*MC
246fa190f98SMatthew G. Knepley    SETERRQ5 - Macro that is called when an error has been detected,
247fa190f98SMatthew G. Knepley 
248fa190f98SMatthew G. Knepley    Synopsis:
249fa190f98SMatthew G. Knepley    #include <petscsys.h>
25031e9e36bSSatish Balay    PetscErrorCode SETERRQ5(MPI_Comm comm,PetscErrorCode ierr,char *formatmessage,arg1,arg2,arg3,arg4,arg5)
251fa190f98SMatthew G. Knepley 
252d083f849SBarry Smith    Collective
253fa190f98SMatthew G. Knepley 
254fa190f98SMatthew G. Knepley    Input Parameters:
255fa190f98SMatthew G. Knepley +  comm - A communicator, so that the error can be collective
2563af045c5SBarry Smith .  ierr - nonzero error code, see the list of standard error codes in include/petscerror.h
257fa190f98SMatthew G. Knepley .  message - error message in the printf format
258fa190f98SMatthew G. Knepley .  arg1 - argument (for example an integer, string or double)
259fa190f98SMatthew G. Knepley .  arg2 - argument (for example an integer, string or double)
260fa190f98SMatthew G. Knepley .  arg3 - argument (for example an integer, string or double)
261fa190f98SMatthew G. Knepley .  arg4 - argument (for example an integer, string or double)
262fa190f98SMatthew G. Knepley -  arg5 - argument (for example an integer, string or double)
263fa190f98SMatthew G. Knepley 
264fa190f98SMatthew G. Knepley   Level: beginner
265fa190f98SMatthew G. Knepley 
266fa190f98SMatthew G. Knepley    Notes:
267fa190f98SMatthew G. Knepley     Once the error handler is called the calling function is then returned from with the given error code.
268fa190f98SMatthew G. Knepley 
269fa190f98SMatthew G. Knepley     There are also versions for 4, 5, 6 and 7 arguments.
270fa190f98SMatthew G. Knepley 
271fa190f98SMatthew G. Knepley    Experienced users can set the error handler with PetscPushErrorHandler().
272fa190f98SMatthew G. Knepley 
273fa190f98SMatthew G. Knepley .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), CHKERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2()
274fa190f98SMatthew G. Knepley M*/
2753af045c5SBarry 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)
276fa190f98SMatthew G. Knepley 
277fa190f98SMatthew G. Knepley /*MC
278fa190f98SMatthew G. Knepley    SETERRQ6 - Macro that is called when an error has been detected,
279fa190f98SMatthew G. Knepley 
280fa190f98SMatthew G. Knepley    Synopsis:
281fa190f98SMatthew G. Knepley    #include <petscsys.h>
28231e9e36bSSatish Balay    PetscErrorCode SETERRQ6(MPI_Comm comm,PetscErrorCode ierr,char *formatmessage,arg1,arg2,arg3,arg4,arg5,arg6)
283fa190f98SMatthew G. Knepley 
284d083f849SBarry Smith    Collective
285fa190f98SMatthew G. Knepley 
286fa190f98SMatthew G. Knepley    Input Parameters:
287fa190f98SMatthew G. Knepley +  comm - A communicator, so that the error can be collective
2883af045c5SBarry Smith .  ierr - nonzero error code, see the list of standard error codes in include/petscerror.h
289fa190f98SMatthew G. Knepley .  message - error message in the printf format
290fa190f98SMatthew G. Knepley .  arg1 - argument (for example an integer, string or double)
291fa190f98SMatthew G. Knepley .  arg2 - argument (for example an integer, string or double)
292fa190f98SMatthew G. Knepley .  arg3 - argument (for example an integer, string or double)
293fa190f98SMatthew G. Knepley .  arg4 - argument (for example an integer, string or double)
294fa190f98SMatthew G. Knepley .  arg5 - argument (for example an integer, string or double)
295fa190f98SMatthew G. Knepley -  arg6 - argument (for example an integer, string or double)
296fa190f98SMatthew G. Knepley 
297fa190f98SMatthew G. Knepley   Level: beginner
298fa190f98SMatthew G. Knepley 
299fa190f98SMatthew G. Knepley    Notes:
300fa190f98SMatthew G. Knepley     Once the error handler is called the calling function is then returned from with the given error code.
301fa190f98SMatthew G. Knepley 
302fa190f98SMatthew G. Knepley     There are also versions for 4, 5, 6 and 7 arguments.
303fa190f98SMatthew G. Knepley 
304fa190f98SMatthew G. Knepley    Experienced users can set the error handler with PetscPushErrorHandler().
305fa190f98SMatthew G. Knepley 
306fa190f98SMatthew G. Knepley .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), CHKERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2()
307fa190f98SMatthew G. Knepley M*/
3083af045c5SBarry 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)
309fa190f98SMatthew G. Knepley 
310fa190f98SMatthew G. Knepley /*MC
311fa190f98SMatthew G. Knepley    SETERRQ7 - Macro that is called when an error has been detected,
312fa190f98SMatthew G. Knepley 
313fa190f98SMatthew G. Knepley    Synopsis:
314fa190f98SMatthew G. Knepley    #include <petscsys.h>
31531e9e36bSSatish Balay    PetscErrorCode SETERRQ7(MPI_Comm comm,PetscErrorCode ierr,char *formatmessage,arg1,arg2,arg3,arg4,arg5,arg6,arg7)
316fa190f98SMatthew G. Knepley 
317d083f849SBarry Smith    Collective
318fa190f98SMatthew G. Knepley 
319fa190f98SMatthew G. Knepley    Input Parameters:
320fa190f98SMatthew G. Knepley +  comm - A communicator, so that the error can be collective
3213af045c5SBarry Smith .  ierr - nonzero error code, see the list of standard error codes in include/petscerror.h
322fa190f98SMatthew G. Knepley .  message - error message in the printf format
323fa190f98SMatthew G. Knepley .  arg1 - argument (for example an integer, string or double)
324fa190f98SMatthew G. Knepley .  arg2 - argument (for example an integer, string or double)
325fa190f98SMatthew G. Knepley .  arg3 - argument (for example an integer, string or double)
326fa190f98SMatthew G. Knepley .  arg4 - argument (for example an integer, string or double)
327fa190f98SMatthew G. Knepley .  arg5 - argument (for example an integer, string or double)
328fa190f98SMatthew G. Knepley .  arg6 - argument (for example an integer, string or double)
329fa190f98SMatthew G. Knepley -  arg7 - argument (for example an integer, string or double)
330fa190f98SMatthew G. Knepley 
331fa190f98SMatthew G. Knepley   Level: beginner
332fa190f98SMatthew G. Knepley 
333fa190f98SMatthew G. Knepley    Notes:
334fa190f98SMatthew G. Knepley     Once the error handler is called the calling function is then returned from with the given error code.
335fa190f98SMatthew G. Knepley 
336fa190f98SMatthew G. Knepley     There are also versions for 4, 5, 6 and 7 arguments.
337fa190f98SMatthew G. Knepley 
338fa190f98SMatthew G. Knepley    Experienced users can set the error handler with PetscPushErrorHandler().
339fa190f98SMatthew G. Knepley 
340fa190f98SMatthew G. Knepley .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), CHKERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2()
341fa190f98SMatthew G. Knepley M*/
3423af045c5SBarry 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)
343fa190f98SMatthew G. Knepley 
344fa190f98SMatthew G. Knepley /*MC
345fa190f98SMatthew G. Knepley    SETERRQ8 - Macro that is called when an error has been detected,
346fa190f98SMatthew G. Knepley 
347fa190f98SMatthew G. Knepley    Synopsis:
348fa190f98SMatthew G. Knepley    #include <petscsys.h>
34931e9e36bSSatish Balay    PetscErrorCode SETERRQ8(MPI_Comm comm,PetscErrorCode ierr,char *formatmessage,arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8)
350fa190f98SMatthew G. Knepley 
351d083f849SBarry Smith    Collective
352fa190f98SMatthew G. Knepley 
353fa190f98SMatthew G. Knepley    Input Parameters:
354fa190f98SMatthew G. Knepley +  comm - A communicator, so that the error can be collective
3553af045c5SBarry Smith .  ierr - nonzero error code, see the list of standard error codes in include/petscerror.h
356fa190f98SMatthew G. Knepley .  message - error message in the printf format
357fa190f98SMatthew G. Knepley .  arg1 - argument (for example an integer, string or double)
358fa190f98SMatthew G. Knepley .  arg2 - argument (for example an integer, string or double)
359fa190f98SMatthew G. Knepley .  arg3 - argument (for example an integer, string or double)
360fa190f98SMatthew G. Knepley .  arg4 - argument (for example an integer, string or double)
361fa190f98SMatthew G. Knepley .  arg5 - argument (for example an integer, string or double)
362fa190f98SMatthew G. Knepley .  arg6 - argument (for example an integer, string or double)
363fa190f98SMatthew G. Knepley .  arg7 - argument (for example an integer, string or double)
364fa190f98SMatthew G. Knepley -  arg8 - argument (for example an integer, string or double)
365fa190f98SMatthew G. Knepley 
366fa190f98SMatthew G. Knepley   Level: beginner
367fa190f98SMatthew G. Knepley 
368fa190f98SMatthew G. Knepley    Notes:
369fa190f98SMatthew G. Knepley     Once the error handler is called the calling function is then returned from with the given error code.
370fa190f98SMatthew G. Knepley 
371fa190f98SMatthew G. Knepley     There are also versions for 4, 5, 6 and 7 arguments.
372fa190f98SMatthew G. Knepley 
373fa190f98SMatthew G. Knepley    Experienced users can set the error handler with PetscPushErrorHandler().
374fa190f98SMatthew G. Knepley 
375fa190f98SMatthew G. Knepley .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), CHKERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2()
376fa190f98SMatthew G. Knepley M*/
3773af045c5SBarry 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)
378fa190f98SMatthew G. Knepley 
379fa190f98SMatthew G. Knepley /*MC
380ee8199e6SMatthew G. Knepley    SETERRQ9 - Macro that is called when an error has been detected,
381ee8199e6SMatthew G. Knepley 
382ee8199e6SMatthew G. Knepley    Synopsis:
383ee8199e6SMatthew G. Knepley    #include <petscsys.h>
38431e9e36bSSatish Balay    PetscErrorCode SETERRQ9(MPI_Comm comm,PetscErrorCode ierr,char *formatmessage,arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9)
385ee8199e6SMatthew G. Knepley 
386d083f849SBarry Smith    Collective
387ee8199e6SMatthew G. Knepley 
388ee8199e6SMatthew G. Knepley    Input Parameters:
389ee8199e6SMatthew G. Knepley +  comm - A communicator, so that the error can be collective
390ee8199e6SMatthew G. Knepley .  ierr - nonzero error code, see the list of standard error codes in include/petscerror.h
391ee8199e6SMatthew G. Knepley .  message - error message in the printf format
392ee8199e6SMatthew G. Knepley .  arg1 - argument (for example an integer, string or double)
393ee8199e6SMatthew G. Knepley .  arg2 - argument (for example an integer, string or double)
394ee8199e6SMatthew G. Knepley .  arg3 - argument (for example an integer, string or double)
395ee8199e6SMatthew G. Knepley .  arg4 - argument (for example an integer, string or double)
396ee8199e6SMatthew G. Knepley .  arg5 - argument (for example an integer, string or double)
397ee8199e6SMatthew G. Knepley .  arg6 - argument (for example an integer, string or double)
398ee8199e6SMatthew G. Knepley .  arg7 - argument (for example an integer, string or double)
399ee8199e6SMatthew G. Knepley .  arg8 - argument (for example an integer, string or double)
400ee8199e6SMatthew G. Knepley -  arg9 - argument (for example an integer, string or double)
401ee8199e6SMatthew G. Knepley 
402ee8199e6SMatthew G. Knepley   Level: beginner
403ee8199e6SMatthew G. Knepley 
404ee8199e6SMatthew G. Knepley    Notes:
405ee8199e6SMatthew G. Knepley     Once the error handler is called the calling function is then returned from with the given error code.
406ee8199e6SMatthew G. Knepley 
407ee8199e6SMatthew G. Knepley     There are also versions for 0 to 9 arguments.
408ee8199e6SMatthew G. Knepley 
409ee8199e6SMatthew G. Knepley    Experienced users can set the error handler with PetscPushErrorHandler().
410ee8199e6SMatthew G. Knepley 
411ee8199e6SMatthew G. Knepley .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), CHKERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2()
412ee8199e6SMatthew G. Knepley M*/
413ee8199e6SMatthew 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)
414ee8199e6SMatthew G. Knepley 
415ee8199e6SMatthew G. Knepley /*MC
416f388eb8bSPatrick Sanan    SETERRA - Fortran-only macro that can be called when an error has been detected from the main program
417f388eb8bSPatrick Sanan 
418f388eb8bSPatrick Sanan    Synopsis:
419f388eb8bSPatrick Sanan    #include <petscsys.h>
420f388eb8bSPatrick Sanan    PetscErrorCode SETERRA(MPI_Comm comm,PetscErrorCode ierr,char *message)
421f388eb8bSPatrick Sanan 
422f388eb8bSPatrick Sanan    Collective
423f388eb8bSPatrick Sanan 
424f388eb8bSPatrick Sanan    Input Parameters:
425f388eb8bSPatrick Sanan +  comm - A communicator, so that the error can be collective
426f388eb8bSPatrick Sanan .  ierr - nonzero error code, see the list of standard error codes in include/petscerror.h
427f388eb8bSPatrick Sanan -  message - error message in the printf format
428f388eb8bSPatrick Sanan 
429f388eb8bSPatrick Sanan   Level: beginner
430f388eb8bSPatrick Sanan 
431f388eb8bSPatrick Sanan    Notes:
432f388eb8bSPatrick Sanan     This should only be used with Fortran. With C/C++, use SETERRQ().
433f388eb8bSPatrick Sanan 
434f388eb8bSPatrick Sanan    Fortran Notes:
435f388eb8bSPatrick Sanan       SETERRQ() may be called from Fortran subroutines but SETERRA() must be called from the
436f388eb8bSPatrick Sanan       Fortran main program.
437f388eb8bSPatrick Sanan 
438f388eb8bSPatrick Sanan .seealso: SETERRQ(), SETERRABORT(), CHKERRQ(), CHKERRA(), CHKERRABORT()
439f388eb8bSPatrick Sanan M*/
440f388eb8bSPatrick Sanan 
441f388eb8bSPatrick Sanan /*MC
442fa190f98SMatthew G. Knepley    SETERRABORT - Macro that can be called when an error has been detected,
443fa190f98SMatthew G. Knepley 
444fa190f98SMatthew G. Knepley    Synopsis:
445fa190f98SMatthew G. Knepley    #include <petscsys.h>
4463af045c5SBarry Smith    PetscErrorCode SETERRABORT(MPI_Comm comm,PetscErrorCode ierr,char *message)
447fa190f98SMatthew G. Knepley 
448d083f849SBarry Smith    Collective
449fa190f98SMatthew G. Knepley 
450fa190f98SMatthew G. Knepley    Input Parameters:
451fa190f98SMatthew G. Knepley +  comm - A communicator, so that the error can be collective
4523af045c5SBarry Smith .  ierr - nonzero error code, see the list of standard error codes in include/petscerror.h
453fa190f98SMatthew G. Knepley -  message - error message in the printf format
454fa190f98SMatthew G. Knepley 
455fa190f98SMatthew G. Knepley   Level: beginner
456fa190f98SMatthew G. Knepley 
457fa190f98SMatthew G. Knepley    Notes:
458fa190f98SMatthew G. Knepley     This function just calls MPI_Abort().
459fa190f98SMatthew G. Knepley 
460fa190f98SMatthew G. Knepley .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), CHKERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2()
461fa190f98SMatthew G. Knepley M*/
4623af045c5SBarry 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)
4639a00fa46SSatish Balay 
46430de9b25SBarry Smith /*MC
465888a1fb3SBarry Smith    CHKERRQ - Checks error code returned from PETSc function, if non-zero it calls the error handler and then returns. Use CHKERRMPI() for checking errors from MPI calls
46630de9b25SBarry Smith 
46730de9b25SBarry Smith    Synopsis:
468aaa7dc30SBarry Smith    #include <petscsys.h>
4693af045c5SBarry Smith    PetscErrorCode CHKERRQ(PetscErrorCode ierr)
47030de9b25SBarry Smith 
471eca87e8dSBarry Smith    Not Collective
47230de9b25SBarry Smith 
47330de9b25SBarry Smith    Input Parameters:
4743af045c5SBarry Smith .  ierr - nonzero error code, see the list of standard error codes in include/petscerror.h
47530de9b25SBarry Smith 
47630de9b25SBarry Smith   Level: beginner
47730de9b25SBarry Smith 
47830de9b25SBarry Smith    Notes:
47930de9b25SBarry Smith     Once the error handler is called the calling function is then returned from with the given error code.
48030de9b25SBarry Smith 
48130de9b25SBarry Smith     Experienced users can set the error handler with PetscPushErrorHandler().
4825324ea47SKris Buschelman 
4833af045c5SBarry Smith     CHKERRQ(ierr) is fundamentally a macro replacement for
4843af045c5SBarry Smith          if (ierr) return(PetscError(...,ierr,...));
4855324ea47SKris Buschelman 
4865324ea47SKris Buschelman     Although typical usage resembles "void CHKERRQ(PetscErrorCode)" as described above, for certain uses it is
4875324ea47SKris Buschelman     highly inappropriate to use it in this manner as it invokes return(PetscErrorCode). In particular,
4885324ea47SKris Buschelman     it cannot be used in functions which return(void) or any other datatype.  In these types of functions,
48958ebbce7SBarry Smith     you can use CHKERRV() which returns without an error code (bad idea since the error is ignored or
4903af045c5SBarry Smith          if (ierr) {PetscError(....); return(YourReturnType);}
4910298fd71SBarry Smith     where you may pass back a NULL to indicate an error. You can also call CHKERRABORT(comm,n) to have
49258ebbce7SBarry Smith     MPI_Abort() returned immediately.
49358ebbce7SBarry Smith 
4947037b0edSPatrick Sanan    Fortran Notes:
4957037b0edSPatrick Sanan       CHKERRQ() may be called from Fortran subroutines but CHKERRA() must be called from the
4967037b0edSPatrick Sanan       Fortran main program.
4977037b0edSPatrick Sanan 
498f388eb8bSPatrick Sanan .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), SETERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2(), SETERRQ2(), CHKERRA()
49930de9b25SBarry Smith M*/
500064a246eSJacob Faibussowitsch #if !defined(PETSC_CLANG_STATIC_ANALYZER)
501ee74f559SJed Brown #define CHKERRQ(ierr)          do {PetscErrorCode ierr__ = (ierr); if (PetscUnlikely(ierr__)) return PetscError(PETSC_COMM_SELF,__LINE__,PETSC_FUNCTION_NAME,__FILE__,ierr__,PETSC_ERROR_REPEAT," ");} while (0)
5020219f5dfSJed Brown #define CHKERRV(ierr)          do {PetscErrorCode ierr__ = (ierr); if (PetscUnlikely(ierr__)) {PetscError(PETSC_COMM_SELF,__LINE__,PETSC_FUNCTION_NAME,__FILE__,ierr__,PETSC_ERROR_REPEAT," ");return;}} while (0)
503064a246eSJacob Faibussowitsch #else
504064a246eSJacob Faibussowitsch #define CHKERRQ(ierr)
505064a246eSJacob Faibussowitsch #define CHKERRV(ierr)
506064a246eSJacob Faibussowitsch #endif
507064a246eSJacob Faibussowitsch 
5087037b0edSPatrick Sanan /*MC
509f388eb8bSPatrick Sanan    CHKERRA - Fortran-only replacement for CHKERRQ in the main program, which aborts immediately
510f388eb8bSPatrick Sanan 
511f388eb8bSPatrick Sanan    Synopsis:
512f388eb8bSPatrick Sanan    #include <petscsys.h>
513f388eb8bSPatrick Sanan    PetscErrorCode CHKERRA(PetscErrorCode ierr)
514f388eb8bSPatrick Sanan 
515f388eb8bSPatrick Sanan    Not Collective
516f388eb8bSPatrick Sanan 
517f388eb8bSPatrick Sanan    Input Parameters:
518f388eb8bSPatrick Sanan .  ierr - nonzero error code, see the list of standard error codes in include/petscerror.h
519f388eb8bSPatrick Sanan 
520f388eb8bSPatrick Sanan   Level: beginner
521f388eb8bSPatrick Sanan 
522f388eb8bSPatrick Sanan    Notes:
523f388eb8bSPatrick Sanan       This should only be used with Fortran. With C/C++, use CHKERRQ() in normal usage,
524f388eb8bSPatrick Sanan       or CHKERRABORT() if wanting to abort immediately on error.
525f388eb8bSPatrick Sanan 
526f388eb8bSPatrick Sanan    Fortran Notes:
527f388eb8bSPatrick Sanan       CHKERRQ() may be called from Fortran subroutines but CHKERRA() must be called from the
528f388eb8bSPatrick Sanan       Fortran main program.
529f388eb8bSPatrick Sanan 
530f388eb8bSPatrick Sanan .seealso: CHKERRQ(), CHKERRABORT(), SETERRA(), SETERRQ(), SETERRABORT()
531f388eb8bSPatrick Sanan M*/
532f388eb8bSPatrick Sanan 
533f388eb8bSPatrick Sanan /*MC
5347037b0edSPatrick Sanan    CHKERRABORT - Checks error code returned from PETSc function. If non-zero it aborts immediately.
5357037b0edSPatrick Sanan 
5367037b0edSPatrick Sanan    Synopsis:
5377037b0edSPatrick Sanan    #include <petscsys.h>
5387037b0edSPatrick Sanan    PetscErrorCode CHKERRABORT(MPI_Comm comm,PetscErrorCode ierr)
5397037b0edSPatrick Sanan 
5407037b0edSPatrick Sanan    Not Collective
5417037b0edSPatrick Sanan 
5427037b0edSPatrick Sanan    Input Parameters:
5437037b0edSPatrick Sanan .  ierr - nonzero error code, see the list of standard error codes in include/petscerror.h
5447037b0edSPatrick Sanan 
5457037b0edSPatrick Sanan   Level: intermediate
5467037b0edSPatrick Sanan 
5477037b0edSPatrick Sanan .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), SETERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2(), SETERRQ2(), SETERRABORT(), CHKERRMPI()
5487037b0edSPatrick Sanan M*/
549*6d210af2SJacob Faibussowitsch #if defined(PETSC_CLANG_STATIC_ANALYZER)
550064a246eSJacob Faibussowitsch #define CHKERRABORT(comm,ierr)
551064a246eSJacob Faibussowitsch #define CHKERRCONTINUE(ierr)
552*6d210af2SJacob Faibussowitsch #else
553*6d210af2SJacob Faibussowitsch #define CHKERRABORT(comm,ierr) do {PetscErrorCode ierr__ = (ierr); if (PetscUnlikely(ierr__)) {PetscError(PETSC_COMM_SELF,__LINE__,PETSC_FUNCTION_NAME,__FILE__,ierr__,PETSC_ERROR_REPEAT," ");MPI_Abort(comm,ierr);}} while (0)
554*6d210af2SJacob Faibussowitsch #define CHKERRCONTINUE(ierr)   do {PetscErrorCode ierr__ = (ierr); if (PetscUnlikely(ierr__)) {PetscError(PETSC_COMM_SELF,__LINE__,PETSC_FUNCTION_NAME,__FILE__,ierr__,PETSC_ERROR_REPEAT," ");}} while (0)
555064a246eSJacob Faibussowitsch #endif
556986eef2eSBarry Smith 
5577c66cc67SJunchao Zhang PETSC_EXTERN PetscErrorCode PetscAbortFindSourceFile_Private(const char*,PetscInt*);
5581e4f893aSSatish Balay PETSC_EXTERN PetscBool petscwaitonerrorflg;
5591e4f893aSSatish Balay PETSC_EXTERN PetscBool petscindebugger;
5607c66cc67SJunchao Zhang 
5617c66cc67SJunchao Zhang /*MC
5627c66cc67SJunchao Zhang    PETSCABORT - Call MPI_Abort with an informative error code
5637c66cc67SJunchao Zhang 
5647c66cc67SJunchao Zhang    Synopsis:
5657c66cc67SJunchao Zhang    #include <petscsys.h>
5667c66cc67SJunchao Zhang    PETSCABORT(MPI_Comm comm, PetscErrorCode ierr)
5677c66cc67SJunchao Zhang 
5687c66cc67SJunchao Zhang    Collective
5697c66cc67SJunchao Zhang 
5707c66cc67SJunchao Zhang    Input Parameters:
5717c66cc67SJunchao Zhang +  comm - A communicator, so that the error can be collective
5727c66cc67SJunchao Zhang -  ierr - nonzero error code, see the list of standard error codes in include/petscerror.h
5737c66cc67SJunchao Zhang 
574bf4d2887SBarry Smith    Level: advanced
5757c66cc67SJunchao Zhang 
576bf4d2887SBarry Smith    Notes:
577bf4d2887SBarry Smith    We pass MPI_Abort() an error code of format XX_YYYY_ZZZ, where XX, YYYY are an index and line number of the file
5787233276eSBarry Smith    where PETSCABORT is called, respectively. ZZZ is the PETSc error code.
5797c66cc67SJunchao Zhang 
5807233276eSBarry Smith    If XX is zero, this means that the call was made in the routine main().
5817233276eSBarry Smith    If XX is one, that means 1) the file is not in PETSc (it may be in users code); OR 2) the file is in PETSc but PetscAbortSourceFiles[]
5827c66cc67SJunchao Zhang      is out of date. PETSc developers have to update it.
583a0760fecSJunchao Zhang    Otherwise, look up the value of XX in the table PetscAbortSourceFiles[] in src/sys/error/err.c to map XX back to the source file where the PETSCABORT() was called.
5847233276eSBarry Smith 
585bf4d2887SBarry Smith    If the option -start_in_debugger was used then this calls abort() to stop the program in the debugger.
586bf4d2887SBarry Smith 
5877c66cc67SJunchao Zhang M*/
5887c66cc67SJunchao Zhang #define PETSCABORT(comm,ierr)  \
5897c66cc67SJunchao Zhang    do {                                                               \
5907c66cc67SJunchao Zhang       PetscInt       idx = 0;                                         \
5917c66cc67SJunchao Zhang       PetscMPIInt    errcode;                                         \
5927c66cc67SJunchao Zhang       PetscAbortFindSourceFile_Private(__FILE__,&idx);                \
59365f093c6SBarry Smith       errcode = (PetscMPIInt)(0*idx*10000000 + 0*__LINE__*1000 + ierr);   \
594baae8e41SSatish Balay       if (petscwaitonerrorflg) PetscSleep(1000);                      \
595bf4d2887SBarry Smith       if (petscindebugger) abort();                                   \
596bf4d2887SBarry Smith       else MPI_Abort(comm,errcode);                                   \
5977c66cc67SJunchao Zhang    } while (0)
598986eef2eSBarry Smith 
599986eef2eSBarry Smith /*MC
600888a1fb3SBarry Smith    CHKERRMPI - Checks error code returned from MPI calls, if non-zero it calls the error handler and then returns
601986eef2eSBarry Smith 
602986eef2eSBarry Smith    Synopsis:
603986eef2eSBarry Smith    #include <petscsys.h>
604986eef2eSBarry Smith    PetscErrorCode CHKERRMPI(PetscErrorCode ierr)
605986eef2eSBarry Smith 
606986eef2eSBarry Smith    Not Collective
607986eef2eSBarry Smith 
608986eef2eSBarry Smith    Input Parameters:
609986eef2eSBarry Smith .  ierr - nonzero error code, see the list of standard error codes in include/petscerror.h
610986eef2eSBarry Smith 
611888a1fb3SBarry Smith   Level: intermediate
612986eef2eSBarry Smith 
613986eef2eSBarry Smith    Notes:
614888a1fb3SBarry Smith     Always returns the error code PETSC_ERR_MPI; the MPI error code and string are embedded in the string error message
615986eef2eSBarry Smith 
6167037b0edSPatrick Sanan .seealso: CHKERRQ(), PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), SETERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2(), SETERRQ2(), SETERRMPI(), SETERRABORT(), CHKERRABORT()
617986eef2eSBarry Smith M*/
618*6d210af2SJacob Faibussowitsch #if defined(PETSC_CLANG_STATIC_ANALYZER)
619*6d210af2SJacob Faibussowitsch #define CHKERRMPI(ierr)
620*6d210af2SJacob Faibussowitsch #else
621ffc4695bSBarry Smith #define CHKERRMPI(ierr) \
622ffc4695bSBarry Smith do { \
6233aa7491dSLisandro Dalcin   PetscErrorCode _7_errorcode = (ierr); \
6243aa7491dSLisandro Dalcin   if (PetscUnlikely(_7_errorcode)) { \
6253aa7491dSLisandro Dalcin     char _7_errorstring[MPI_MAX_ERROR_STRING]; \
626a964e738SLisandro Dalcin     PetscMPIInt _7_resultlen; \
627a964e738SLisandro Dalcin     MPI_Error_string(_7_errorcode,(char*)_7_errorstring,&_7_resultlen); (void)_7_resultlen; \
6283aa7491dSLisandro Dalcin     SETERRQ2(PETSC_COMM_SELF,PETSC_ERR_MPI,"MPI error %d %s",(int)_7_errorcode,_7_errorstring); \
629ffc4695bSBarry Smith   } \
630ffc4695bSBarry Smith } while (0)
631064a246eSJacob Faibussowitsch #endif
63285614651SBarry Smith 
633fd705b32SMatthew Knepley #ifdef PETSC_CLANGUAGE_CXX
634fd705b32SMatthew Knepley 
635cc26af49SMatthew Knepley /*MC
636cc26af49SMatthew Knepley    CHKERRXX - Checks error code, if non-zero it calls the C++ error handler which throws an exception
637cc26af49SMatthew Knepley 
638cc26af49SMatthew Knepley    Synopsis:
639aaa7dc30SBarry Smith    #include <petscsys.h>
6403af045c5SBarry Smith    void CHKERRXX(PetscErrorCode ierr)
641cc26af49SMatthew Knepley 
642eca87e8dSBarry Smith    Not Collective
643cc26af49SMatthew Knepley 
644cc26af49SMatthew Knepley    Input Parameters:
6453af045c5SBarry Smith .  ierr - nonzero error code, see the list of standard error codes in include/petscerror.h
646cc26af49SMatthew Knepley 
647cc26af49SMatthew Knepley   Level: beginner
648cc26af49SMatthew Knepley 
649cc26af49SMatthew Knepley    Notes:
650cc26af49SMatthew Knepley     Once the error handler throws a ??? exception.
651cc26af49SMatthew Knepley 
652cc26af49SMatthew Knepley     You can use CHKERRV() which returns without an error code (bad idea since the error is ignored)
653cc26af49SMatthew Knepley     or CHKERRABORT(comm,n) to have MPI_Abort() returned immediately.
654cc26af49SMatthew Knepley 
655cc26af49SMatthew Knepley .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), SETERRQ(), CHKERRQ(), CHKMEMQ
656cc26af49SMatthew Knepley M*/
6573af045c5SBarry 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)
658fd705b32SMatthew Knepley #endif
659fd705b32SMatthew Knepley 
6603f520e80SJunchao Zhang /*MC
6613f520e80SJunchao Zhang    CHKERRCXX - Checks C++ function calls and if they throw an exception, catch it and then return a PETSc error code
6623f520e80SJunchao Zhang 
6633f520e80SJunchao Zhang    Synopsis:
6643f520e80SJunchao Zhang    #include <petscsys.h>
6653f520e80SJunchao Zhang    CHKERRCXX(func);
6663f520e80SJunchao Zhang 
6673f520e80SJunchao Zhang    Not Collective
6683f520e80SJunchao Zhang 
6693f520e80SJunchao Zhang    Input Parameters:
6703f520e80SJunchao Zhang .  func - C++ function calls
6713f520e80SJunchao Zhang 
6723f520e80SJunchao Zhang   Level: beginner
6733f520e80SJunchao Zhang 
6743f520e80SJunchao Zhang   Notes:
6753f520e80SJunchao Zhang    For example,
6763f520e80SJunchao Zhang 
6773f520e80SJunchao Zhang $     void foo(int x) {throw std::runtime_error("error");}
6783f520e80SJunchao Zhang $     CHKERRCXX(foo(1));
6793f520e80SJunchao Zhang 
6803f520e80SJunchao Zhang .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), SETERRQ(), CHKERRQ(), CHKMEMQ
6813f520e80SJunchao Zhang M*/
6823f520e80SJunchao Zhang #define CHKERRCXX(func) do {try {func;} catch (const std::exception& e) { SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_LIB,"%s", e.what()); }} while (0)
6833f520e80SJunchao Zhang 
68430de9b25SBarry Smith /*MC
68530de9b25SBarry Smith    CHKMEMQ - Checks the memory for corruption, calls error handler if any is detected
68630de9b25SBarry Smith 
68730de9b25SBarry Smith    Synopsis:
688aaa7dc30SBarry Smith    #include <petscsys.h>
68991d3bdf4SKris Buschelman    CHKMEMQ;
69030de9b25SBarry Smith 
691eca87e8dSBarry Smith    Not Collective
692eca87e8dSBarry Smith 
69330de9b25SBarry Smith   Level: beginner
69430de9b25SBarry Smith 
69530de9b25SBarry Smith    Notes:
696a17b96a8SKyle Gerard Felker     We highly recommend using Valgrind https://petsc.org/release/faq/#valgrind or for NVIDIA CUDA systems
6975ed36255SBarry Smith     https://docs.nvidia.com/cuda/cuda-memcheck/index.html for finding memory problems. The ``CHKMEMQ`` macro is useful on systems that
6985ed36255SBarry Smith     do not have valgrind, but is not as good as valgrind or cuda-memcheck.
6991957e957SBarry Smith 
70079dccf82SBarry Smith     Must run with the option -malloc_debug (-malloc_test in debug mode; or if PetscMallocSetDebug() called) to enable this option
70130de9b25SBarry Smith 
70230de9b25SBarry Smith     Once the error handler is called the calling function is then returned from with the given error code.
70330de9b25SBarry Smith 
70430de9b25SBarry Smith     By defaults prints location where memory that is corrupted was allocated.
70530de9b25SBarry Smith 
706f621e05eSBarry Smith     Use CHKMEMA for functions that return void
707f621e05eSBarry Smith 
7086024bd2cSBarry Smith .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), SETERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2(), SETERRQ3(),
709ff002950SBarry Smith           PetscMallocValidate()
71030de9b25SBarry Smith M*/
711*6d210af2SJacob Faibussowitsch #if defined(PETSC_CLANG_STATIC_ANALYZER)
712064a246eSJacob Faibussowitsch #define CHKMEMQ
713064a246eSJacob Faibussowitsch #define CHKMEMA
714*6d210af2SJacob Faibussowitsch #else
715*6d210af2SJacob Faibussowitsch #define CHKMEMQ do {PetscErrorCode _7_ierr = PetscMallocValidate(__LINE__,PETSC_FUNCTION_NAME,__FILE__);CHKERRQ(_7_ierr);} while (0)
716*6d210af2SJacob Faibussowitsch #define CHKMEMA PetscMallocValidate(__LINE__,PETSC_FUNCTION_NAME,__FILE__)
717064a246eSJacob Faibussowitsch #endif
718668f157eSBarry Smith /*E
719668f157eSBarry Smith   PetscErrorType - passed to the PETSc error handling routines indicating if this is the first or a later call to the error handlers
720668f157eSBarry Smith 
721668f157eSBarry Smith   Level: advanced
722668f157eSBarry Smith 
723d736bfebSBarry Smith   PETSC_ERROR_IN_CXX indicates the error was detected in C++ and an exception should be generated
724d736bfebSBarry Smith 
72595452b02SPatrick Sanan   Developer Notes:
72695452b02SPatrick Sanan     This is currently used to decide when to print the detailed information about the run in PetscTraceBackErrorHandler()
727668f157eSBarry Smith 
728d736bfebSBarry Smith .seealso: PetscError(), SETERRXX()
729668f157eSBarry Smith E*/
730d736bfebSBarry Smith typedef enum {PETSC_ERROR_INITIAL=0,PETSC_ERROR_REPEAT=1,PETSC_ERROR_IN_CXX = 2} PetscErrorType;
7314b209cf6SBarry Smith 
732eb9e708aSLisandro Dalcin #if defined(__clang_analyzer__)
733eb9e708aSLisandro Dalcin __attribute__((analyzer_noreturn))
734eb9e708aSLisandro Dalcin #endif
7353ca90d2dSJacob Faibussowitsch PETSC_EXTERN PetscErrorCode PetscError(MPI_Comm,int,const char*,const char*,PetscErrorCode,PetscErrorType,const char*,...) PETSC_ATTRIBUTE_FORMAT(7,8);
736eb9e708aSLisandro Dalcin 
737014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscErrorPrintfInitialize(void);
738014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscErrorMessage(int,const char*[],char **);
739efca3c55SSatish Balay PETSC_EXTERN PetscErrorCode PetscTraceBackErrorHandler(MPI_Comm,int,const char*,const char*,PetscErrorCode,PetscErrorType,const char*,void*);
740efca3c55SSatish Balay PETSC_EXTERN PetscErrorCode PetscIgnoreErrorHandler(MPI_Comm,int,const char*,const char*,PetscErrorCode,PetscErrorType,const char*,void*);
741efca3c55SSatish Balay PETSC_EXTERN PetscErrorCode PetscEmacsClientErrorHandler(MPI_Comm,int,const char*,const char*,PetscErrorCode,PetscErrorType,const char*,void*);
742efca3c55SSatish Balay PETSC_EXTERN PetscErrorCode PetscMPIAbortErrorHandler(MPI_Comm,int,const char*,const char*,PetscErrorCode,PetscErrorType,const char*,void*);
743efca3c55SSatish Balay PETSC_EXTERN PetscErrorCode PetscAbortErrorHandler(MPI_Comm,int,const char*,const char*,PetscErrorCode,PetscErrorType,const char*,void*);
744efca3c55SSatish Balay PETSC_EXTERN PetscErrorCode PetscAttachDebuggerErrorHandler(MPI_Comm,int,const char*,const char*,PetscErrorCode,PetscErrorType,const char*,void*);
745efca3c55SSatish Balay PETSC_EXTERN PetscErrorCode PetscReturnErrorHandler(MPI_Comm,int,const char*,const char*,PetscErrorCode,PetscErrorType,const char*,void*);
746efca3c55SSatish Balay PETSC_EXTERN PetscErrorCode PetscPushErrorHandler(PetscErrorCode (*handler)(MPI_Comm,int,const char*,const char*,PetscErrorCode,PetscErrorType,const char*,void*),void*);
747014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscPopErrorHandler(void);
7488d359177SBarry Smith PETSC_EXTERN PetscErrorCode PetscSignalHandlerDefault(int,void*);
749014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscPushSignalHandler(PetscErrorCode (*)(int,void *),void*);
750014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscPopSignalHandler(void);
75128559dc8SJed Brown PETSC_EXTERN PetscErrorCode PetscCheckPointerSetIntensity(PetscInt);
752c2a741eeSJunchao Zhang PETSC_EXTERN void PetscSignalSegvCheckPointerOrMpi(void);
753c2a741eeSJunchao Zhang PETSC_DEPRECATED_FUNCTION("Use PetscSignalSegvCheckPointerOrMpi() (since version 3.13)") PETSC_STATIC_INLINE void PetscSignalSegvCheckPointer(void) {PetscSignalSegvCheckPointerOrMpi();}
754329f5518SBarry Smith 
755639ff905SBarry Smith /*MC
756639ff905SBarry Smith     PetscErrorPrintf - Prints error messages.
757639ff905SBarry Smith 
758639ff905SBarry Smith    Synopsis:
759aaa7dc30SBarry Smith     #include <petscsys.h>
760639ff905SBarry Smith      PetscErrorCode (*PetscErrorPrintf)(const char format[],...);
761639ff905SBarry Smith 
762639ff905SBarry Smith     Not Collective
763639ff905SBarry Smith 
764f899ff85SJose E. Roman     Input Parameter:
765639ff905SBarry Smith .   format - the usual printf() format string
766639ff905SBarry Smith 
767639ff905SBarry Smith    Options Database Keys:
7681957e957SBarry Smith +    -error_output_stdout - cause error messages to be printed to stdout instead of the  (default) stderr
769e1bc860dSBarry Smith -    -error_output_none - to turn off all printing of error messages (does not change the way the error is handled.)
770639ff905SBarry Smith 
77195452b02SPatrick Sanan    Notes:
77295452b02SPatrick Sanan     Use
773639ff905SBarry Smith $     PetscErrorPrintf = PetscErrorPrintfNone; to turn off all printing of error messages (does not change the way the
774639ff905SBarry Smith $                        error is handled.) and
7751957e957SBarry Smith $     PetscErrorPrintf = PetscErrorPrintfDefault; to turn it back on or you can use your own function
776639ff905SBarry Smith 
777639ff905SBarry Smith           Use
778639ff905SBarry Smith      PETSC_STDERR = FILE* obtained from a file open etc. to have stderr printed to the file.
779639ff905SBarry Smith      PETSC_STDOUT = FILE* obtained from a file open etc. to have stdout printed to the file.
780639ff905SBarry Smith 
781639ff905SBarry Smith           Use
782639ff905SBarry Smith       PetscPushErrorHandler() to provide your own error handler that determines what kind of messages to print
783639ff905SBarry Smith 
784639ff905SBarry Smith    Level: developer
785639ff905SBarry Smith 
786639ff905SBarry Smith     Fortran Note:
787639ff905SBarry Smith     This routine is not supported in Fortran.
788639ff905SBarry Smith 
7892b60790dSJed Brown .seealso: PetscFPrintf(), PetscSynchronizedPrintf(), PetscHelpPrintf(), PetscPrintf(), PetscPushErrorHandler(), PetscVFPrintf(), PetscHelpPrintf()
790639ff905SBarry Smith M*/
7913ca90d2dSJacob Faibussowitsch PETSC_EXTERN PetscErrorCode (*PetscErrorPrintf)(const char[],...) PETSC_ATTRIBUTE_FORMAT(1,2);
792639ff905SBarry Smith 
793329f5518SBarry Smith typedef enum {PETSC_FP_TRAP_OFF=0,PETSC_FP_TRAP_ON=1} PetscFPTrap;
794014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSetFPTrap(PetscFPTrap);
795014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscFPTrapPush(PetscFPTrap);
796014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscFPTrapPop(void);
797aba4c478SBarry Smith PETSC_EXTERN PetscErrorCode PetscDetermineInitialFPTrap(void);
79854a8ef01SBarry Smith 
7993a40ed3dSBarry Smith /*
8003a40ed3dSBarry Smith       Allows the code to build a stack frame as it runs
8013a40ed3dSBarry Smith */
8023a40ed3dSBarry Smith 
80327104ee2SJacob Faibussowitsch #if defined(PETSC_USE_DEBUG)
80499cd645aSJed Brown #define PETSCSTACKSIZE 64
8053a40ed3dSBarry Smith typedef struct  {
8060e33f6ddSBarry Smith   const char *function[PETSCSTACKSIZE];
8070e33f6ddSBarry Smith   const char *file[PETSCSTACKSIZE];
808184914b5SBarry Smith         int  line[PETSCSTACKSIZE];
809362febeeSStefano Zampini         int  petscroutine[PETSCSTACKSIZE]; /* 0 external called from petsc, 1 petsc functions, 2 petsc user functions */
810184914b5SBarry Smith         int  currentsize;
811a2f94806SJed Brown         int  hotdepth;
812362febeeSStefano Zampini   PetscBool  check; /* runtime option to check for correct Push/Pop semantics at runtime */
8133a40ed3dSBarry Smith } PetscStack;
81427104ee2SJacob Faibussowitsch PETSC_EXTERN PetscStack petscstack;
81527104ee2SJacob Faibussowitsch #else
81627104ee2SJacob Faibussowitsch typedef struct {
81727104ee2SJacob Faibussowitsch   char Silence_empty_struct_has_size_0_in_C_size_1_in_Cpp;
81827104ee2SJacob Faibussowitsch } PetscStack;
81927104ee2SJacob Faibussowitsch #endif
8203a40ed3dSBarry Smith 
8215d12eec7SSatish Balay #if defined(PETSC_SERIALIZE_FUNCTIONS)
8225d12eec7SSatish Balay #include <petsc/private/petscfptimpl.h>
8235d12eec7SSatish Balay /*
8245d12eec7SSatish Balay    Registers the current function into the global function pointer to function name table
8255d12eec7SSatish Balay 
8265d12eec7SSatish Balay    Have to fix this to handle errors but cannot return error since used in PETSC_VIEWER_DRAW_() etc
8275d12eec7SSatish Balay */
8285d12eec7SSatish Balay #define PetscRegister__FUNCT__() do { \
8295d12eec7SSatish Balay   static PetscBool __chked = PETSC_FALSE; \
8305d12eec7SSatish Balay   if (!__chked) {\
8315d12eec7SSatish Balay   void *ptr; PetscDLSym(NULL,PETSC_FUNCTION_NAME,&ptr);\
8325d12eec7SSatish Balay   __chked = PETSC_TRUE;\
8335d12eec7SSatish Balay   }} while (0)
8345d12eec7SSatish Balay #else
8355d12eec7SSatish Balay #define PetscRegister__FUNCT__()
8365d12eec7SSatish Balay #endif
8375d12eec7SSatish Balay 
838*6d210af2SJacob Faibussowitsch #if defined(PETSC_CLANG_STATIC_ANALYZER)
839*6d210af2SJacob Faibussowitsch #define PetscStackPushNoCheck(funct,petsc_routine,hot)
840*6d210af2SJacob Faibussowitsch #define PetscStackPopNoCheck
841*6d210af2SJacob Faibussowitsch #define PetscStackClearTop
842*6d210af2SJacob Faibussowitsch #define PetscFunctionBegin
843*6d210af2SJacob Faibussowitsch #define PetscFunctionBeginUser
844*6d210af2SJacob Faibussowitsch #define PetscFunctionBeginHot
845*6d210af2SJacob Faibussowitsch #define PetscFunctionReturn(a)    return a
846*6d210af2SJacob Faibussowitsch #define PetscFunctionReturnVoid() return
847*6d210af2SJacob Faibussowitsch #define PetscStackPop
848*6d210af2SJacob Faibussowitsch #define PetscStackPush(f)
849*6d210af2SJacob Faibussowitsch #elif defined(PETSC_USE_DEBUG)
850441dd030SJed Brown /* Stack handling is based on the following two "NoCheck" macros.  These should only be called directly by other error
851441dd030SJed Brown  * handling macros.  We record the line of the call, which may or may not be the location of the definition.  But is at
852441dd030SJed Brown  * least more useful than "unknown" because it can distinguish multiple calls from the same function.
853441dd030SJed Brown  */
85427104ee2SJacob Faibussowitsch #define PetscStackPushNoCheck(funct,petsc_routine,hot) do {             \
855e04113cfSBarry Smith     PetscStackSAWsTakeAccess();                                         \
85627104ee2SJacob Faibussowitsch     if (petscstack.currentsize < PETSCSTACKSIZE) {                      \
85727104ee2SJacob Faibussowitsch       petscstack.function[petscstack.currentsize]     = funct;          \
85827104ee2SJacob Faibussowitsch       petscstack.file[petscstack.currentsize]         = __FILE__;       \
85927104ee2SJacob Faibussowitsch       petscstack.line[petscstack.currentsize]         = __LINE__;       \
86027104ee2SJacob Faibussowitsch       petscstack.petscroutine[petscstack.currentsize] = petsc_routine;  \
861441dd030SJed Brown     }                                                                   \
86227104ee2SJacob Faibussowitsch     ++petscstack.currentsize;                                           \
86327104ee2SJacob Faibussowitsch     petscstack.hotdepth += (hot || petscstack.hotdepth);                \
864e04113cfSBarry Smith     PetscStackSAWsGrantAccess();                                        \
865441dd030SJed Brown   } while (0)
866441dd030SJed Brown 
86727104ee2SJacob Faibussowitsch #define PetscStackPopNoCheck(funct)                    do {             \
868362febeeSStefano Zampini     PetscStackSAWsTakeAccess();                                         \
8691724198aSStefano Zampini     if (PetscUnlikely(petscstack.currentsize <= 0)) {                   \
8701724198aSStefano Zampini       if (PetscUnlikely(petscstack.check)) {                            \
87127104ee2SJacob Faibussowitsch         printf("Invalid stack size %d, pop %s\n",                       \
87227104ee2SJacob Faibussowitsch                petscstack.currentsize,funct);                           \
8731724198aSStefano Zampini       }                                                                 \
874362febeeSStefano Zampini     } else {                                                            \
87527104ee2SJacob Faibussowitsch       if (--petscstack.currentsize < PETSCSTACKSIZE) {                  \
87627104ee2SJacob Faibussowitsch         if (PetscUnlikely(                                              \
87727104ee2SJacob Faibussowitsch               petscstack.check                                &&        \
87827104ee2SJacob Faibussowitsch               petscstack.petscroutine[petscstack.currentsize] &&        \
87927104ee2SJacob Faibussowitsch               (petscstack.function[petscstack.currentsize]    !=        \
88027104ee2SJacob Faibussowitsch                (const char*)funct))) {                                  \
881ecbde57cSMatthew G. Knepley           /* We need this string comparison because "unknown" can be defined in different static strings: */ \
882ecbde57cSMatthew G. Knepley           PetscBool _cmpflg;                                            \
883ecbde57cSMatthew G. Knepley           const char *_funct = petscstack.function[petscstack.currentsize]; \
884ecbde57cSMatthew G. Knepley           PetscStrcmp(_funct,funct,&_cmpflg);                           \
885ecbde57cSMatthew G. Knepley           if (!_cmpflg)                                                 \
886ecbde57cSMatthew G. Knepley             printf("Invalid stack: push from %s, pop from %s\n", _funct,funct); \
887362febeeSStefano Zampini         }                                                               \
88827104ee2SJacob Faibussowitsch         petscstack.function[petscstack.currentsize] = PETSC_NULLPTR;    \
88927104ee2SJacob Faibussowitsch         petscstack.file[petscstack.currentsize]     = PETSC_NULLPTR;    \
89027104ee2SJacob Faibussowitsch         petscstack.line[petscstack.currentsize]     = 0;                \
89127104ee2SJacob Faibussowitsch         petscstack.petscroutine[petscstack.currentsize] = 0;            \
892362febeeSStefano Zampini       }                                                                 \
89327104ee2SJacob Faibussowitsch       petscstack.hotdepth = PetscMax(petscstack.hotdepth-1,0);          \
894362febeeSStefano Zampini     }                                                                   \
895362febeeSStefano Zampini     PetscStackSAWsGrantAccess();                                        \
896362febeeSStefano Zampini   } while (0)
897362febeeSStefano Zampini 
89827104ee2SJacob Faibussowitsch #define PetscStackClearTop                             do {             \
899e04113cfSBarry Smith     PetscStackSAWsTakeAccess();                                         \
9001724198aSStefano Zampini     if (petscstack.currentsize > 0 &&                                   \
9011724198aSStefano Zampini         --petscstack.currentsize < PETSCSTACKSIZE) {                    \
90227104ee2SJacob Faibussowitsch       petscstack.function[petscstack.currentsize]     = PETSC_NULLPTR;  \
90327104ee2SJacob Faibussowitsch       petscstack.file[petscstack.currentsize]         = PETSC_NULLPTR;  \
90427104ee2SJacob Faibussowitsch       petscstack.line[petscstack.currentsize]         = 0;              \
90527104ee2SJacob Faibussowitsch       petscstack.petscroutine[petscstack.currentsize] = 0;              \
906441dd030SJed Brown     }                                                                   \
90727104ee2SJacob Faibussowitsch     petscstack.hotdepth = PetscMax(petscstack.hotdepth-1,0);            \
908e04113cfSBarry Smith     PetscStackSAWsGrantAccess();                                        \
909441dd030SJed Brown   } while (0)
910441dd030SJed Brown 
91130de9b25SBarry Smith /*MC
9121957e957SBarry Smith    PetscFunctionBegin - First executable line of each PETSc function,  used for error handling. Final
9131957e957SBarry Smith       line of PETSc functions should be PetscFunctionReturn(0);
91430de9b25SBarry Smith 
91530de9b25SBarry Smith    Synopsis:
916aaa7dc30SBarry Smith    #include <petscsys.h>
91730de9b25SBarry Smith    void PetscFunctionBegin;
91830de9b25SBarry Smith 
919eca87e8dSBarry Smith    Not Collective
920eca87e8dSBarry Smith 
92130de9b25SBarry Smith    Usage:
92230de9b25SBarry Smith .vb
92330de9b25SBarry Smith      int something;
92430de9b25SBarry Smith 
92530de9b25SBarry Smith      PetscFunctionBegin;
92630de9b25SBarry Smith .ve
92730de9b25SBarry Smith 
92830de9b25SBarry Smith    Notes:
9291957e957SBarry Smith      Use PetscFunctionBeginUser for application codes.
9301957e957SBarry Smith 
93130de9b25SBarry Smith      Not available in Fortran
93230de9b25SBarry Smith 
93330de9b25SBarry Smith    Level: developer
93430de9b25SBarry Smith 
9351957e957SBarry Smith .seealso: PetscFunctionReturn(), PetscFunctionBeginHot(), PetscFunctionBeginUser()
93630de9b25SBarry Smith 
93730de9b25SBarry Smith M*/
938441dd030SJed Brown #define PetscFunctionBegin do {                               \
939362febeeSStefano Zampini     PetscStackPushNoCheck(PETSC_FUNCTION_NAME,1,PETSC_FALSE); \
940a2f94806SJed Brown     PetscRegister__FUNCT__();                                 \
941a2f94806SJed Brown   } while (0)
942a2f94806SJed Brown 
943a2f94806SJed Brown /*MC
944a2f94806SJed Brown    PetscFunctionBeginHot - Substitute for PetscFunctionBegin to be used in functions that are called in
945a2f94806SJed Brown    performance-critical circumstances.  Use of this function allows for lighter profiling by default.
946a2f94806SJed Brown 
947a2f94806SJed Brown    Synopsis:
948aaa7dc30SBarry Smith    #include <petscsys.h>
949a2f94806SJed Brown    void PetscFunctionBeginHot;
950a2f94806SJed Brown 
951a2f94806SJed Brown    Not Collective
952a2f94806SJed Brown 
953a2f94806SJed Brown    Usage:
954a2f94806SJed Brown .vb
955a2f94806SJed Brown      int something;
956a2f94806SJed Brown 
957a2f94806SJed Brown      PetscFunctionBeginHot;
958a2f94806SJed Brown .ve
959a2f94806SJed Brown 
960a2f94806SJed Brown    Notes:
961a2f94806SJed Brown      Not available in Fortran
962a2f94806SJed Brown 
963a2f94806SJed Brown    Level: developer
964a2f94806SJed Brown 
965a2f94806SJed Brown .seealso: PetscFunctionBegin, PetscFunctionReturn()
966a2f94806SJed Brown 
967a2f94806SJed Brown M*/
968a2f94806SJed Brown #define PetscFunctionBeginHot do {                           \
969362febeeSStefano Zampini     PetscStackPushNoCheck(PETSC_FUNCTION_NAME,1,PETSC_TRUE); \
9702d53ad75SBarry Smith     PetscRegister__FUNCT__();                                \
97153c77d0aSJed Brown   } while (0)
97253c77d0aSJed Brown 
973a8d2bbe5SBarry Smith /*MC
974a8d2bbe5SBarry Smith    PetscFunctionBeginUser - First executable line of user provided PETSc routine
975a8d2bbe5SBarry Smith 
976a8d2bbe5SBarry Smith    Synopsis:
977aaa7dc30SBarry Smith    #include <petscsys.h>
978a8d2bbe5SBarry Smith    void PetscFunctionBeginUser;
979a8d2bbe5SBarry Smith 
980a8d2bbe5SBarry Smith    Not Collective
981a8d2bbe5SBarry Smith 
982a8d2bbe5SBarry Smith    Usage:
983a8d2bbe5SBarry Smith .vb
984a8d2bbe5SBarry Smith      int something;
985a8d2bbe5SBarry Smith 
986ac285190SBarry Smith      PetscFunctionBeginUser;
987a8d2bbe5SBarry Smith .ve
988a8d2bbe5SBarry Smith 
989a8d2bbe5SBarry Smith    Notes:
9901957e957SBarry Smith       Final line of PETSc functions should be PetscFunctionReturn(0) except for main().
9911957e957SBarry Smith 
992a8d2bbe5SBarry Smith       Not available in Fortran
993a8d2bbe5SBarry Smith 
994ac285190SBarry Smith       This is identical to PetscFunctionBegin except it labels the routine as a user
995ac285190SBarry Smith       routine instead of as a PETSc library routine.
996ac285190SBarry Smith 
997a2f94806SJed Brown    Level: intermediate
998a8d2bbe5SBarry Smith 
999a2f94806SJed Brown .seealso: PetscFunctionReturn(), PetscFunctionBegin, PetscFunctionBeginHot
1000a8d2bbe5SBarry Smith 
1001a8d2bbe5SBarry Smith M*/
100227104ee2SJacob Faibussowitsch #define PetscFunctionBeginUser do {                           \
1003362febeeSStefano Zampini     PetscStackPushNoCheck(PETSC_FUNCTION_NAME,2,PETSC_FALSE); \
1004a8d2bbe5SBarry Smith     PetscRegister__FUNCT__();                                 \
1005a8d2bbe5SBarry Smith   } while (0)
1006a8d2bbe5SBarry Smith 
100727104ee2SJacob Faibussowitsch #define PetscStackPush(n)       do {        \
1008362febeeSStefano Zampini     PetscStackPushNoCheck(n,0,PETSC_FALSE); \
100915681b3cSBarry Smith     CHKMEMQ;                                \
101015681b3cSBarry Smith   } while (0)
10113a40ed3dSBarry Smith 
101227104ee2SJacob Faibussowitsch #define PetscStackPop           do {             \
1013441dd030SJed Brown       CHKMEMQ;                                   \
1014362febeeSStefano Zampini       PetscStackPopNoCheck(PETSC_FUNCTION_NAME); \
101515681b3cSBarry Smith     } while (0)
1016d64ed03dSBarry Smith 
101730de9b25SBarry Smith /*MC
101830de9b25SBarry Smith    PetscFunctionReturn - Last executable line of each PETSc function
101930de9b25SBarry Smith         used for error handling. Replaces return()
102030de9b25SBarry Smith 
102130de9b25SBarry Smith    Synopsis:
1022aaa7dc30SBarry Smith    #include <petscsys.h>
102330de9b25SBarry Smith    void PetscFunctionReturn(0);
102430de9b25SBarry Smith 
1025eca87e8dSBarry Smith    Not Collective
1026eca87e8dSBarry Smith 
102730de9b25SBarry Smith    Usage:
102830de9b25SBarry Smith .vb
102930de9b25SBarry Smith     ....
103030de9b25SBarry Smith      PetscFunctionReturn(0);
103130de9b25SBarry Smith    }
103230de9b25SBarry Smith .ve
103330de9b25SBarry Smith 
103430de9b25SBarry Smith    Notes:
103530de9b25SBarry Smith      Not available in Fortran
103630de9b25SBarry Smith 
103730de9b25SBarry Smith    Level: developer
103830de9b25SBarry Smith 
103930de9b25SBarry Smith .seealso: PetscFunctionBegin()
104030de9b25SBarry Smith 
104130de9b25SBarry Smith M*/
104227104ee2SJacob Faibussowitsch #define PetscFunctionReturn(a)    do {          \
1043362febeeSStefano Zampini     PetscStackPopNoCheck(PETSC_FUNCTION_NAME);  \
104427104ee2SJacob Faibussowitsch     return a;                                   \
104527104ee2SJacob Faibussowitsch   } while (0)
1046d64ed03dSBarry Smith 
104727104ee2SJacob Faibussowitsch #define PetscFunctionReturnVoid() do {          \
1048362febeeSStefano Zampini     PetscStackPopNoCheck(PETSC_FUNCTION_NAME);  \
104927104ee2SJacob Faibussowitsch     return;                                     \
105027104ee2SJacob Faibussowitsch   } while (0)
105127104ee2SJacob Faibussowitsch #else /* PETSC_USE_DEBUG */
105227104ee2SJacob Faibussowitsch #define PetscStackPushNoCheck(funct,petsc_routine,hot)
105327104ee2SJacob Faibussowitsch #define PetscStackPopNoCheck
105427104ee2SJacob Faibussowitsch #define PetscStackClearTop
10553a40ed3dSBarry Smith #define PetscFunctionBegin
10560bdf7c52SPeter Brune #define PetscFunctionBeginUser
1057a2f94806SJed Brown #define PetscFunctionBeginHot
105827104ee2SJacob Faibussowitsch #define PetscFunctionReturn(a)    return a
10595665465eSBarry Smith #define PetscFunctionReturnVoid() return
1060812af9f3SBarry Smith #define PetscStackPop             CHKMEMQ
1061812af9f3SBarry Smith #define PetscStackPush(f)         CHKMEMQ
106227104ee2SJacob Faibussowitsch #endif /* PETSC_USE_DEBUG */
10633a40ed3dSBarry Smith 
1064*6d210af2SJacob Faibussowitsch #if defined(PETSC_CLANG_STATIC_ANALYZER)
1065*6d210af2SJacob Faibussowitsch #define PetscStackCall(name,routine)
1066*6d210af2SJacob Faibussowitsch #define PetscStackCallStandard(name,routine)
1067*6d210af2SJacob Faibussowitsch #else
1068eb6b5d47SBarry Smith /*
1069eb6b5d47SBarry Smith     PetscStackCall - Calls an external library routine or user function after pushing the name of the routine on the stack.
1070eb6b5d47SBarry Smith 
1071eb6b5d47SBarry Smith    Input Parameters:
1072eb6b5d47SBarry Smith +   name - string that gives the name of the function being called
1073fd3f9acdSBarry Smith -   routine - actual call to the routine, including ierr = and CHKERRQ(ierr);
1074fd3f9acdSBarry Smith 
1075dbf62e16SBarry Smith    Note: Often one should use PetscStackCallStandard() instead. This routine is intended for external library routines that DO NOT return error codes
1076eb6b5d47SBarry Smith 
1077eb6b5d47SBarry 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.
1078eb6b5d47SBarry Smith 
1079eb6b5d47SBarry Smith */
108030ecc5abSKarl Rupp #define PetscStackCall(name,routine) do { PetscStackPush(name);routine;PetscStackPop; } while (0)
1081eb6b5d47SBarry Smith 
1082fd3f9acdSBarry Smith /*
1083fd3f9acdSBarry Smith     PetscStackCallStandard - Calls an external library routine after pushing the name of the routine on the stack.
1084fd3f9acdSBarry Smith 
1085fd3f9acdSBarry Smith    Input Parameters:
1086fd3f9acdSBarry Smith +   func-  name of the routine
1087fd3f9acdSBarry Smith -   args - arguments to the routine surrounded by ()
1088fd3f9acdSBarry Smith 
108995452b02SPatrick Sanan    Notes:
109095452b02SPatrick Sanan     This is intended for external package routines that return error codes. Use PetscStackCall() for those that do not.
1091dbf62e16SBarry Smith 
1092dbf62e16SBarry 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.
1093fd3f9acdSBarry Smith 
1094fd3f9acdSBarry Smith */
1095fd3f9acdSBarry Smith #define PetscStackCallStandard(func,args) do {                                                            \
10961d4906efSStefano Zampini     PetscErrorCode __ierr;                                                                                \
10971d4906efSStefano Zampini     PetscStackPush(#func);                                                                                \
10981d4906efSStefano Zampini     __ierr = func args;                                                                                   \
10991d4906efSStefano Zampini     PetscStackPop;                                                                                        \
11001d4906efSStefano Zampini     if (__ierr) SETERRQ2(PETSC_COMM_SELF,PETSC_ERR_LIB,"Error in %s(): error code %d",#func,(int)__ierr); \
1101fd3f9acdSBarry Smith   } while (0)
1102*6d210af2SJacob Faibussowitsch #endif /* PETSC_CLANG_STATIC_ANALYZER */
110306d1fe2cSBarry Smith 
110406d1fe2cSBarry Smith #endif
1105