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 */ 6892e8f287SBarry Smith #define PETSC_ERR_MAX_VALUE 93 /* this is always the one more than the largest error code */ 692a6744ebSBarry Smith 70b9eb5ee8SHong Zhang #define PETSC_ERR_OPT_OVERWRITE 94 /* overwrote options which should not be changed */ 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 469*82f73ecaSAlejandro Lamas Daviña #define CHKERRCUDA(err) do {if (PetscUnlikely(((int)err) != (int)CUDA_SUCCESS)) SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_LIB,"CUDA error %d",err);} while(0) 470*82f73ecaSAlejandro Lamas Daviña #define CHKERRCUBLAS(err) do {if (PetscUnlikely(((int)err) != (int)CUBLAS_STATUS_SUCCESS)) SETERRQ1(PETSC_COMM_SELF, PETSC_ERR_LIB, "CUBLAS error %d",err);} while(0) 471*82f73ecaSAlejandro 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) ; 5221ee4faa0SMatthew Knepley #define CHKERRABORT(comm,n) ; 5231ee4faa0SMatthew Knepley #define CHKERRCONTINUE(n) ; 52485614651SBarry Smith #define CHKMEMQ ; 525*82f73ecaSAlejandro Lamas Daviña #define CHKERRCUDA(err) ; 526*82f73ecaSAlejandro Lamas Daviña #define CHKERRCUBLAS(err) ; 52785614651SBarry Smith 5288cabf42eSMatthew G Knepley #ifdef PETSC_CLANGUAGE_CXX 5298cabf42eSMatthew G Knepley #define CHKERRXX(n) ; 5308cabf42eSMatthew G Knepley #endif 5318cabf42eSMatthew G Knepley 532f8e50935SSatish Balay #endif /* PETSC_USE_ERRORCHECKING */ 53354a8ef01SBarry Smith 534668f157eSBarry Smith /*E 535668f157eSBarry Smith PetscErrorType - passed to the PETSc error handling routines indicating if this is the first or a later call to the error handlers 536668f157eSBarry Smith 537668f157eSBarry Smith Level: advanced 538668f157eSBarry Smith 539d736bfebSBarry Smith PETSC_ERROR_IN_CXX indicates the error was detected in C++ and an exception should be generated 540d736bfebSBarry Smith 54161b0d812SBarry Smith Developer Notes: This is currently used to decide when to print the detailed information about the run in PetscTraceBackErrorHandler() 542668f157eSBarry Smith 543d736bfebSBarry Smith .seealso: PetscError(), SETERRXX() 544668f157eSBarry Smith E*/ 545d736bfebSBarry Smith typedef enum {PETSC_ERROR_INITIAL=0,PETSC_ERROR_REPEAT=1,PETSC_ERROR_IN_CXX = 2} PetscErrorType; 5464b209cf6SBarry Smith 547eb9e708aSLisandro Dalcin #if defined(__clang_analyzer__) 548eb9e708aSLisandro Dalcin __attribute__((analyzer_noreturn)) 549eb9e708aSLisandro Dalcin #endif 550eb9e708aSLisandro Dalcin PETSC_EXTERN PetscErrorCode PetscError(MPI_Comm,int,const char*,const char*,PetscErrorCode,PetscErrorType,const char*,...); 551eb9e708aSLisandro Dalcin 552014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscErrorPrintfInitialize(void); 553014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscErrorMessage(int,const char*[],char **); 554efca3c55SSatish Balay PETSC_EXTERN PetscErrorCode PetscTraceBackErrorHandler(MPI_Comm,int,const char*,const char*,PetscErrorCode,PetscErrorType,const char*,void*); 555efca3c55SSatish Balay PETSC_EXTERN PetscErrorCode PetscIgnoreErrorHandler(MPI_Comm,int,const char*,const char*,PetscErrorCode,PetscErrorType,const char*,void*); 556efca3c55SSatish Balay PETSC_EXTERN PetscErrorCode PetscEmacsClientErrorHandler(MPI_Comm,int,const char*,const char*,PetscErrorCode,PetscErrorType,const char*,void*); 557efca3c55SSatish Balay PETSC_EXTERN PetscErrorCode PetscMPIAbortErrorHandler(MPI_Comm,int,const char*,const char*,PetscErrorCode,PetscErrorType,const char*,void*); 558efca3c55SSatish Balay PETSC_EXTERN PetscErrorCode PetscAbortErrorHandler(MPI_Comm,int,const char*,const char*,PetscErrorCode,PetscErrorType,const char*,void*); 559efca3c55SSatish Balay PETSC_EXTERN PetscErrorCode PetscAttachDebuggerErrorHandler(MPI_Comm,int,const char*,const char*,PetscErrorCode,PetscErrorType,const char*,void*); 560efca3c55SSatish Balay PETSC_EXTERN PetscErrorCode PetscReturnErrorHandler(MPI_Comm,int,const char*,const char*,PetscErrorCode,PetscErrorType,const char*,void*); 561efca3c55SSatish Balay PETSC_EXTERN PetscErrorCode PetscPushErrorHandler(PetscErrorCode (*handler)(MPI_Comm,int,const char*,const char*,PetscErrorCode,PetscErrorType,const char*,void*),void*); 562014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscPopErrorHandler(void); 5638d359177SBarry Smith PETSC_EXTERN PetscErrorCode PetscSignalHandlerDefault(int,void*); 564014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscPushSignalHandler(PetscErrorCode (*)(int,void *),void*); 565014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscPopSignalHandler(void); 56628559dc8SJed Brown PETSC_EXTERN PetscErrorCode PetscCheckPointerSetIntensity(PetscInt); 567329f5518SBarry Smith 568639ff905SBarry Smith /*MC 569639ff905SBarry Smith PetscErrorPrintf - Prints error messages. 570639ff905SBarry Smith 571639ff905SBarry Smith Synopsis: 572aaa7dc30SBarry Smith #include <petscsys.h> 573639ff905SBarry Smith PetscErrorCode (*PetscErrorPrintf)(const char format[],...); 574639ff905SBarry Smith 575639ff905SBarry Smith Not Collective 576639ff905SBarry Smith 577639ff905SBarry Smith Input Parameters: 578639ff905SBarry Smith . format - the usual printf() format string 579639ff905SBarry Smith 580639ff905SBarry Smith Options Database Keys: 5811957e957SBarry Smith + -error_output_stdout - cause error messages to be printed to stdout instead of the (default) stderr 582e1bc860dSBarry Smith - -error_output_none - to turn off all printing of error messages (does not change the way the error is handled.) 583639ff905SBarry Smith 584639ff905SBarry Smith Notes: Use 585639ff905SBarry Smith $ PetscErrorPrintf = PetscErrorPrintfNone; to turn off all printing of error messages (does not change the way the 586639ff905SBarry Smith $ error is handled.) and 5871957e957SBarry Smith $ PetscErrorPrintf = PetscErrorPrintfDefault; to turn it back on or you can use your own function 588639ff905SBarry Smith 589639ff905SBarry Smith Use 590639ff905SBarry Smith PETSC_STDERR = FILE* obtained from a file open etc. to have stderr printed to the file. 591639ff905SBarry Smith PETSC_STDOUT = FILE* obtained from a file open etc. to have stdout printed to the file. 592639ff905SBarry Smith 593639ff905SBarry Smith Use 594639ff905SBarry Smith PetscPushErrorHandler() to provide your own error handler that determines what kind of messages to print 595639ff905SBarry Smith 596639ff905SBarry Smith Level: developer 597639ff905SBarry Smith 598639ff905SBarry Smith Fortran Note: 599639ff905SBarry Smith This routine is not supported in Fortran. 600639ff905SBarry Smith 601639ff905SBarry Smith Concepts: error messages^printing 602639ff905SBarry Smith Concepts: printing^error messages 603639ff905SBarry Smith 604639ff905SBarry Smith .seealso: PetscFPrintf(), PetscSynchronizedPrintf(), PetscHelpPrintf(), PetscPrintf(), PetscErrorHandlerPush(), PetscVFPrintf(), PetscHelpPrintf() 605639ff905SBarry Smith M*/ 606639ff905SBarry Smith PETSC_EXTERN PetscErrorCode (*PetscErrorPrintf)(const char[],...); 607639ff905SBarry Smith 608329f5518SBarry Smith typedef enum {PETSC_FP_TRAP_OFF=0,PETSC_FP_TRAP_ON=1} PetscFPTrap; 609014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSetFPTrap(PetscFPTrap); 610014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscFPTrapPush(PetscFPTrap); 611014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscFPTrapPop(void); 61254a8ef01SBarry Smith 6133a40ed3dSBarry Smith /* 6143a40ed3dSBarry Smith Allows the code to build a stack frame as it runs 6153a40ed3dSBarry Smith */ 6163a40ed3dSBarry Smith 61799cd645aSJed Brown #define PETSCSTACKSIZE 64 618184914b5SBarry Smith 6193a40ed3dSBarry Smith typedef struct { 6200e33f6ddSBarry Smith const char *function[PETSCSTACKSIZE]; 6210e33f6ddSBarry Smith const char *file[PETSCSTACKSIZE]; 622184914b5SBarry Smith int line[PETSCSTACKSIZE]; 623a8d2bbe5SBarry Smith PetscBool petscroutine[PETSCSTACKSIZE]; 624184914b5SBarry Smith int currentsize; 625a2f94806SJed Brown int hotdepth; 6263a40ed3dSBarry Smith } PetscStack; 6273a40ed3dSBarry Smith 6281f46d60fSShri Abhyankar PETSC_EXTERN PetscStack *petscstack; 629184914b5SBarry Smith 6306f5c2d7aSBarry Smith PetscErrorCode PetscStackCopy(PetscStack*,PetscStack*); 6316f5c2d7aSBarry Smith PetscErrorCode PetscStackPrint(PetscStack *,FILE*); 6322d7c6352SJed Brown #if defined(PETSC_USE_DEBUG) 633dbf62e16SBarry Smith PETSC_STATIC_INLINE PetscBool PetscStackActive(void) 634dbf62e16SBarry Smith { 6355c25fcd7SBarry Smith return(petscstack ? PETSC_TRUE : PETSC_FALSE); 636dbf62e16SBarry Smith } 6373a40ed3dSBarry Smith 638441dd030SJed Brown /* Stack handling is based on the following two "NoCheck" macros. These should only be called directly by other error 639441dd030SJed Brown * handling macros. We record the line of the call, which may or may not be the location of the definition. But is at 640441dd030SJed Brown * least more useful than "unknown" because it can distinguish multiple calls from the same function. 641441dd030SJed Brown */ 642441dd030SJed Brown 643a2f94806SJed Brown #define PetscStackPushNoCheck(funct,petsc_routine,hot) \ 644441dd030SJed Brown do { \ 645e04113cfSBarry Smith PetscStackSAWsTakeAccess(); \ 6465c25fcd7SBarry Smith if (petscstack && (petscstack->currentsize < PETSCSTACKSIZE)) { \ 6475c25fcd7SBarry Smith petscstack->function[petscstack->currentsize] = funct; \ 6485c25fcd7SBarry Smith petscstack->file[petscstack->currentsize] = __FILE__; \ 6495c25fcd7SBarry Smith petscstack->line[petscstack->currentsize] = __LINE__; \ 6505c25fcd7SBarry Smith petscstack->petscroutine[petscstack->currentsize] = petsc_routine; \ 6515c25fcd7SBarry Smith petscstack->currentsize++; \ 652441dd030SJed Brown } \ 6535c25fcd7SBarry Smith if (petscstack) { \ 6545c25fcd7SBarry Smith petscstack->hotdepth += (hot || petscstack->hotdepth); \ 655a2f94806SJed Brown } \ 656e04113cfSBarry Smith PetscStackSAWsGrantAccess(); \ 657441dd030SJed Brown } while (0) 658441dd030SJed Brown 659441dd030SJed Brown #define PetscStackPopNoCheck \ 6605c25fcd7SBarry Smith do { \ 661e04113cfSBarry Smith PetscStackSAWsTakeAccess(); \ 6625c25fcd7SBarry Smith if (petscstack && petscstack->currentsize > 0) { \ 6635c25fcd7SBarry Smith petscstack->currentsize--; \ 6645c25fcd7SBarry Smith petscstack->function[petscstack->currentsize] = 0; \ 6655c25fcd7SBarry Smith petscstack->file[petscstack->currentsize] = 0; \ 6665c25fcd7SBarry Smith petscstack->line[petscstack->currentsize] = 0; \ 6675c25fcd7SBarry Smith petscstack->petscroutine[petscstack->currentsize] = PETSC_FALSE;\ 668441dd030SJed Brown } \ 6695c25fcd7SBarry Smith if (petscstack) { \ 6705c25fcd7SBarry Smith petscstack->hotdepth = PetscMax(petscstack->hotdepth-1,0); \ 671a2f94806SJed Brown } \ 672e04113cfSBarry Smith PetscStackSAWsGrantAccess(); \ 673441dd030SJed Brown } while (0) 674441dd030SJed Brown 67530de9b25SBarry Smith /*MC 6761957e957SBarry Smith PetscFunctionBegin - First executable line of each PETSc function, used for error handling. Final 6771957e957SBarry Smith line of PETSc functions should be PetscFunctionReturn(0); 67830de9b25SBarry Smith 67930de9b25SBarry Smith Synopsis: 680aaa7dc30SBarry Smith #include <petscsys.h> 68130de9b25SBarry Smith void PetscFunctionBegin; 68230de9b25SBarry Smith 683eca87e8dSBarry Smith Not Collective 684eca87e8dSBarry Smith 68530de9b25SBarry Smith Usage: 68630de9b25SBarry Smith .vb 68730de9b25SBarry Smith int something; 68830de9b25SBarry Smith 68930de9b25SBarry Smith PetscFunctionBegin; 69030de9b25SBarry Smith .ve 69130de9b25SBarry Smith 69230de9b25SBarry Smith Notes: 6931957e957SBarry Smith Use PetscFunctionBeginUser for application codes. 6941957e957SBarry Smith 69530de9b25SBarry Smith Not available in Fortran 69630de9b25SBarry Smith 69730de9b25SBarry Smith Level: developer 69830de9b25SBarry Smith 6991957e957SBarry Smith .seealso: PetscFunctionReturn(), PetscFunctionBeginHot(), PetscFunctionBeginUser() 70030de9b25SBarry Smith 70130de9b25SBarry Smith .keywords: traceback, error handling 70230de9b25SBarry Smith M*/ 703441dd030SJed Brown #define PetscFunctionBegin do { \ 704a2f94806SJed Brown PetscStackPushNoCheck(PETSC_FUNCTION_NAME,PETSC_TRUE,PETSC_FALSE); \ 705a2f94806SJed Brown PetscCheck__FUNCT__(); \ 706a2f94806SJed Brown PetscRegister__FUNCT__(); \ 707a2f94806SJed Brown } while (0) 708a2f94806SJed Brown 709a2f94806SJed Brown /*MC 710a2f94806SJed Brown PetscFunctionBeginHot - Substitute for PetscFunctionBegin to be used in functions that are called in 711a2f94806SJed Brown performance-critical circumstances. Use of this function allows for lighter profiling by default. 712a2f94806SJed Brown 713a2f94806SJed Brown Synopsis: 714aaa7dc30SBarry Smith #include <petscsys.h> 715a2f94806SJed Brown void PetscFunctionBeginHot; 716a2f94806SJed Brown 717a2f94806SJed Brown Not Collective 718a2f94806SJed Brown 719a2f94806SJed Brown Usage: 720a2f94806SJed Brown .vb 721a2f94806SJed Brown int something; 722a2f94806SJed Brown 723a2f94806SJed Brown PetscFunctionBeginHot; 724a2f94806SJed Brown .ve 725a2f94806SJed Brown 726a2f94806SJed Brown Notes: 727a2f94806SJed Brown Not available in Fortran 728a2f94806SJed Brown 729a2f94806SJed Brown Level: developer 730a2f94806SJed Brown 731a2f94806SJed Brown .seealso: PetscFunctionBegin, PetscFunctionReturn() 732a2f94806SJed Brown 733a2f94806SJed Brown .keywords: traceback, error handling 734a2f94806SJed Brown M*/ 735a2f94806SJed Brown #define PetscFunctionBeginHot do { \ 736a2f94806SJed Brown PetscStackPushNoCheck(PETSC_FUNCTION_NAME,PETSC_TRUE,PETSC_TRUE); \ 73753c77d0aSJed Brown PetscCheck__FUNCT__(); \ 7382d53ad75SBarry Smith PetscRegister__FUNCT__(); \ 73953c77d0aSJed Brown } while (0) 74053c77d0aSJed Brown 741a8d2bbe5SBarry Smith /*MC 742a8d2bbe5SBarry Smith PetscFunctionBeginUser - First executable line of user provided PETSc routine 743a8d2bbe5SBarry Smith 744a8d2bbe5SBarry Smith Synopsis: 745aaa7dc30SBarry Smith #include <petscsys.h> 746a8d2bbe5SBarry Smith void PetscFunctionBeginUser; 747a8d2bbe5SBarry Smith 748a8d2bbe5SBarry Smith Not Collective 749a8d2bbe5SBarry Smith 750a8d2bbe5SBarry Smith Usage: 751a8d2bbe5SBarry Smith .vb 752a8d2bbe5SBarry Smith int something; 753a8d2bbe5SBarry Smith 754a8d2bbe5SBarry Smith PetscFunctionBegin; 755a8d2bbe5SBarry Smith .ve 756a8d2bbe5SBarry Smith 757a8d2bbe5SBarry Smith Notes: 7581957e957SBarry Smith Final line of PETSc functions should be PetscFunctionReturn(0) except for main(). 7591957e957SBarry Smith 760a8d2bbe5SBarry Smith Not available in Fortran 761a8d2bbe5SBarry Smith 762a2f94806SJed Brown Level: intermediate 763a8d2bbe5SBarry Smith 764a2f94806SJed Brown .seealso: PetscFunctionReturn(), PetscFunctionBegin, PetscFunctionBeginHot 765a8d2bbe5SBarry Smith 766a8d2bbe5SBarry Smith .keywords: traceback, error handling 767a8d2bbe5SBarry Smith M*/ 768a8d2bbe5SBarry Smith #define PetscFunctionBeginUser \ 769a8d2bbe5SBarry Smith do { \ 770a2f94806SJed Brown PetscStackPushNoCheck(PETSC_FUNCTION_NAME,PETSC_FALSE,PETSC_FALSE); \ 771a8d2bbe5SBarry Smith PetscCheck__FUNCT__(); \ 772a8d2bbe5SBarry Smith PetscRegister__FUNCT__(); \ 773a8d2bbe5SBarry Smith } while (0) 774a8d2bbe5SBarry Smith 775a8d2bbe5SBarry Smith 7762d53ad75SBarry Smith #if defined(PETSC_SERIALIZE_FUNCTIONS) 777af0996ceSBarry Smith #include <petsc/private/petscfptimpl.h> 7782d53ad75SBarry Smith /* 7792d53ad75SBarry Smith Registers the current function into the global function pointer to function name table 7802d53ad75SBarry Smith 7812d53ad75SBarry Smith Have to fix this to handle errors but cannot return error since used in PETSC_VIEWER_DRAW_() etc 7822d53ad75SBarry Smith */ 7832d53ad75SBarry Smith #define PetscRegister__FUNCT__() do { \ 7842d53ad75SBarry Smith static PetscBool __chked = PETSC_FALSE; \ 7852d53ad75SBarry Smith if (!__chked) {\ 7860298fd71SBarry Smith void *ptr; PetscDLSym(NULL,__FUNCT__,&ptr);\ 7872d53ad75SBarry Smith __chked = PETSC_TRUE;\ 7882d53ad75SBarry Smith }} while (0) 7892d53ad75SBarry Smith #else 7902d53ad75SBarry Smith #define PetscRegister__FUNCT__() 7912d53ad75SBarry Smith #endif 7922d53ad75SBarry Smith 793573b0fb4SBarry Smith #define PetscCheck__FUNCT__() do { PetscBool _sc1,_sc2; \ 794573b0fb4SBarry Smith PetscStrcmpNoError(PETSC_FUNCTION_NAME,__FUNCT__,&_sc1);\ 795573b0fb4SBarry Smith PetscStrcmpNoError(__FUNCT__,"User provided function",&_sc2);\ 796573b0fb4SBarry Smith if (!_sc1 && !_sc2) { \ 797e9f0693fSJed Brown printf("%s:%d: __FUNCT__=\"%s\" does not agree with %s=\"%s\"\n",__FILE__,__LINE__,__FUNCT__,PetscStringize(PETSC_FUNCTION_NAME),PETSC_FUNCTION_NAME); \ 79853c77d0aSJed Brown } \ 79953c77d0aSJed Brown } while (0) 8003a40ed3dSBarry Smith 8015cd90555SBarry Smith #define PetscStackPush(n) \ 80261d886c9SShri Abhyankar do { \ 803a2f94806SJed Brown PetscStackPushNoCheck(n,PETSC_FALSE,PETSC_FALSE); \ 80415681b3cSBarry Smith CHKMEMQ; \ 80515681b3cSBarry Smith } while (0) 8063a40ed3dSBarry Smith 807d64ed03dSBarry Smith #define PetscStackPop \ 808441dd030SJed Brown do { \ 809441dd030SJed Brown CHKMEMQ; \ 810441dd030SJed Brown PetscStackPopNoCheck; \ 81115681b3cSBarry Smith } while (0) 812d64ed03dSBarry Smith 81330de9b25SBarry Smith /*MC 81430de9b25SBarry Smith PetscFunctionReturn - Last executable line of each PETSc function 81530de9b25SBarry Smith used for error handling. Replaces return() 81630de9b25SBarry Smith 81730de9b25SBarry Smith Synopsis: 818aaa7dc30SBarry Smith #include <petscsys.h> 81930de9b25SBarry Smith void PetscFunctionReturn(0); 82030de9b25SBarry Smith 821eca87e8dSBarry Smith Not Collective 822eca87e8dSBarry Smith 82330de9b25SBarry Smith Usage: 82430de9b25SBarry Smith .vb 82530de9b25SBarry Smith .... 82630de9b25SBarry Smith PetscFunctionReturn(0); 82730de9b25SBarry Smith } 82830de9b25SBarry Smith .ve 82930de9b25SBarry Smith 83030de9b25SBarry Smith Notes: 83130de9b25SBarry Smith Not available in Fortran 83230de9b25SBarry Smith 83330de9b25SBarry Smith Level: developer 83430de9b25SBarry Smith 83530de9b25SBarry Smith .seealso: PetscFunctionBegin() 83630de9b25SBarry Smith 83730de9b25SBarry Smith .keywords: traceback, error handling 83830de9b25SBarry Smith M*/ 8395cd90555SBarry Smith #define PetscFunctionReturn(a) \ 8408246ba0dSJed Brown do { \ 841441dd030SJed Brown PetscStackPopNoCheck; \ 8428246ba0dSJed Brown return(a);} while (0) 843d64ed03dSBarry Smith 844ff94ddecSSatish Balay #define PetscFunctionReturnVoid() \ 8458246ba0dSJed Brown do { \ 846441dd030SJed Brown PetscStackPopNoCheck; \ 8478246ba0dSJed Brown return;} while (0) 84876386721SLisandro Dalcin 8496d385327SIbrahima Ba #else 8506d385327SIbrahima Ba 851c82b4e47SJed Brown PETSC_STATIC_INLINE PetscBool PetscStackActive(void) {return PETSC_FALSE;} 852a2f94806SJed Brown #define PetscStackPushNoCheck(funct,petsc_routine,hot) do {} while (0) 853441dd030SJed Brown #define PetscStackPopNoCheck do {} while (0) 8543a40ed3dSBarry Smith #define PetscFunctionBegin 8550bdf7c52SPeter Brune #define PetscFunctionBeginUser 856a2f94806SJed Brown #define PetscFunctionBeginHot 8573a40ed3dSBarry Smith #define PetscFunctionReturn(a) return(a) 8585665465eSBarry Smith #define PetscFunctionReturnVoid() return 859812af9f3SBarry Smith #define PetscStackPop CHKMEMQ 860812af9f3SBarry Smith #define PetscStackPush(f) CHKMEMQ 8613a40ed3dSBarry Smith 8623a40ed3dSBarry Smith #endif 8633a40ed3dSBarry Smith 864eb6b5d47SBarry Smith /* 865eb6b5d47SBarry Smith PetscStackCall - Calls an external library routine or user function after pushing the name of the routine on the stack. 866eb6b5d47SBarry Smith 867eb6b5d47SBarry Smith Input Parameters: 868eb6b5d47SBarry Smith + name - string that gives the name of the function being called 869fd3f9acdSBarry Smith - routine - actual call to the routine, including ierr = and CHKERRQ(ierr); 870fd3f9acdSBarry Smith 871dbf62e16SBarry Smith Note: Often one should use PetscStackCallStandard() instead. This routine is intended for external library routines that DO NOT return error codes 872eb6b5d47SBarry Smith 873eb6b5d47SBarry 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. 874eb6b5d47SBarry Smith 875fd3f9acdSBarry Smith 876fd3f9acdSBarry Smith 877eb6b5d47SBarry Smith */ 87830ecc5abSKarl Rupp #define PetscStackCall(name,routine) do { PetscStackPush(name);routine;PetscStackPop; } while(0) 879eb6b5d47SBarry Smith 880fd3f9acdSBarry Smith /* 881fd3f9acdSBarry Smith PetscStackCallStandard - Calls an external library routine after pushing the name of the routine on the stack. 882fd3f9acdSBarry Smith 883fd3f9acdSBarry Smith Input Parameters: 884fd3f9acdSBarry Smith + func- name of the routine 885fd3f9acdSBarry Smith - args - arguments to the routine surrounded by () 886fd3f9acdSBarry Smith 887dbf62e16SBarry Smith Notes: This is intended for external package routines that return error codes. Use PetscStackCall() for those that do not. 888dbf62e16SBarry Smith 889dbf62e16SBarry 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. 890fd3f9acdSBarry Smith 891fd3f9acdSBarry Smith */ 892fd3f9acdSBarry Smith #define PetscStackCallStandard(func,args) do { \ 893fd3f9acdSBarry Smith PetscStackPush(#func);ierr = func args;PetscStackPop; if (ierr) SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_LIB,"Error in %s()",#func); \ 894fd3f9acdSBarry Smith } while (0) 895fd3f9acdSBarry Smith 896014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscStackCreate(void); 897639ff905SBarry Smith PETSC_EXTERN PetscErrorCode PetscStackView(FILE*); 898014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscStackDestroy(void); 89906d1fe2cSBarry Smith 90006d1fe2cSBarry Smith #endif 901