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 /* 84f227f7cSBarry Smith Defines the function where the compiled source is located; used 9f621e05eSBarry Smith in printing error messages. This is defined here in case the user 10f621e05eSBarry Smith does not declare it. 114f227f7cSBarry Smith */ 124a2ae208SSatish Balay #if !defined(__FUNCT__) 13da9b6338SBarry Smith #define __FUNCT__ "User provided function" 144f227f7cSBarry Smith #endif 154f227f7cSBarry Smith 164f227f7cSBarry Smith /* 17329ffe3dSLois Curfman McInnes These are the generic error codes. These error codes are used 18e2d1d2b7SBarry Smith many different places in the PETSc source code. The string versions are 190e5e90baSSatish Balay at src/sys/error/err.c any changes here must also be made there 20af0996ceSBarry Smith These are also define in include/petsc/finclude/petscerror.h any CHANGES here 210f9cf654SBarry Smith must be also made there. 2245d48df9SBarry Smith 2354a8ef01SBarry Smith */ 242a6744ebSBarry Smith #define PETSC_ERR_MIN_VALUE 54 /* should always be one less then the smallest value */ 252a6744ebSBarry Smith 2645d48df9SBarry Smith #define PETSC_ERR_MEM 55 /* unable to allocate requested memory */ 2747794344SBarry Smith #define PETSC_ERR_SUP 56 /* no support for requested operation */ 28e2d1d2b7SBarry Smith #define PETSC_ERR_SUP_SYS 57 /* no support for requested operation on this computer system */ 29e2d1d2b7SBarry Smith #define PETSC_ERR_ORDER 58 /* operation done in wrong order */ 3045d48df9SBarry Smith #define PETSC_ERR_SIG 59 /* signal received */ 31f1caa5a4SBarry Smith #define PETSC_ERR_FP 72 /* floating point exception */ 32a8c6a408SBarry Smith #define PETSC_ERR_COR 74 /* corrupted PETSc object */ 33a8c6a408SBarry Smith #define PETSC_ERR_LIB 76 /* error in library called by PETSc */ 34329ffe3dSLois Curfman McInnes #define PETSC_ERR_PLIB 77 /* PETSc library generated inconsistent data */ 35329ffe3dSLois Curfman McInnes #define PETSC_ERR_MEMC 78 /* memory corruption */ 36b3cc6726SBarry Smith #define PETSC_ERR_CONV_FAILED 82 /* iterative method (KSP or SNES) failed */ 371302d50aSBarry Smith #define PETSC_ERR_USER 83 /* user has not provided needed function */ 384e2ffeddSBarry Smith #define PETSC_ERR_SYS 88 /* error in system call */ 39a8b45ee7SBarry Smith #define PETSC_ERR_POINTER 70 /* pointer does not point to valid address */ 4045d48df9SBarry Smith 4145d48df9SBarry Smith #define PETSC_ERR_ARG_SIZ 60 /* nonconforming object sizes used in operation */ 4245d48df9SBarry Smith #define PETSC_ERR_ARG_IDN 61 /* two arguments not allowed to be the same */ 43a8c6a408SBarry Smith #define PETSC_ERR_ARG_WRONG 62 /* wrong argument (but object probably ok) */ 4445d48df9SBarry Smith #define PETSC_ERR_ARG_CORRUPT 64 /* null or corrupted PETSc object as argument */ 4545d48df9SBarry Smith #define PETSC_ERR_ARG_OUTOFRANGE 63 /* input argument, out of range */ 464f227f7cSBarry Smith #define PETSC_ERR_ARG_BADPTR 68 /* invalid pointer argument */ 474f227f7cSBarry Smith #define PETSC_ERR_ARG_NOTSAMETYPE 69 /* two args must be same object type */ 486831982aSBarry Smith #define PETSC_ERR_ARG_NOTSAMECOMM 80 /* two args must be same communicators */ 49d252947aSBarry Smith #define PETSC_ERR_ARG_WRONGSTATE 73 /* object in argument is in wrong state, e.g. unassembled mat */ 508cda6cd7SBarry Smith #define PETSC_ERR_ARG_TYPENOTSET 89 /* the type of the object has not yet been set */ 51a8c6a408SBarry Smith #define PETSC_ERR_ARG_INCOMP 75 /* two arguments are incompatible */ 524482741eSBarry Smith #define PETSC_ERR_ARG_NULL 85 /* argument is null that should not be */ 53958c9bccSBarry Smith #define PETSC_ERR_ARG_UNKNOWN_TYPE 86 /* type name doesn't match any registered type */ 544f227f7cSBarry Smith 554f227f7cSBarry Smith #define PETSC_ERR_FILE_OPEN 65 /* unable to open file */ 564f227f7cSBarry Smith #define PETSC_ERR_FILE_READ 66 /* unable to read from file */ 574f227f7cSBarry Smith #define PETSC_ERR_FILE_WRITE 67 /* unable to write to file */ 58a8c6a408SBarry Smith #define PETSC_ERR_FILE_UNEXPECTED 79 /* unexpected data in file */ 5945d48df9SBarry Smith 60329ffe3dSLois Curfman McInnes #define PETSC_ERR_MAT_LU_ZRPVT 71 /* detected a zero pivot during LU factorization */ 619e3b2f23SBarry Smith #define PETSC_ERR_MAT_CH_ZRPVT 81 /* detected a zero pivot during Cholesky factorization */ 6254a8ef01SBarry Smith 6368e69593SBarry Smith #define PETSC_ERR_INT_OVERFLOW 84 643855c12bSBarry Smith 65bf3909cdSBarry Smith #define PETSC_ERR_FLOP_COUNT 90 66e113a28aSBarry Smith #define PETSC_ERR_NOT_CONVERGED 91 /* solver did not converge */ 6792e8f287SBarry Smith #define PETSC_ERR_MISSING_FACTOR 92 /* MatGetFactor() failed */ 68c5a392abSBarry Smith #define PETSC_ERR_OPT_OVERWRITE 93 /* attempted to over wrote options which should not be changed */ 692a6744ebSBarry Smith 70c5a392abSBarry Smith #define PETSC_ERR_MAX_VALUE 94 /* this is always the one more than the largest error code */ 71b9eb5ee8SHong Zhang 7259aaf355SLisandro Dalcin #define PetscStringizeArg(a) #a 7359aaf355SLisandro Dalcin #define PetscStringize(a) PetscStringizeArg(a) 74330cf3c9SBarry Smith 75e8b7e333SSatish Balay #if defined(PETSC_USE_ERRORCHECKING) 76e8b7e333SSatish Balay 7730de9b25SBarry Smith /*MC 781957e957SBarry Smith SETERRQ - Macro to be called when an error has been detected, 7930de9b25SBarry Smith 8030de9b25SBarry Smith Synopsis: 81aaa7dc30SBarry Smith #include <petscsys.h> 82e7e72b3dSBarry Smith PetscErrorCode SETERRQ(MPI_Comm comm,PetscErrorCode errorcode,char *message) 8330de9b25SBarry Smith 84eca87e8dSBarry Smith Not Collective 8530de9b25SBarry Smith 8630de9b25SBarry Smith Input Parameters: 87fa190f98SMatthew G. Knepley + comm - A communicator, so that the error can be collective 88fa190f98SMatthew G. Knepley . errorcode - nonzero error code, see the list of standard error codes in include/petscerror.h 8930de9b25SBarry Smith - message - error message 9030de9b25SBarry Smith 9130de9b25SBarry Smith Level: beginner 9230de9b25SBarry Smith 9330de9b25SBarry Smith Notes: 9430de9b25SBarry Smith Once the error handler is called the calling function is then returned from with the given error code. 9530de9b25SBarry Smith 9630de9b25SBarry Smith See SETERRQ1(), SETERRQ2(), SETERRQ3() for versions that take arguments 9730de9b25SBarry Smith 9858ebbce7SBarry Smith In Fortran MPI_Abort() is always called 9930de9b25SBarry Smith 10030de9b25SBarry Smith Experienced users can set the error handler with PetscPushErrorHandler(). 10130de9b25SBarry Smith 10230de9b25SBarry Smith Concepts: error^setting condition 10330de9b25SBarry Smith 10491d3bdf4SKris Buschelman .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), CHKERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2(), SETERRQ3() 10530de9b25SBarry Smith M*/ 106efca3c55SSatish Balay #define SETERRQ(comm,n,s) return PetscError(comm,__LINE__,PETSC_FUNCTION_NAME,__FILE__,n,PETSC_ERROR_INITIAL,s) 10730de9b25SBarry Smith 10830de9b25SBarry Smith /*MC 10930de9b25SBarry Smith SETERRQ1 - Macro that is called when an error has been detected, 11030de9b25SBarry Smith 11130de9b25SBarry Smith Synopsis: 112aaa7dc30SBarry Smith #include <petscsys.h> 113e32f2f54SBarry Smith PetscErrorCode SETERRQ1(MPI_Comm comm,PetscErrorCode errorcode,char *formatmessage,arg) 11430de9b25SBarry Smith 115eca87e8dSBarry Smith Not Collective 11630de9b25SBarry Smith 11730de9b25SBarry Smith Input Parameters: 118fa190f98SMatthew G. Knepley + comm - A communicator, so that the error can be collective 119fa190f98SMatthew G. Knepley . errorcode - nonzero error code, see the list of standard error codes in include/petscerror.h 12030de9b25SBarry Smith . message - error message in the printf format 12130de9b25SBarry Smith - arg - argument (for example an integer, string or double) 12230de9b25SBarry Smith 12330de9b25SBarry Smith Level: beginner 12430de9b25SBarry Smith 12530de9b25SBarry Smith Notes: 12630de9b25SBarry Smith Once the error handler is called the calling function is then returned from with the given error code. 12730de9b25SBarry Smith 12830de9b25SBarry Smith Experienced users can set the error handler with PetscPushErrorHandler(). 12930de9b25SBarry Smith 13030de9b25SBarry Smith Concepts: error^setting condition 13130de9b25SBarry Smith 13291d3bdf4SKris Buschelman .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), CHKERRQ(), CHKMEMQ, SETERRQ(), SETERRQ2(), SETERRQ3() 13330de9b25SBarry Smith M*/ 134efca3c55SSatish Balay #define SETERRQ1(comm,n,s,a1) return PetscError(comm,__LINE__,PETSC_FUNCTION_NAME,__FILE__,n,PETSC_ERROR_INITIAL,s,a1) 13530de9b25SBarry Smith 13630de9b25SBarry Smith /*MC 13730de9b25SBarry Smith SETERRQ2 - Macro that is called when an error has been detected, 13830de9b25SBarry Smith 13930de9b25SBarry Smith Synopsis: 140aaa7dc30SBarry Smith #include <petscsys.h> 141fa190f98SMatthew G. Knepley PetscErrorCode SETERRQ2(MPI_Comm comm,PetscErrorCode errorcode,char *formatmessage,arg1,arg2) 14230de9b25SBarry Smith 143eca87e8dSBarry Smith Not Collective 14430de9b25SBarry Smith 14530de9b25SBarry Smith Input Parameters: 146fa190f98SMatthew G. Knepley + comm - A communicator, so that the error can be collective 147fa190f98SMatthew G. Knepley . errorcode - nonzero error code, see the list of standard error codes in include/petscerror.h 14830de9b25SBarry Smith . message - error message in the printf format 14930de9b25SBarry Smith . arg1 - argument (for example an integer, string or double) 15030de9b25SBarry Smith - arg2 - argument (for example an integer, string or double) 15130de9b25SBarry Smith 15230de9b25SBarry Smith Level: beginner 15330de9b25SBarry Smith 15430de9b25SBarry Smith Notes: 15530de9b25SBarry Smith Once the error handler is called the calling function is then returned from with the given error code. 15630de9b25SBarry Smith 15730de9b25SBarry Smith Experienced users can set the error handler with PetscPushErrorHandler(). 15830de9b25SBarry Smith 15930de9b25SBarry Smith Concepts: error^setting condition 16030de9b25SBarry Smith 1616024bd2cSBarry Smith .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), CHKERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ3() 16230de9b25SBarry Smith M*/ 163efca3c55SSatish Balay #define SETERRQ2(comm,n,s,a1,a2) return PetscError(comm,__LINE__,PETSC_FUNCTION_NAME,__FILE__,n,PETSC_ERROR_INITIAL,s,a1,a2) 16430de9b25SBarry Smith 16530de9b25SBarry Smith /*MC 16630de9b25SBarry Smith SETERRQ3 - Macro that is called when an error has been detected, 16730de9b25SBarry Smith 16830de9b25SBarry Smith Synopsis: 169aaa7dc30SBarry Smith #include <petscsys.h> 170fa190f98SMatthew G. Knepley PetscErrorCode SETERRQ3(MPI_Comm comm,PetscErrorCode errorcode,char *formatmessage,arg1,arg2,arg3) 17130de9b25SBarry Smith 172eca87e8dSBarry Smith Not Collective 17330de9b25SBarry Smith 17430de9b25SBarry Smith Input Parameters: 175fa190f98SMatthew G. Knepley + comm - A communicator, so that the error can be collective 176fa190f98SMatthew G. Knepley . errorcode - nonzero error code, see the list of standard error codes in include/petscerror.h 17730de9b25SBarry Smith . message - error message in the printf format 17830de9b25SBarry Smith . arg1 - argument (for example an integer, string or double) 17930de9b25SBarry Smith . arg2 - argument (for example an integer, string or double) 18030de9b25SBarry Smith - arg3 - argument (for example an integer, string or double) 18130de9b25SBarry Smith 18230de9b25SBarry Smith Level: beginner 18330de9b25SBarry Smith 18430de9b25SBarry Smith Notes: 18530de9b25SBarry Smith Once the error handler is called the calling function is then returned from with the given error code. 18630de9b25SBarry Smith 187f621e05eSBarry Smith There are also versions for 4, 5, 6 and 7 arguments. 188f621e05eSBarry Smith 18930de9b25SBarry Smith Experienced users can set the error handler with PetscPushErrorHandler(). 19030de9b25SBarry Smith 19130de9b25SBarry Smith Concepts: error^setting condition 19230de9b25SBarry Smith 1936024bd2cSBarry Smith .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), CHKERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2() 19430de9b25SBarry Smith M*/ 195efca3c55SSatish Balay #define SETERRQ3(comm,n,s,a1,a2,a3) return PetscError(comm,__LINE__,PETSC_FUNCTION_NAME,__FILE__,n,PETSC_ERROR_INITIAL,s,a1,a2,a3) 19630de9b25SBarry Smith 197fa190f98SMatthew G. Knepley /*MC 198fa190f98SMatthew G. Knepley SETERRQ4 - Macro that is called when an error has been detected, 199fa190f98SMatthew G. Knepley 200fa190f98SMatthew G. Knepley Synopsis: 201fa190f98SMatthew G. Knepley #include <petscsys.h> 202fa190f98SMatthew G. Knepley PetscErrorCode SETERRQ4(MPI_Comm comm,PetscErrorCode errorcode,char *formatmessage,arg1,arg2,arg3) 203fa190f98SMatthew G. Knepley 204fa190f98SMatthew G. Knepley Not Collective 205fa190f98SMatthew G. Knepley 206fa190f98SMatthew G. Knepley Input Parameters: 207fa190f98SMatthew G. Knepley + comm - A communicator, so that the error can be collective 208fa190f98SMatthew G. Knepley . errorcode - nonzero error code, see the list of standard error codes in include/petscerror.h 209fa190f98SMatthew G. Knepley . message - error message in the printf format 210fa190f98SMatthew G. Knepley . arg1 - argument (for example an integer, string or double) 211fa190f98SMatthew G. Knepley . arg2 - argument (for example an integer, string or double) 212fa190f98SMatthew G. Knepley . arg3 - argument (for example an integer, string or double) 213fa190f98SMatthew G. Knepley - arg4 - argument (for example an integer, string or double) 214fa190f98SMatthew G. Knepley 215fa190f98SMatthew G. Knepley Level: beginner 216fa190f98SMatthew G. Knepley 217fa190f98SMatthew G. Knepley Notes: 218fa190f98SMatthew G. Knepley Once the error handler is called the calling function is then returned from with the given error code. 219fa190f98SMatthew G. Knepley 220fa190f98SMatthew G. Knepley There are also versions for 4, 5, 6 and 7 arguments. 221fa190f98SMatthew G. Knepley 222fa190f98SMatthew G. Knepley Experienced users can set the error handler with PetscPushErrorHandler(). 223fa190f98SMatthew G. Knepley 224fa190f98SMatthew G. Knepley Concepts: error^setting condition 225fa190f98SMatthew G. Knepley 226fa190f98SMatthew G. Knepley .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), CHKERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2() 227fa190f98SMatthew G. Knepley M*/ 228efca3c55SSatish Balay #define SETERRQ4(comm,n,s,a1,a2,a3,a4) return PetscError(comm,__LINE__,PETSC_FUNCTION_NAME,__FILE__,n,PETSC_ERROR_INITIAL,s,a1,a2,a3,a4) 229fa190f98SMatthew G. Knepley 230fa190f98SMatthew G. Knepley /*MC 231fa190f98SMatthew G. Knepley SETERRQ5 - Macro that is called when an error has been detected, 232fa190f98SMatthew G. Knepley 233fa190f98SMatthew G. Knepley Synopsis: 234fa190f98SMatthew G. Knepley #include <petscsys.h> 235fa190f98SMatthew G. Knepley PetscErrorCode SETERRQ5(MPI_Comm comm,PetscErrorCode errorcode,char *formatmessage,arg1,arg2,arg3) 236fa190f98SMatthew G. Knepley 237fa190f98SMatthew G. Knepley Not Collective 238fa190f98SMatthew G. Knepley 239fa190f98SMatthew G. Knepley Input Parameters: 240fa190f98SMatthew G. Knepley + comm - A communicator, so that the error can be collective 241fa190f98SMatthew G. Knepley . errorcode - nonzero error code, see the list of standard error codes in include/petscerror.h 242fa190f98SMatthew G. Knepley . message - error message in the printf format 243fa190f98SMatthew G. Knepley . arg1 - argument (for example an integer, string or double) 244fa190f98SMatthew G. Knepley . arg2 - argument (for example an integer, string or double) 245fa190f98SMatthew G. Knepley . arg3 - argument (for example an integer, string or double) 246fa190f98SMatthew G. Knepley . arg4 - argument (for example an integer, string or double) 247fa190f98SMatthew G. Knepley - arg5 - argument (for example an integer, string or double) 248fa190f98SMatthew G. Knepley 249fa190f98SMatthew G. Knepley Level: beginner 250fa190f98SMatthew G. Knepley 251fa190f98SMatthew G. Knepley Notes: 252fa190f98SMatthew G. Knepley Once the error handler is called the calling function is then returned from with the given error code. 253fa190f98SMatthew G. Knepley 254fa190f98SMatthew G. Knepley There are also versions for 4, 5, 6 and 7 arguments. 255fa190f98SMatthew G. Knepley 256fa190f98SMatthew G. Knepley Experienced users can set the error handler with PetscPushErrorHandler(). 257fa190f98SMatthew G. Knepley 258fa190f98SMatthew G. Knepley Concepts: error^setting condition 259fa190f98SMatthew G. Knepley 260fa190f98SMatthew G. Knepley .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), CHKERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2() 261fa190f98SMatthew G. Knepley M*/ 262efca3c55SSatish Balay #define SETERRQ5(comm,n,s,a1,a2,a3,a4,a5) return PetscError(comm,__LINE__,PETSC_FUNCTION_NAME,__FILE__,n,PETSC_ERROR_INITIAL,s,a1,a2,a3,a4,a5) 263fa190f98SMatthew G. Knepley 264fa190f98SMatthew G. Knepley /*MC 265fa190f98SMatthew G. Knepley SETERRQ6 - Macro that is called when an error has been detected, 266fa190f98SMatthew G. Knepley 267fa190f98SMatthew G. Knepley Synopsis: 268fa190f98SMatthew G. Knepley #include <petscsys.h> 269fa190f98SMatthew G. Knepley PetscErrorCode SETERRQ6(MPI_Comm comm,PetscErrorCode errorcode,char *formatmessage,arg1,arg2,arg3) 270fa190f98SMatthew G. Knepley 271fa190f98SMatthew G. Knepley Not Collective 272fa190f98SMatthew G. Knepley 273fa190f98SMatthew G. Knepley Input Parameters: 274fa190f98SMatthew G. Knepley + comm - A communicator, so that the error can be collective 275fa190f98SMatthew G. Knepley . errorcode - nonzero error code, see the list of standard error codes in include/petscerror.h 276fa190f98SMatthew G. Knepley . message - error message in the printf format 277fa190f98SMatthew G. Knepley . arg1 - argument (for example an integer, string or double) 278fa190f98SMatthew G. Knepley . arg2 - argument (for example an integer, string or double) 279fa190f98SMatthew G. Knepley . arg3 - argument (for example an integer, string or double) 280fa190f98SMatthew G. Knepley . arg4 - argument (for example an integer, string or double) 281fa190f98SMatthew G. Knepley . arg5 - argument (for example an integer, string or double) 282fa190f98SMatthew G. Knepley - arg6 - argument (for example an integer, string or double) 283fa190f98SMatthew G. Knepley 284fa190f98SMatthew G. Knepley Level: beginner 285fa190f98SMatthew G. Knepley 286fa190f98SMatthew G. Knepley Notes: 287fa190f98SMatthew G. Knepley Once the error handler is called the calling function is then returned from with the given error code. 288fa190f98SMatthew G. Knepley 289fa190f98SMatthew G. Knepley There are also versions for 4, 5, 6 and 7 arguments. 290fa190f98SMatthew G. Knepley 291fa190f98SMatthew G. Knepley Experienced users can set the error handler with PetscPushErrorHandler(). 292fa190f98SMatthew G. Knepley 293fa190f98SMatthew G. Knepley Concepts: error^setting condition 294fa190f98SMatthew G. Knepley 295fa190f98SMatthew G. Knepley .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), CHKERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2() 296fa190f98SMatthew G. Knepley M*/ 297efca3c55SSatish Balay #define SETERRQ6(comm,n,s,a1,a2,a3,a4,a5,a6) return PetscError(comm,__LINE__,PETSC_FUNCTION_NAME,__FILE__,n,PETSC_ERROR_INITIAL,s,a1,a2,a3,a4,a5,a6) 298fa190f98SMatthew G. Knepley 299fa190f98SMatthew G. Knepley /*MC 300fa190f98SMatthew G. Knepley SETERRQ7 - Macro that is called when an error has been detected, 301fa190f98SMatthew G. Knepley 302fa190f98SMatthew G. Knepley Synopsis: 303fa190f98SMatthew G. Knepley #include <petscsys.h> 304fa190f98SMatthew G. Knepley PetscErrorCode SETERRQ7(MPI_Comm comm,PetscErrorCode errorcode,char *formatmessage,arg1,arg2,arg3) 305fa190f98SMatthew G. Knepley 306fa190f98SMatthew G. Knepley Not Collective 307fa190f98SMatthew G. Knepley 308fa190f98SMatthew G. Knepley Input Parameters: 309fa190f98SMatthew G. Knepley + comm - A communicator, so that the error can be collective 310fa190f98SMatthew G. Knepley . errorcode - nonzero error code, see the list of standard error codes in include/petscerror.h 311fa190f98SMatthew G. Knepley . message - error message in the printf format 312fa190f98SMatthew G. Knepley . arg1 - argument (for example an integer, string or double) 313fa190f98SMatthew G. Knepley . arg2 - argument (for example an integer, string or double) 314fa190f98SMatthew G. Knepley . arg3 - argument (for example an integer, string or double) 315fa190f98SMatthew G. Knepley . arg4 - argument (for example an integer, string or double) 316fa190f98SMatthew G. Knepley . arg5 - argument (for example an integer, string or double) 317fa190f98SMatthew G. Knepley . arg6 - argument (for example an integer, string or double) 318fa190f98SMatthew G. Knepley - arg7 - argument (for example an integer, string or double) 319fa190f98SMatthew G. Knepley 320fa190f98SMatthew G. Knepley Level: beginner 321fa190f98SMatthew G. Knepley 322fa190f98SMatthew G. Knepley Notes: 323fa190f98SMatthew G. Knepley Once the error handler is called the calling function is then returned from with the given error code. 324fa190f98SMatthew G. Knepley 325fa190f98SMatthew G. Knepley There are also versions for 4, 5, 6 and 7 arguments. 326fa190f98SMatthew G. Knepley 327fa190f98SMatthew G. Knepley Experienced users can set the error handler with PetscPushErrorHandler(). 328fa190f98SMatthew G. Knepley 329fa190f98SMatthew G. Knepley Concepts: error^setting condition 330fa190f98SMatthew G. Knepley 331fa190f98SMatthew G. Knepley .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), CHKERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2() 332fa190f98SMatthew G. Knepley M*/ 333efca3c55SSatish Balay #define SETERRQ7(comm,n,s,a1,a2,a3,a4,a5,a6,a7) return PetscError(comm,__LINE__,PETSC_FUNCTION_NAME,__FILE__,n,PETSC_ERROR_INITIAL,s,a1,a2,a3,a4,a5,a6,a7) 334fa190f98SMatthew G. Knepley 335fa190f98SMatthew G. Knepley /*MC 336fa190f98SMatthew G. Knepley SETERRQ8 - Macro that is called when an error has been detected, 337fa190f98SMatthew G. Knepley 338fa190f98SMatthew G. Knepley Synopsis: 339fa190f98SMatthew G. Knepley #include <petscsys.h> 340fa190f98SMatthew G. Knepley PetscErrorCode SETERRQ8(MPI_Comm comm,PetscErrorCode errorcode,char *formatmessage,arg1,arg2,arg3) 341fa190f98SMatthew G. Knepley 342fa190f98SMatthew G. Knepley Not Collective 343fa190f98SMatthew G. Knepley 344fa190f98SMatthew G. Knepley Input Parameters: 345fa190f98SMatthew G. Knepley + comm - A communicator, so that the error can be collective 346fa190f98SMatthew G. Knepley . errorcode - nonzero error code, see the list of standard error codes in include/petscerror.h 347fa190f98SMatthew G. Knepley . message - error message in the printf format 348fa190f98SMatthew G. Knepley . arg1 - argument (for example an integer, string or double) 349fa190f98SMatthew G. Knepley . arg2 - argument (for example an integer, string or double) 350fa190f98SMatthew G. Knepley . arg3 - argument (for example an integer, string or double) 351fa190f98SMatthew G. Knepley . arg4 - argument (for example an integer, string or double) 352fa190f98SMatthew G. Knepley . arg5 - argument (for example an integer, string or double) 353fa190f98SMatthew G. Knepley . arg6 - argument (for example an integer, string or double) 354fa190f98SMatthew G. Knepley . arg7 - argument (for example an integer, string or double) 355fa190f98SMatthew G. Knepley - arg8 - argument (for example an integer, string or double) 356fa190f98SMatthew G. Knepley 357fa190f98SMatthew G. Knepley Level: beginner 358fa190f98SMatthew G. Knepley 359fa190f98SMatthew G. Knepley Notes: 360fa190f98SMatthew G. Knepley Once the error handler is called the calling function is then returned from with the given error code. 361fa190f98SMatthew G. Knepley 362fa190f98SMatthew G. Knepley There are also versions for 4, 5, 6 and 7 arguments. 363fa190f98SMatthew G. Knepley 364fa190f98SMatthew G. Knepley Experienced users can set the error handler with PetscPushErrorHandler(). 365fa190f98SMatthew G. Knepley 366fa190f98SMatthew G. Knepley Concepts: error^setting condition 367fa190f98SMatthew G. Knepley 368fa190f98SMatthew G. Knepley .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), CHKERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2() 369fa190f98SMatthew G. Knepley M*/ 370efca3c55SSatish Balay #define SETERRQ8(comm,n,s,a1,a2,a3,a4,a5,a6,a7,a8) return PetscError(comm,__LINE__,PETSC_FUNCTION_NAME,__FILE__,n,PETSC_ERROR_INITIAL,s,a1,a2,a3,a4,a5,a6,a7,a8) 371fa190f98SMatthew G. Knepley 372fa190f98SMatthew G. Knepley /*MC 373fa190f98SMatthew G. Knepley SETERRABORT - Macro that can be called when an error has been detected, 374fa190f98SMatthew G. Knepley 375fa190f98SMatthew G. Knepley Synopsis: 376fa190f98SMatthew G. Knepley #include <petscsys.h> 377fa190f98SMatthew G. Knepley PetscErrorCode SETERRABORT(MPI_Comm comm,PetscErrorCode errorcode,char *message) 378fa190f98SMatthew G. Knepley 379fa190f98SMatthew G. Knepley Not Collective 380fa190f98SMatthew G. Knepley 381fa190f98SMatthew G. Knepley Input Parameters: 382fa190f98SMatthew G. Knepley + comm - A communicator, so that the error can be collective 383fa190f98SMatthew G. Knepley . errorcode - nonzero error code, see the list of standard error codes in include/petscerror.h 384fa190f98SMatthew G. Knepley - message - error message in the printf format 385fa190f98SMatthew G. Knepley 386fa190f98SMatthew G. Knepley Level: beginner 387fa190f98SMatthew G. Knepley 388fa190f98SMatthew G. Knepley Notes: 389fa190f98SMatthew G. Knepley This function just calls MPI_Abort(). 390fa190f98SMatthew G. Knepley 391fa190f98SMatthew G. Knepley Concepts: error^setting condition 392fa190f98SMatthew G. Knepley 393fa190f98SMatthew G. Knepley .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), CHKERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2() 394fa190f98SMatthew G. Knepley M*/ 395efca3c55SSatish Balay #define SETERRABORT(comm,n,s) do {PetscError(comm,__LINE__,PETSC_FUNCTION_NAME,__FILE__,n,PETSC_ERROR_INITIAL,s);MPI_Abort(comm,n);} while (0) 3969a00fa46SSatish Balay 39730de9b25SBarry Smith /*MC 39830de9b25SBarry Smith CHKERRQ - Checks error code, if non-zero it calls the error handler and then returns 39930de9b25SBarry Smith 40030de9b25SBarry Smith Synopsis: 401aaa7dc30SBarry Smith #include <petscsys.h> 402f4442326SMatthew Knepley PetscErrorCode CHKERRQ(PetscErrorCode errorcode) 40330de9b25SBarry Smith 404eca87e8dSBarry Smith Not Collective 40530de9b25SBarry Smith 40630de9b25SBarry Smith Input Parameters: 40730de9b25SBarry Smith . errorcode - nonzero error code, see the list of standard error codes in include/petscerror.h 40830de9b25SBarry Smith 40930de9b25SBarry Smith Level: beginner 41030de9b25SBarry Smith 41130de9b25SBarry Smith Notes: 41230de9b25SBarry Smith Once the error handler is called the calling function is then returned from with the given error code. 41330de9b25SBarry Smith 41430de9b25SBarry Smith Experienced users can set the error handler with PetscPushErrorHandler(). 4155324ea47SKris Buschelman 416fcecf507SKris Buschelman CHKERRQ(n) is fundamentally a macro replacement for 4175324ea47SKris Buschelman if (n) return(PetscError(...,n,...)); 4185324ea47SKris Buschelman 4195324ea47SKris Buschelman Although typical usage resembles "void CHKERRQ(PetscErrorCode)" as described above, for certain uses it is 4205324ea47SKris Buschelman highly inappropriate to use it in this manner as it invokes return(PetscErrorCode). In particular, 4215324ea47SKris Buschelman it cannot be used in functions which return(void) or any other datatype. In these types of functions, 42258ebbce7SBarry Smith you can use CHKERRV() which returns without an error code (bad idea since the error is ignored or 4235324ea47SKris Buschelman if (n) {PetscError(....); return(YourReturnType);} 4240298fd71SBarry Smith where you may pass back a NULL to indicate an error. You can also call CHKERRABORT(comm,n) to have 42558ebbce7SBarry Smith MPI_Abort() returned immediately. 42658ebbce7SBarry Smith 42758ebbce7SBarry Smith In Fortran MPI_Abort() is always called 42830de9b25SBarry Smith 42930de9b25SBarry Smith Concepts: error^setting condition 43030de9b25SBarry Smith 43191d3bdf4SKris Buschelman .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), SETERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2(), SETERRQ2() 43230de9b25SBarry Smith M*/ 433efca3c55SSatish Balay #define CHKERRQ(n) do {if (PetscUnlikely(n)) return PetscError(PETSC_COMM_SELF,__LINE__,PETSC_FUNCTION_NAME,__FILE__,n,PETSC_ERROR_REPEAT," ");} while (0) 43430de9b25SBarry Smith 435efca3c55SSatish Balay #define CHKERRV(n) do {if (PetscUnlikely(n)) {n = PetscError(PETSC_COMM_SELF,__LINE__,PETSC_FUNCTION_NAME,__FILE__,n,PETSC_ERROR_REPEAT," ");return;}} while(0) 436efca3c55SSatish Balay #define CHKERRABORT(comm,n) do {if (PetscUnlikely(n)) {PetscError(PETSC_COMM_SELF,__LINE__,PETSC_FUNCTION_NAME,__FILE__,n,PETSC_ERROR_REPEAT," ");MPI_Abort(comm,n);}} while (0) 437efca3c55SSatish Balay #define CHKERRCONTINUE(n) do {if (PetscUnlikely(n)) {PetscError(PETSC_COMM_SELF,__LINE__,PETSC_FUNCTION_NAME,__FILE__,n,PETSC_ERROR_REPEAT," ");}} while (0) 43885614651SBarry Smith 439fd705b32SMatthew Knepley #ifdef PETSC_CLANGUAGE_CXX 440fd705b32SMatthew Knepley 441cc26af49SMatthew Knepley /*MC 442cc26af49SMatthew Knepley CHKERRXX - Checks error code, if non-zero it calls the C++ error handler which throws an exception 443cc26af49SMatthew Knepley 444cc26af49SMatthew Knepley Synopsis: 445aaa7dc30SBarry Smith #include <petscsys.h> 446cc26af49SMatthew Knepley void CHKERRXX(PetscErrorCode errorcode) 447cc26af49SMatthew Knepley 448eca87e8dSBarry Smith Not Collective 449cc26af49SMatthew Knepley 450cc26af49SMatthew Knepley Input Parameters: 451cc26af49SMatthew Knepley . errorcode - nonzero error code, see the list of standard error codes in include/petscerror.h 452cc26af49SMatthew Knepley 453cc26af49SMatthew Knepley Level: beginner 454cc26af49SMatthew Knepley 455cc26af49SMatthew Knepley Notes: 456cc26af49SMatthew Knepley Once the error handler throws a ??? exception. 457cc26af49SMatthew Knepley 458cc26af49SMatthew Knepley You can use CHKERRV() which returns without an error code (bad idea since the error is ignored) 459cc26af49SMatthew Knepley or CHKERRABORT(comm,n) to have MPI_Abort() returned immediately. 460cc26af49SMatthew Knepley 461cc26af49SMatthew Knepley Concepts: error^setting condition 462cc26af49SMatthew Knepley 463cc26af49SMatthew Knepley .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), SETERRQ(), CHKERRQ(), CHKMEMQ 464cc26af49SMatthew Knepley M*/ 465efca3c55SSatish Balay #define CHKERRXX(n) do {if (PetscUnlikely(n)) {PetscError(PETSC_COMM_SELF,__LINE__,PETSC_FUNCTION_NAME,__FILE__,n,PETSC_ERROR_IN_CXX,0);}} while(0) 466fd705b32SMatthew Knepley 467fd705b32SMatthew Knepley #endif 468fd705b32SMatthew Knepley 4695be1650bSAlejandro Lamas Daviña #define CHKERRCUDA(err) do {if (PetscUnlikely(err)) SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_LIB,"CUDA error %d",err);} while(0) 4705be1650bSAlejandro Lamas Daviña #define CHKERRCUBLAS(err) do {if (PetscUnlikely(err)) SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_LIB,"CUBLAS error %d",err);} while(0) 47182f73ecaSAlejandro Lamas Daviña 47230de9b25SBarry Smith /*MC 47330de9b25SBarry Smith CHKMEMQ - Checks the memory for corruption, calls error handler if any is detected 47430de9b25SBarry Smith 47530de9b25SBarry Smith Synopsis: 476aaa7dc30SBarry Smith #include <petscsys.h> 47791d3bdf4SKris Buschelman CHKMEMQ; 47830de9b25SBarry Smith 479eca87e8dSBarry Smith Not Collective 480eca87e8dSBarry Smith 48130de9b25SBarry Smith Level: beginner 48230de9b25SBarry Smith 48330de9b25SBarry Smith Notes: 4841957e957SBarry Smith We highly recommend using valgrind http://www.mcs.anl.gov/petsc/documentation/faq.html#valgrind for finding memory problems. This is useful 4851957e957SBarry Smith on systems that do not have valgrind, but much much less useful. 4861957e957SBarry Smith 487ff002950SBarry Smith Must run with the option -malloc_debug to enable this option 48830de9b25SBarry Smith 48930de9b25SBarry Smith Once the error handler is called the calling function is then returned from with the given error code. 49030de9b25SBarry Smith 49130de9b25SBarry Smith By defaults prints location where memory that is corrupted was allocated. 49230de9b25SBarry Smith 493f621e05eSBarry Smith Use CHKMEMA for functions that return void 494f621e05eSBarry Smith 49530de9b25SBarry Smith Concepts: memory corruption 49630de9b25SBarry Smith 4976024bd2cSBarry Smith .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), SETERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2(), SETERRQ3(), 498ff002950SBarry Smith PetscMallocValidate() 49930de9b25SBarry Smith M*/ 500efca3c55SSatish Balay #define CHKMEMQ do {PetscErrorCode _7_ierr = PetscMallocValidate(__LINE__,PETSC_FUNCTION_NAME,__FILE__);CHKERRQ(_7_ierr);} while(0) 50185614651SBarry Smith 502efca3c55SSatish Balay #define CHKMEMA PetscMallocValidate(__LINE__,PETSC_FUNCTION_NAME,__FILE__) 503e68848bdSBarry Smith 504f8e50935SSatish Balay #else /* PETSC_USE_ERRORCHECKING */ 505f621e05eSBarry Smith 506f621e05eSBarry Smith /* 507e2e64c6bSBarry Smith These are defined to be empty for when error checking is turned off, with ./configure --with-errorchecking=0 508f621e05eSBarry Smith */ 509f621e05eSBarry Smith 5104b209cf6SBarry Smith #define SETERRQ(c,n,s) 5114b209cf6SBarry Smith #define SETERRQ1(c,n,s,a1) 5124b209cf6SBarry Smith #define SETERRQ2(c,n,s,a1,a2) 5134b209cf6SBarry Smith #define SETERRQ3(c,n,s,a1,a2,a3) 5144b209cf6SBarry Smith #define SETERRQ4(c,n,s,a1,a2,a3,a4) 5154b209cf6SBarry Smith #define SETERRQ5(c,n,s,a1,a2,a3,a4,a5) 5164b209cf6SBarry Smith #define SETERRQ6(c,n,s,a1,a2,a3,a4,a5,a6) 5174ef524e9SStefano Zampini #define SETERRQ7(c,n,s,a1,a2,a3,a4,a5,a6,a7) 5184ef524e9SStefano Zampini #define SETERRQ8(c,n,s,a1,a2,a3,a4,a5,a6,a7,a8) 5194b209cf6SBarry Smith #define SETERRABORT(comm,n,s) 52085614651SBarry Smith 5214f227f7cSBarry Smith #define CHKERRQ(n) ; 52271241078SStefano Zampini #define CHKERRV(n) ; 5231ee4faa0SMatthew Knepley #define CHKERRABORT(comm,n) ; 5241ee4faa0SMatthew Knepley #define CHKERRCONTINUE(n) ; 52585614651SBarry Smith #define CHKMEMQ ; 52682f73ecaSAlejandro Lamas Daviña #define CHKERRCUDA(err) ; 52782f73ecaSAlejandro Lamas Daviña #define CHKERRCUBLAS(err) ; 52885614651SBarry Smith 5298cabf42eSMatthew G Knepley #ifdef PETSC_CLANGUAGE_CXX 5308cabf42eSMatthew G Knepley #define CHKERRXX(n) ; 5318cabf42eSMatthew G Knepley #endif 5328cabf42eSMatthew G Knepley 533f8e50935SSatish Balay #endif /* PETSC_USE_ERRORCHECKING */ 53454a8ef01SBarry Smith 535668f157eSBarry Smith /*E 536668f157eSBarry Smith PetscErrorType - passed to the PETSc error handling routines indicating if this is the first or a later call to the error handlers 537668f157eSBarry Smith 538668f157eSBarry Smith Level: advanced 539668f157eSBarry Smith 540d736bfebSBarry Smith PETSC_ERROR_IN_CXX indicates the error was detected in C++ and an exception should be generated 541d736bfebSBarry Smith 54261b0d812SBarry Smith Developer Notes: This is currently used to decide when to print the detailed information about the run in PetscTraceBackErrorHandler() 543668f157eSBarry Smith 544d736bfebSBarry Smith .seealso: PetscError(), SETERRXX() 545668f157eSBarry Smith E*/ 546d736bfebSBarry Smith typedef enum {PETSC_ERROR_INITIAL=0,PETSC_ERROR_REPEAT=1,PETSC_ERROR_IN_CXX = 2} PetscErrorType; 5474b209cf6SBarry Smith 548eb9e708aSLisandro Dalcin #if defined(__clang_analyzer__) 549eb9e708aSLisandro Dalcin __attribute__((analyzer_noreturn)) 550eb9e708aSLisandro Dalcin #endif 551eb9e708aSLisandro Dalcin PETSC_EXTERN PetscErrorCode PetscError(MPI_Comm,int,const char*,const char*,PetscErrorCode,PetscErrorType,const char*,...); 552eb9e708aSLisandro Dalcin 553014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscErrorPrintfInitialize(void); 554014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscErrorMessage(int,const char*[],char **); 555efca3c55SSatish Balay PETSC_EXTERN PetscErrorCode PetscTraceBackErrorHandler(MPI_Comm,int,const char*,const char*,PetscErrorCode,PetscErrorType,const char*,void*); 556efca3c55SSatish Balay PETSC_EXTERN PetscErrorCode PetscIgnoreErrorHandler(MPI_Comm,int,const char*,const char*,PetscErrorCode,PetscErrorType,const char*,void*); 557efca3c55SSatish Balay PETSC_EXTERN PetscErrorCode PetscEmacsClientErrorHandler(MPI_Comm,int,const char*,const char*,PetscErrorCode,PetscErrorType,const char*,void*); 558efca3c55SSatish Balay PETSC_EXTERN PetscErrorCode PetscMPIAbortErrorHandler(MPI_Comm,int,const char*,const char*,PetscErrorCode,PetscErrorType,const char*,void*); 559efca3c55SSatish Balay PETSC_EXTERN PetscErrorCode PetscAbortErrorHandler(MPI_Comm,int,const char*,const char*,PetscErrorCode,PetscErrorType,const char*,void*); 560efca3c55SSatish Balay PETSC_EXTERN PetscErrorCode PetscAttachDebuggerErrorHandler(MPI_Comm,int,const char*,const char*,PetscErrorCode,PetscErrorType,const char*,void*); 561efca3c55SSatish Balay PETSC_EXTERN PetscErrorCode PetscReturnErrorHandler(MPI_Comm,int,const char*,const char*,PetscErrorCode,PetscErrorType,const char*,void*); 562efca3c55SSatish Balay PETSC_EXTERN PetscErrorCode PetscPushErrorHandler(PetscErrorCode (*handler)(MPI_Comm,int,const char*,const char*,PetscErrorCode,PetscErrorType,const char*,void*),void*); 563014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscPopErrorHandler(void); 5648d359177SBarry Smith PETSC_EXTERN PetscErrorCode PetscSignalHandlerDefault(int,void*); 565014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscPushSignalHandler(PetscErrorCode (*)(int,void *),void*); 566014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscPopSignalHandler(void); 56728559dc8SJed Brown PETSC_EXTERN PetscErrorCode PetscCheckPointerSetIntensity(PetscInt); 568329f5518SBarry Smith 569639ff905SBarry Smith /*MC 570639ff905SBarry Smith PetscErrorPrintf - Prints error messages. 571639ff905SBarry Smith 572639ff905SBarry Smith Synopsis: 573aaa7dc30SBarry Smith #include <petscsys.h> 574639ff905SBarry Smith PetscErrorCode (*PetscErrorPrintf)(const char format[],...); 575639ff905SBarry Smith 576639ff905SBarry Smith Not Collective 577639ff905SBarry Smith 578639ff905SBarry Smith Input Parameters: 579639ff905SBarry Smith . format - the usual printf() format string 580639ff905SBarry Smith 581639ff905SBarry Smith Options Database Keys: 5821957e957SBarry Smith + -error_output_stdout - cause error messages to be printed to stdout instead of the (default) stderr 583e1bc860dSBarry Smith - -error_output_none - to turn off all printing of error messages (does not change the way the error is handled.) 584639ff905SBarry Smith 585639ff905SBarry Smith Notes: Use 586639ff905SBarry Smith $ PetscErrorPrintf = PetscErrorPrintfNone; to turn off all printing of error messages (does not change the way the 587639ff905SBarry Smith $ error is handled.) and 5881957e957SBarry Smith $ PetscErrorPrintf = PetscErrorPrintfDefault; to turn it back on or you can use your own function 589639ff905SBarry Smith 590639ff905SBarry Smith Use 591639ff905SBarry Smith PETSC_STDERR = FILE* obtained from a file open etc. to have stderr printed to the file. 592639ff905SBarry Smith PETSC_STDOUT = FILE* obtained from a file open etc. to have stdout printed to the file. 593639ff905SBarry Smith 594639ff905SBarry Smith Use 595639ff905SBarry Smith PetscPushErrorHandler() to provide your own error handler that determines what kind of messages to print 596639ff905SBarry Smith 597639ff905SBarry Smith Level: developer 598639ff905SBarry Smith 599639ff905SBarry Smith Fortran Note: 600639ff905SBarry Smith This routine is not supported in Fortran. 601639ff905SBarry Smith 602639ff905SBarry Smith Concepts: error messages^printing 603639ff905SBarry Smith Concepts: printing^error messages 604639ff905SBarry Smith 605639ff905SBarry Smith .seealso: PetscFPrintf(), PetscSynchronizedPrintf(), PetscHelpPrintf(), PetscPrintf(), PetscErrorHandlerPush(), PetscVFPrintf(), PetscHelpPrintf() 606639ff905SBarry Smith M*/ 607639ff905SBarry Smith PETSC_EXTERN PetscErrorCode (*PetscErrorPrintf)(const char[],...); 608639ff905SBarry Smith 609329f5518SBarry Smith typedef enum {PETSC_FP_TRAP_OFF=0,PETSC_FP_TRAP_ON=1} PetscFPTrap; 610014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSetFPTrap(PetscFPTrap); 611014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscFPTrapPush(PetscFPTrap); 612014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscFPTrapPop(void); 61354a8ef01SBarry Smith 6143a40ed3dSBarry Smith /* 6153a40ed3dSBarry Smith Allows the code to build a stack frame as it runs 6163a40ed3dSBarry Smith */ 6173a40ed3dSBarry Smith 61899cd645aSJed Brown #define PETSCSTACKSIZE 64 619184914b5SBarry Smith 6203a40ed3dSBarry Smith typedef struct { 6210e33f6ddSBarry Smith const char *function[PETSCSTACKSIZE]; 6220e33f6ddSBarry Smith const char *file[PETSCSTACKSIZE]; 623184914b5SBarry Smith int line[PETSCSTACKSIZE]; 624a8d2bbe5SBarry Smith PetscBool petscroutine[PETSCSTACKSIZE]; 625184914b5SBarry Smith int currentsize; 626a2f94806SJed Brown int hotdepth; 6273a40ed3dSBarry Smith } PetscStack; 6283a40ed3dSBarry Smith 6291f46d60fSShri Abhyankar PETSC_EXTERN PetscStack *petscstack; 630184914b5SBarry Smith 6316f5c2d7aSBarry Smith PetscErrorCode PetscStackCopy(PetscStack*,PetscStack*); 6326f5c2d7aSBarry Smith PetscErrorCode PetscStackPrint(PetscStack *,FILE*); 6332d7c6352SJed Brown #if defined(PETSC_USE_DEBUG) 634dbf62e16SBarry Smith PETSC_STATIC_INLINE PetscBool PetscStackActive(void) 635dbf62e16SBarry Smith { 6365c25fcd7SBarry Smith return(petscstack ? PETSC_TRUE : PETSC_FALSE); 637dbf62e16SBarry Smith } 6383a40ed3dSBarry Smith 639441dd030SJed Brown /* Stack handling is based on the following two "NoCheck" macros. These should only be called directly by other error 640441dd030SJed Brown * handling macros. We record the line of the call, which may or may not be the location of the definition. But is at 641441dd030SJed Brown * least more useful than "unknown" because it can distinguish multiple calls from the same function. 642441dd030SJed Brown */ 643441dd030SJed Brown 644a2f94806SJed Brown #define PetscStackPushNoCheck(funct,petsc_routine,hot) \ 645441dd030SJed Brown do { \ 646e04113cfSBarry Smith PetscStackSAWsTakeAccess(); \ 6475c25fcd7SBarry Smith if (petscstack && (petscstack->currentsize < PETSCSTACKSIZE)) { \ 6485c25fcd7SBarry Smith petscstack->function[petscstack->currentsize] = funct; \ 6495c25fcd7SBarry Smith petscstack->file[petscstack->currentsize] = __FILE__; \ 6505c25fcd7SBarry Smith petscstack->line[petscstack->currentsize] = __LINE__; \ 6515c25fcd7SBarry Smith petscstack->petscroutine[petscstack->currentsize] = petsc_routine; \ 6525c25fcd7SBarry Smith petscstack->currentsize++; \ 653441dd030SJed Brown } \ 6545c25fcd7SBarry Smith if (petscstack) { \ 6555c25fcd7SBarry Smith petscstack->hotdepth += (hot || petscstack->hotdepth); \ 656a2f94806SJed Brown } \ 657e04113cfSBarry Smith PetscStackSAWsGrantAccess(); \ 658441dd030SJed Brown } while (0) 659441dd030SJed Brown 660441dd030SJed Brown #define PetscStackPopNoCheck \ 6615c25fcd7SBarry Smith do { \ 662e04113cfSBarry Smith PetscStackSAWsTakeAccess(); \ 6635c25fcd7SBarry Smith if (petscstack && petscstack->currentsize > 0) { \ 6645c25fcd7SBarry Smith petscstack->currentsize--; \ 6655c25fcd7SBarry Smith petscstack->function[petscstack->currentsize] = 0; \ 6665c25fcd7SBarry Smith petscstack->file[petscstack->currentsize] = 0; \ 6675c25fcd7SBarry Smith petscstack->line[petscstack->currentsize] = 0; \ 6685c25fcd7SBarry Smith petscstack->petscroutine[petscstack->currentsize] = PETSC_FALSE;\ 669441dd030SJed Brown } \ 6705c25fcd7SBarry Smith if (petscstack) { \ 6715c25fcd7SBarry Smith petscstack->hotdepth = PetscMax(petscstack->hotdepth-1,0); \ 672a2f94806SJed Brown } \ 673e04113cfSBarry Smith PetscStackSAWsGrantAccess(); \ 674441dd030SJed Brown } while (0) 675441dd030SJed Brown 67630de9b25SBarry Smith /*MC 6771957e957SBarry Smith PetscFunctionBegin - First executable line of each PETSc function, used for error handling. Final 6781957e957SBarry Smith line of PETSc functions should be PetscFunctionReturn(0); 67930de9b25SBarry Smith 68030de9b25SBarry Smith Synopsis: 681aaa7dc30SBarry Smith #include <petscsys.h> 68230de9b25SBarry Smith void PetscFunctionBegin; 68330de9b25SBarry Smith 684eca87e8dSBarry Smith Not Collective 685eca87e8dSBarry Smith 68630de9b25SBarry Smith Usage: 68730de9b25SBarry Smith .vb 68830de9b25SBarry Smith int something; 68930de9b25SBarry Smith 69030de9b25SBarry Smith PetscFunctionBegin; 69130de9b25SBarry Smith .ve 69230de9b25SBarry Smith 69330de9b25SBarry Smith Notes: 6941957e957SBarry Smith Use PetscFunctionBeginUser for application codes. 6951957e957SBarry Smith 69630de9b25SBarry Smith Not available in Fortran 69730de9b25SBarry Smith 69830de9b25SBarry Smith Level: developer 69930de9b25SBarry Smith 7001957e957SBarry Smith .seealso: PetscFunctionReturn(), PetscFunctionBeginHot(), PetscFunctionBeginUser() 70130de9b25SBarry Smith 70230de9b25SBarry Smith .keywords: traceback, error handling 70330de9b25SBarry Smith M*/ 704441dd030SJed Brown #define PetscFunctionBegin do { \ 705a2f94806SJed Brown PetscStackPushNoCheck(PETSC_FUNCTION_NAME,PETSC_TRUE,PETSC_FALSE); \ 706a2f94806SJed Brown PetscCheck__FUNCT__(); \ 707a2f94806SJed Brown PetscRegister__FUNCT__(); \ 708a2f94806SJed Brown } while (0) 709a2f94806SJed Brown 710a2f94806SJed Brown /*MC 711a2f94806SJed Brown PetscFunctionBeginHot - Substitute for PetscFunctionBegin to be used in functions that are called in 712a2f94806SJed Brown performance-critical circumstances. Use of this function allows for lighter profiling by default. 713a2f94806SJed Brown 714a2f94806SJed Brown Synopsis: 715aaa7dc30SBarry Smith #include <petscsys.h> 716a2f94806SJed Brown void PetscFunctionBeginHot; 717a2f94806SJed Brown 718a2f94806SJed Brown Not Collective 719a2f94806SJed Brown 720a2f94806SJed Brown Usage: 721a2f94806SJed Brown .vb 722a2f94806SJed Brown int something; 723a2f94806SJed Brown 724a2f94806SJed Brown PetscFunctionBeginHot; 725a2f94806SJed Brown .ve 726a2f94806SJed Brown 727a2f94806SJed Brown Notes: 728a2f94806SJed Brown Not available in Fortran 729a2f94806SJed Brown 730a2f94806SJed Brown Level: developer 731a2f94806SJed Brown 732a2f94806SJed Brown .seealso: PetscFunctionBegin, PetscFunctionReturn() 733a2f94806SJed Brown 734a2f94806SJed Brown .keywords: traceback, error handling 735a2f94806SJed Brown M*/ 736a2f94806SJed Brown #define PetscFunctionBeginHot do { \ 737a2f94806SJed Brown PetscStackPushNoCheck(PETSC_FUNCTION_NAME,PETSC_TRUE,PETSC_TRUE); \ 73853c77d0aSJed Brown PetscCheck__FUNCT__(); \ 7392d53ad75SBarry Smith PetscRegister__FUNCT__(); \ 74053c77d0aSJed Brown } while (0) 74153c77d0aSJed Brown 742a8d2bbe5SBarry Smith /*MC 743a8d2bbe5SBarry Smith PetscFunctionBeginUser - First executable line of user provided PETSc routine 744a8d2bbe5SBarry Smith 745a8d2bbe5SBarry Smith Synopsis: 746aaa7dc30SBarry Smith #include <petscsys.h> 747a8d2bbe5SBarry Smith void PetscFunctionBeginUser; 748a8d2bbe5SBarry Smith 749a8d2bbe5SBarry Smith Not Collective 750a8d2bbe5SBarry Smith 751a8d2bbe5SBarry Smith Usage: 752a8d2bbe5SBarry Smith .vb 753a8d2bbe5SBarry Smith int something; 754a8d2bbe5SBarry Smith 755ac285190SBarry Smith PetscFunctionBeginUser; 756a8d2bbe5SBarry Smith .ve 757a8d2bbe5SBarry Smith 758a8d2bbe5SBarry Smith Notes: 7591957e957SBarry Smith Final line of PETSc functions should be PetscFunctionReturn(0) except for main(). 7601957e957SBarry Smith 761a8d2bbe5SBarry Smith Not available in Fortran 762a8d2bbe5SBarry Smith 763ac285190SBarry Smith This is identical to PetscFunctionBegin except it labels the routine as a user 764ac285190SBarry Smith routine instead of as a PETSc library routine. 765ac285190SBarry Smith 766a2f94806SJed Brown Level: intermediate 767a8d2bbe5SBarry Smith 768a2f94806SJed Brown .seealso: PetscFunctionReturn(), PetscFunctionBegin, PetscFunctionBeginHot 769a8d2bbe5SBarry Smith 770a8d2bbe5SBarry Smith .keywords: traceback, error handling 771a8d2bbe5SBarry Smith M*/ 772a8d2bbe5SBarry Smith #define PetscFunctionBeginUser \ 773a8d2bbe5SBarry Smith do { \ 774a2f94806SJed Brown PetscStackPushNoCheck(PETSC_FUNCTION_NAME,PETSC_FALSE,PETSC_FALSE); \ 775a8d2bbe5SBarry Smith PetscCheck__FUNCT__(); \ 776a8d2bbe5SBarry Smith PetscRegister__FUNCT__(); \ 777a8d2bbe5SBarry Smith } while (0) 778a8d2bbe5SBarry Smith 779a8d2bbe5SBarry Smith 7802d53ad75SBarry Smith #if defined(PETSC_SERIALIZE_FUNCTIONS) 781af0996ceSBarry Smith #include <petsc/private/petscfptimpl.h> 7822d53ad75SBarry Smith /* 7832d53ad75SBarry Smith Registers the current function into the global function pointer to function name table 7842d53ad75SBarry Smith 7852d53ad75SBarry Smith Have to fix this to handle errors but cannot return error since used in PETSC_VIEWER_DRAW_() etc 7862d53ad75SBarry Smith */ 7872d53ad75SBarry Smith #define PetscRegister__FUNCT__() do { \ 7882d53ad75SBarry Smith static PetscBool __chked = PETSC_FALSE; \ 7892d53ad75SBarry Smith if (!__chked) {\ 7900298fd71SBarry Smith void *ptr; PetscDLSym(NULL,__FUNCT__,&ptr);\ 7912d53ad75SBarry Smith __chked = PETSC_TRUE;\ 7922d53ad75SBarry Smith }} while (0) 7932d53ad75SBarry Smith #else 7942d53ad75SBarry Smith #define PetscRegister__FUNCT__() 7952d53ad75SBarry Smith #endif 7962d53ad75SBarry Smith 797573b0fb4SBarry Smith #define PetscCheck__FUNCT__() do { PetscBool _sc1,_sc2; \ 798573b0fb4SBarry Smith PetscStrcmpNoError(PETSC_FUNCTION_NAME,__FUNCT__,&_sc1);\ 799573b0fb4SBarry Smith PetscStrcmpNoError(__FUNCT__,"User provided function",&_sc2);\ 800573b0fb4SBarry Smith if (!_sc1 && !_sc2) { \ 801e9f0693fSJed Brown printf("%s:%d: __FUNCT__=\"%s\" does not agree with %s=\"%s\"\n",__FILE__,__LINE__,__FUNCT__,PetscStringize(PETSC_FUNCTION_NAME),PETSC_FUNCTION_NAME); \ 80253c77d0aSJed Brown } \ 80353c77d0aSJed Brown } while (0) 8043a40ed3dSBarry Smith 8055cd90555SBarry Smith #define PetscStackPush(n) \ 80661d886c9SShri Abhyankar do { \ 807a2f94806SJed Brown PetscStackPushNoCheck(n,PETSC_FALSE,PETSC_FALSE); \ 80815681b3cSBarry Smith CHKMEMQ; \ 80915681b3cSBarry Smith } while (0) 8103a40ed3dSBarry Smith 811d64ed03dSBarry Smith #define PetscStackPop \ 812441dd030SJed Brown do { \ 813441dd030SJed Brown CHKMEMQ; \ 814441dd030SJed Brown PetscStackPopNoCheck; \ 81515681b3cSBarry Smith } while (0) 816d64ed03dSBarry Smith 81730de9b25SBarry Smith /*MC 81830de9b25SBarry Smith PetscFunctionReturn - Last executable line of each PETSc function 81930de9b25SBarry Smith used for error handling. Replaces return() 82030de9b25SBarry Smith 82130de9b25SBarry Smith Synopsis: 822aaa7dc30SBarry Smith #include <petscsys.h> 82330de9b25SBarry Smith void PetscFunctionReturn(0); 82430de9b25SBarry Smith 825eca87e8dSBarry Smith Not Collective 826eca87e8dSBarry Smith 82730de9b25SBarry Smith Usage: 82830de9b25SBarry Smith .vb 82930de9b25SBarry Smith .... 83030de9b25SBarry Smith PetscFunctionReturn(0); 83130de9b25SBarry Smith } 83230de9b25SBarry Smith .ve 83330de9b25SBarry Smith 83430de9b25SBarry Smith Notes: 83530de9b25SBarry Smith Not available in Fortran 83630de9b25SBarry Smith 83730de9b25SBarry Smith Level: developer 83830de9b25SBarry Smith 83930de9b25SBarry Smith .seealso: PetscFunctionBegin() 84030de9b25SBarry Smith 84130de9b25SBarry Smith .keywords: traceback, error handling 84230de9b25SBarry Smith M*/ 8435cd90555SBarry Smith #define PetscFunctionReturn(a) \ 8448246ba0dSJed Brown do { \ 845441dd030SJed Brown PetscStackPopNoCheck; \ 8468246ba0dSJed Brown return(a);} while (0) 847d64ed03dSBarry Smith 848ff94ddecSSatish Balay #define PetscFunctionReturnVoid() \ 8498246ba0dSJed Brown do { \ 850441dd030SJed Brown PetscStackPopNoCheck; \ 8518246ba0dSJed Brown return;} while (0) 85276386721SLisandro Dalcin 8536d385327SIbrahima Ba #else 8546d385327SIbrahima Ba 855c82b4e47SJed Brown PETSC_STATIC_INLINE PetscBool PetscStackActive(void) {return PETSC_FALSE;} 856a2f94806SJed Brown #define PetscStackPushNoCheck(funct,petsc_routine,hot) do {} while (0) 857441dd030SJed Brown #define PetscStackPopNoCheck do {} while (0) 8583a40ed3dSBarry Smith #define PetscFunctionBegin 8590bdf7c52SPeter Brune #define PetscFunctionBeginUser 860a2f94806SJed Brown #define PetscFunctionBeginHot 8613a40ed3dSBarry Smith #define PetscFunctionReturn(a) return(a) 8625665465eSBarry Smith #define PetscFunctionReturnVoid() return 863812af9f3SBarry Smith #define PetscStackPop CHKMEMQ 864812af9f3SBarry Smith #define PetscStackPush(f) CHKMEMQ 8653a40ed3dSBarry Smith 8663a40ed3dSBarry Smith #endif 8673a40ed3dSBarry Smith 868eb6b5d47SBarry Smith /* 869eb6b5d47SBarry Smith PetscStackCall - Calls an external library routine or user function after pushing the name of the routine on the stack. 870eb6b5d47SBarry Smith 871eb6b5d47SBarry Smith Input Parameters: 872eb6b5d47SBarry Smith + name - string that gives the name of the function being called 873fd3f9acdSBarry Smith - routine - actual call to the routine, including ierr = and CHKERRQ(ierr); 874fd3f9acdSBarry Smith 875dbf62e16SBarry Smith Note: Often one should use PetscStackCallStandard() instead. This routine is intended for external library routines that DO NOT return error codes 876eb6b5d47SBarry Smith 877eb6b5d47SBarry 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. 878eb6b5d47SBarry Smith 879fd3f9acdSBarry Smith 880fd3f9acdSBarry Smith 881eb6b5d47SBarry Smith */ 88230ecc5abSKarl Rupp #define PetscStackCall(name,routine) do { PetscStackPush(name);routine;PetscStackPop; } while(0) 883eb6b5d47SBarry Smith 884fd3f9acdSBarry Smith /* 885fd3f9acdSBarry Smith PetscStackCallStandard - Calls an external library routine after pushing the name of the routine on the stack. 886fd3f9acdSBarry Smith 887fd3f9acdSBarry Smith Input Parameters: 888fd3f9acdSBarry Smith + func- name of the routine 889fd3f9acdSBarry Smith - args - arguments to the routine surrounded by () 890fd3f9acdSBarry Smith 891dbf62e16SBarry Smith Notes: This is intended for external package routines that return error codes. Use PetscStackCall() for those that do not. 892dbf62e16SBarry Smith 893dbf62e16SBarry 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. 894fd3f9acdSBarry Smith 895fd3f9acdSBarry Smith */ 896fd3f9acdSBarry Smith #define PetscStackCallStandard(func,args) do { \ 897*7afcd97cSStefano 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); \ 898fd3f9acdSBarry Smith } while (0) 899fd3f9acdSBarry Smith 900014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscStackCreate(void); 901639ff905SBarry Smith PETSC_EXTERN PetscErrorCode PetscStackView(FILE*); 902014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscStackDestroy(void); 90306d1fe2cSBarry Smith 90406d1fe2cSBarry Smith #endif 905