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 70*b9eb5ee8SHong Zhang #define PETSC_ERR_OPT_OVERWRITE 94 /* overwrote options which should not be changed */ 71*b9eb5ee8SHong 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 46930de9b25SBarry Smith /*MC 47030de9b25SBarry Smith CHKMEMQ - Checks the memory for corruption, calls error handler if any is detected 47130de9b25SBarry Smith 47230de9b25SBarry Smith Synopsis: 473aaa7dc30SBarry Smith #include <petscsys.h> 47491d3bdf4SKris Buschelman CHKMEMQ; 47530de9b25SBarry Smith 476eca87e8dSBarry Smith Not Collective 477eca87e8dSBarry Smith 47830de9b25SBarry Smith Level: beginner 47930de9b25SBarry Smith 48030de9b25SBarry Smith Notes: 4811957e957SBarry Smith We highly recommend using valgrind http://www.mcs.anl.gov/petsc/documentation/faq.html#valgrind for finding memory problems. This is useful 4821957e957SBarry Smith on systems that do not have valgrind, but much much less useful. 4831957e957SBarry Smith 484ff002950SBarry Smith Must run with the option -malloc_debug to enable this option 48530de9b25SBarry Smith 48630de9b25SBarry Smith Once the error handler is called the calling function is then returned from with the given error code. 48730de9b25SBarry Smith 48830de9b25SBarry Smith By defaults prints location where memory that is corrupted was allocated. 48930de9b25SBarry Smith 490f621e05eSBarry Smith Use CHKMEMA for functions that return void 491f621e05eSBarry Smith 49230de9b25SBarry Smith Concepts: memory corruption 49330de9b25SBarry Smith 4946024bd2cSBarry Smith .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), SETERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2(), SETERRQ3(), 495ff002950SBarry Smith PetscMallocValidate() 49630de9b25SBarry Smith M*/ 497efca3c55SSatish Balay #define CHKMEMQ do {PetscErrorCode _7_ierr = PetscMallocValidate(__LINE__,PETSC_FUNCTION_NAME,__FILE__);CHKERRQ(_7_ierr);} while(0) 49885614651SBarry Smith 499efca3c55SSatish Balay #define CHKMEMA PetscMallocValidate(__LINE__,PETSC_FUNCTION_NAME,__FILE__) 500e68848bdSBarry Smith 501f8e50935SSatish Balay #else /* PETSC_USE_ERRORCHECKING */ 502f621e05eSBarry Smith 503f621e05eSBarry Smith /* 504e2e64c6bSBarry Smith These are defined to be empty for when error checking is turned off, with ./configure --with-errorchecking=0 505f621e05eSBarry Smith */ 506f621e05eSBarry Smith 5074b209cf6SBarry Smith #define SETERRQ(c,n,s) 5084b209cf6SBarry Smith #define SETERRQ1(c,n,s,a1) 5094b209cf6SBarry Smith #define SETERRQ2(c,n,s,a1,a2) 5104b209cf6SBarry Smith #define SETERRQ3(c,n,s,a1,a2,a3) 5114b209cf6SBarry Smith #define SETERRQ4(c,n,s,a1,a2,a3,a4) 5124b209cf6SBarry Smith #define SETERRQ5(c,n,s,a1,a2,a3,a4,a5) 5134b209cf6SBarry Smith #define SETERRQ6(c,n,s,a1,a2,a3,a4,a5,a6) 5144ef524e9SStefano Zampini #define SETERRQ7(c,n,s,a1,a2,a3,a4,a5,a6,a7) 5154ef524e9SStefano Zampini #define SETERRQ8(c,n,s,a1,a2,a3,a4,a5,a6,a7,a8) 5164b209cf6SBarry Smith #define SETERRABORT(comm,n,s) 51785614651SBarry Smith 5184f227f7cSBarry Smith #define CHKERRQ(n) ; 5191ee4faa0SMatthew Knepley #define CHKERRABORT(comm,n) ; 5201ee4faa0SMatthew Knepley #define CHKERRCONTINUE(n) ; 52185614651SBarry Smith #define CHKMEMQ ; 52285614651SBarry Smith 5238cabf42eSMatthew G Knepley #ifdef PETSC_CLANGUAGE_CXX 5248cabf42eSMatthew G Knepley #define CHKERRXX(n) ; 5258cabf42eSMatthew G Knepley #endif 5268cabf42eSMatthew G Knepley 527f8e50935SSatish Balay #endif /* PETSC_USE_ERRORCHECKING */ 52854a8ef01SBarry Smith 529668f157eSBarry Smith /*E 530668f157eSBarry Smith PetscErrorType - passed to the PETSc error handling routines indicating if this is the first or a later call to the error handlers 531668f157eSBarry Smith 532668f157eSBarry Smith Level: advanced 533668f157eSBarry Smith 534d736bfebSBarry Smith PETSC_ERROR_IN_CXX indicates the error was detected in C++ and an exception should be generated 535d736bfebSBarry Smith 53661b0d812SBarry Smith Developer Notes: This is currently used to decide when to print the detailed information about the run in PetscTraceBackErrorHandler() 537668f157eSBarry Smith 538d736bfebSBarry Smith .seealso: PetscError(), SETERRXX() 539668f157eSBarry Smith E*/ 540d736bfebSBarry Smith typedef enum {PETSC_ERROR_INITIAL=0,PETSC_ERROR_REPEAT=1,PETSC_ERROR_IN_CXX = 2} PetscErrorType; 5414b209cf6SBarry Smith 542eb9e708aSLisandro Dalcin #if defined(__clang_analyzer__) 543eb9e708aSLisandro Dalcin __attribute__((analyzer_noreturn)) 544eb9e708aSLisandro Dalcin #endif 545eb9e708aSLisandro Dalcin PETSC_EXTERN PetscErrorCode PetscError(MPI_Comm,int,const char*,const char*,PetscErrorCode,PetscErrorType,const char*,...); 546eb9e708aSLisandro Dalcin 547014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscErrorPrintfInitialize(void); 548014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscErrorMessage(int,const char*[],char **); 549efca3c55SSatish Balay PETSC_EXTERN PetscErrorCode PetscTraceBackErrorHandler(MPI_Comm,int,const char*,const char*,PetscErrorCode,PetscErrorType,const char*,void*); 550efca3c55SSatish Balay PETSC_EXTERN PetscErrorCode PetscIgnoreErrorHandler(MPI_Comm,int,const char*,const char*,PetscErrorCode,PetscErrorType,const char*,void*); 551efca3c55SSatish Balay PETSC_EXTERN PetscErrorCode PetscEmacsClientErrorHandler(MPI_Comm,int,const char*,const char*,PetscErrorCode,PetscErrorType,const char*,void*); 552efca3c55SSatish Balay PETSC_EXTERN PetscErrorCode PetscMPIAbortErrorHandler(MPI_Comm,int,const char*,const char*,PetscErrorCode,PetscErrorType,const char*,void*); 553efca3c55SSatish Balay PETSC_EXTERN PetscErrorCode PetscAbortErrorHandler(MPI_Comm,int,const char*,const char*,PetscErrorCode,PetscErrorType,const char*,void*); 554efca3c55SSatish Balay PETSC_EXTERN PetscErrorCode PetscAttachDebuggerErrorHandler(MPI_Comm,int,const char*,const char*,PetscErrorCode,PetscErrorType,const char*,void*); 555efca3c55SSatish Balay PETSC_EXTERN PetscErrorCode PetscReturnErrorHandler(MPI_Comm,int,const char*,const char*,PetscErrorCode,PetscErrorType,const char*,void*); 556efca3c55SSatish Balay PETSC_EXTERN PetscErrorCode PetscPushErrorHandler(PetscErrorCode (*handler)(MPI_Comm,int,const char*,const char*,PetscErrorCode,PetscErrorType,const char*,void*),void*); 557014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscPopErrorHandler(void); 5588d359177SBarry Smith PETSC_EXTERN PetscErrorCode PetscSignalHandlerDefault(int,void*); 559014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscPushSignalHandler(PetscErrorCode (*)(int,void *),void*); 560014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscPopSignalHandler(void); 56128559dc8SJed Brown PETSC_EXTERN PetscErrorCode PetscCheckPointerSetIntensity(PetscInt); 562329f5518SBarry Smith 563639ff905SBarry Smith /*MC 564639ff905SBarry Smith PetscErrorPrintf - Prints error messages. 565639ff905SBarry Smith 566639ff905SBarry Smith Synopsis: 567aaa7dc30SBarry Smith #include <petscsys.h> 568639ff905SBarry Smith PetscErrorCode (*PetscErrorPrintf)(const char format[],...); 569639ff905SBarry Smith 570639ff905SBarry Smith Not Collective 571639ff905SBarry Smith 572639ff905SBarry Smith Input Parameters: 573639ff905SBarry Smith . format - the usual printf() format string 574639ff905SBarry Smith 575639ff905SBarry Smith Options Database Keys: 5761957e957SBarry Smith + -error_output_stdout - cause error messages to be printed to stdout instead of the (default) stderr 577e1bc860dSBarry Smith - -error_output_none - to turn off all printing of error messages (does not change the way the error is handled.) 578639ff905SBarry Smith 579639ff905SBarry Smith Notes: Use 580639ff905SBarry Smith $ PetscErrorPrintf = PetscErrorPrintfNone; to turn off all printing of error messages (does not change the way the 581639ff905SBarry Smith $ error is handled.) and 5821957e957SBarry Smith $ PetscErrorPrintf = PetscErrorPrintfDefault; to turn it back on or you can use your own function 583639ff905SBarry Smith 584639ff905SBarry Smith Use 585639ff905SBarry Smith PETSC_STDERR = FILE* obtained from a file open etc. to have stderr printed to the file. 586639ff905SBarry Smith PETSC_STDOUT = FILE* obtained from a file open etc. to have stdout printed to the file. 587639ff905SBarry Smith 588639ff905SBarry Smith Use 589639ff905SBarry Smith PetscPushErrorHandler() to provide your own error handler that determines what kind of messages to print 590639ff905SBarry Smith 591639ff905SBarry Smith Level: developer 592639ff905SBarry Smith 593639ff905SBarry Smith Fortran Note: 594639ff905SBarry Smith This routine is not supported in Fortran. 595639ff905SBarry Smith 596639ff905SBarry Smith Concepts: error messages^printing 597639ff905SBarry Smith Concepts: printing^error messages 598639ff905SBarry Smith 599639ff905SBarry Smith .seealso: PetscFPrintf(), PetscSynchronizedPrintf(), PetscHelpPrintf(), PetscPrintf(), PetscErrorHandlerPush(), PetscVFPrintf(), PetscHelpPrintf() 600639ff905SBarry Smith M*/ 601639ff905SBarry Smith PETSC_EXTERN PetscErrorCode (*PetscErrorPrintf)(const char[],...); 602639ff905SBarry Smith 603329f5518SBarry Smith typedef enum {PETSC_FP_TRAP_OFF=0,PETSC_FP_TRAP_ON=1} PetscFPTrap; 604014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSetFPTrap(PetscFPTrap); 605014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscFPTrapPush(PetscFPTrap); 606014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscFPTrapPop(void); 60754a8ef01SBarry Smith 6083a40ed3dSBarry Smith /* 6093a40ed3dSBarry Smith Allows the code to build a stack frame as it runs 6103a40ed3dSBarry Smith */ 6113a40ed3dSBarry Smith 61299cd645aSJed Brown #define PETSCSTACKSIZE 64 613184914b5SBarry Smith 6143a40ed3dSBarry Smith typedef struct { 6150e33f6ddSBarry Smith const char *function[PETSCSTACKSIZE]; 6160e33f6ddSBarry Smith const char *file[PETSCSTACKSIZE]; 617184914b5SBarry Smith int line[PETSCSTACKSIZE]; 618a8d2bbe5SBarry Smith PetscBool petscroutine[PETSCSTACKSIZE]; 619184914b5SBarry Smith int currentsize; 620a2f94806SJed Brown int hotdepth; 6213a40ed3dSBarry Smith } PetscStack; 6223a40ed3dSBarry Smith 6231f46d60fSShri Abhyankar PETSC_EXTERN PetscStack *petscstack; 624184914b5SBarry Smith 6256f5c2d7aSBarry Smith PetscErrorCode PetscStackCopy(PetscStack*,PetscStack*); 6266f5c2d7aSBarry Smith PetscErrorCode PetscStackPrint(PetscStack *,FILE*); 6272d7c6352SJed Brown #if defined(PETSC_USE_DEBUG) 628dbf62e16SBarry Smith PETSC_STATIC_INLINE PetscBool PetscStackActive(void) 629dbf62e16SBarry Smith { 6305c25fcd7SBarry Smith return(petscstack ? PETSC_TRUE : PETSC_FALSE); 631dbf62e16SBarry Smith } 6323a40ed3dSBarry Smith 633441dd030SJed Brown /* Stack handling is based on the following two "NoCheck" macros. These should only be called directly by other error 634441dd030SJed Brown * handling macros. We record the line of the call, which may or may not be the location of the definition. But is at 635441dd030SJed Brown * least more useful than "unknown" because it can distinguish multiple calls from the same function. 636441dd030SJed Brown */ 637441dd030SJed Brown 638a2f94806SJed Brown #define PetscStackPushNoCheck(funct,petsc_routine,hot) \ 639441dd030SJed Brown do { \ 640e04113cfSBarry Smith PetscStackSAWsTakeAccess(); \ 6415c25fcd7SBarry Smith if (petscstack && (petscstack->currentsize < PETSCSTACKSIZE)) { \ 6425c25fcd7SBarry Smith petscstack->function[petscstack->currentsize] = funct; \ 6435c25fcd7SBarry Smith petscstack->file[petscstack->currentsize] = __FILE__; \ 6445c25fcd7SBarry Smith petscstack->line[petscstack->currentsize] = __LINE__; \ 6455c25fcd7SBarry Smith petscstack->petscroutine[petscstack->currentsize] = petsc_routine; \ 6465c25fcd7SBarry Smith petscstack->currentsize++; \ 647441dd030SJed Brown } \ 6485c25fcd7SBarry Smith if (petscstack) { \ 6495c25fcd7SBarry Smith petscstack->hotdepth += (hot || petscstack->hotdepth); \ 650a2f94806SJed Brown } \ 651e04113cfSBarry Smith PetscStackSAWsGrantAccess(); \ 652441dd030SJed Brown } while (0) 653441dd030SJed Brown 654441dd030SJed Brown #define PetscStackPopNoCheck \ 6555c25fcd7SBarry Smith do { \ 656e04113cfSBarry Smith PetscStackSAWsTakeAccess(); \ 6575c25fcd7SBarry Smith if (petscstack && petscstack->currentsize > 0) { \ 6585c25fcd7SBarry Smith petscstack->currentsize--; \ 6595c25fcd7SBarry Smith petscstack->function[petscstack->currentsize] = 0; \ 6605c25fcd7SBarry Smith petscstack->file[petscstack->currentsize] = 0; \ 6615c25fcd7SBarry Smith petscstack->line[petscstack->currentsize] = 0; \ 6625c25fcd7SBarry Smith petscstack->petscroutine[petscstack->currentsize] = PETSC_FALSE;\ 663441dd030SJed Brown } \ 6645c25fcd7SBarry Smith if (petscstack) { \ 6655c25fcd7SBarry Smith petscstack->hotdepth = PetscMax(petscstack->hotdepth-1,0); \ 666a2f94806SJed Brown } \ 667e04113cfSBarry Smith PetscStackSAWsGrantAccess(); \ 668441dd030SJed Brown } while (0) 669441dd030SJed Brown 67030de9b25SBarry Smith /*MC 6711957e957SBarry Smith PetscFunctionBegin - First executable line of each PETSc function, used for error handling. Final 6721957e957SBarry Smith line of PETSc functions should be PetscFunctionReturn(0); 67330de9b25SBarry Smith 67430de9b25SBarry Smith Synopsis: 675aaa7dc30SBarry Smith #include <petscsys.h> 67630de9b25SBarry Smith void PetscFunctionBegin; 67730de9b25SBarry Smith 678eca87e8dSBarry Smith Not Collective 679eca87e8dSBarry Smith 68030de9b25SBarry Smith Usage: 68130de9b25SBarry Smith .vb 68230de9b25SBarry Smith int something; 68330de9b25SBarry Smith 68430de9b25SBarry Smith PetscFunctionBegin; 68530de9b25SBarry Smith .ve 68630de9b25SBarry Smith 68730de9b25SBarry Smith Notes: 6881957e957SBarry Smith Use PetscFunctionBeginUser for application codes. 6891957e957SBarry Smith 69030de9b25SBarry Smith Not available in Fortran 69130de9b25SBarry Smith 69230de9b25SBarry Smith Level: developer 69330de9b25SBarry Smith 6941957e957SBarry Smith .seealso: PetscFunctionReturn(), PetscFunctionBeginHot(), PetscFunctionBeginUser() 69530de9b25SBarry Smith 69630de9b25SBarry Smith .keywords: traceback, error handling 69730de9b25SBarry Smith M*/ 698441dd030SJed Brown #define PetscFunctionBegin do { \ 699a2f94806SJed Brown PetscStackPushNoCheck(PETSC_FUNCTION_NAME,PETSC_TRUE,PETSC_FALSE); \ 700a2f94806SJed Brown PetscCheck__FUNCT__(); \ 701a2f94806SJed Brown PetscRegister__FUNCT__(); \ 702a2f94806SJed Brown } while (0) 703a2f94806SJed Brown 704a2f94806SJed Brown /*MC 705a2f94806SJed Brown PetscFunctionBeginHot - Substitute for PetscFunctionBegin to be used in functions that are called in 706a2f94806SJed Brown performance-critical circumstances. Use of this function allows for lighter profiling by default. 707a2f94806SJed Brown 708a2f94806SJed Brown Synopsis: 709aaa7dc30SBarry Smith #include <petscsys.h> 710a2f94806SJed Brown void PetscFunctionBeginHot; 711a2f94806SJed Brown 712a2f94806SJed Brown Not Collective 713a2f94806SJed Brown 714a2f94806SJed Brown Usage: 715a2f94806SJed Brown .vb 716a2f94806SJed Brown int something; 717a2f94806SJed Brown 718a2f94806SJed Brown PetscFunctionBeginHot; 719a2f94806SJed Brown .ve 720a2f94806SJed Brown 721a2f94806SJed Brown Notes: 722a2f94806SJed Brown Not available in Fortran 723a2f94806SJed Brown 724a2f94806SJed Brown Level: developer 725a2f94806SJed Brown 726a2f94806SJed Brown .seealso: PetscFunctionBegin, PetscFunctionReturn() 727a2f94806SJed Brown 728a2f94806SJed Brown .keywords: traceback, error handling 729a2f94806SJed Brown M*/ 730a2f94806SJed Brown #define PetscFunctionBeginHot do { \ 731a2f94806SJed Brown PetscStackPushNoCheck(PETSC_FUNCTION_NAME,PETSC_TRUE,PETSC_TRUE); \ 73253c77d0aSJed Brown PetscCheck__FUNCT__(); \ 7332d53ad75SBarry Smith PetscRegister__FUNCT__(); \ 73453c77d0aSJed Brown } while (0) 73553c77d0aSJed Brown 736a8d2bbe5SBarry Smith /*MC 737a8d2bbe5SBarry Smith PetscFunctionBeginUser - First executable line of user provided PETSc routine 738a8d2bbe5SBarry Smith 739a8d2bbe5SBarry Smith Synopsis: 740aaa7dc30SBarry Smith #include <petscsys.h> 741a8d2bbe5SBarry Smith void PetscFunctionBeginUser; 742a8d2bbe5SBarry Smith 743a8d2bbe5SBarry Smith Not Collective 744a8d2bbe5SBarry Smith 745a8d2bbe5SBarry Smith Usage: 746a8d2bbe5SBarry Smith .vb 747a8d2bbe5SBarry Smith int something; 748a8d2bbe5SBarry Smith 749a8d2bbe5SBarry Smith PetscFunctionBegin; 750a8d2bbe5SBarry Smith .ve 751a8d2bbe5SBarry Smith 752a8d2bbe5SBarry Smith Notes: 7531957e957SBarry Smith Final line of PETSc functions should be PetscFunctionReturn(0) except for main(). 7541957e957SBarry Smith 755a8d2bbe5SBarry Smith Not available in Fortran 756a8d2bbe5SBarry Smith 757a2f94806SJed Brown Level: intermediate 758a8d2bbe5SBarry Smith 759a2f94806SJed Brown .seealso: PetscFunctionReturn(), PetscFunctionBegin, PetscFunctionBeginHot 760a8d2bbe5SBarry Smith 761a8d2bbe5SBarry Smith .keywords: traceback, error handling 762a8d2bbe5SBarry Smith M*/ 763a8d2bbe5SBarry Smith #define PetscFunctionBeginUser \ 764a8d2bbe5SBarry Smith do { \ 765a2f94806SJed Brown PetscStackPushNoCheck(PETSC_FUNCTION_NAME,PETSC_FALSE,PETSC_FALSE); \ 766a8d2bbe5SBarry Smith PetscCheck__FUNCT__(); \ 767a8d2bbe5SBarry Smith PetscRegister__FUNCT__(); \ 768a8d2bbe5SBarry Smith } while (0) 769a8d2bbe5SBarry Smith 770a8d2bbe5SBarry Smith 7712d53ad75SBarry Smith #if defined(PETSC_SERIALIZE_FUNCTIONS) 772af0996ceSBarry Smith #include <petsc/private/petscfptimpl.h> 7732d53ad75SBarry Smith /* 7742d53ad75SBarry Smith Registers the current function into the global function pointer to function name table 7752d53ad75SBarry Smith 7762d53ad75SBarry Smith Have to fix this to handle errors but cannot return error since used in PETSC_VIEWER_DRAW_() etc 7772d53ad75SBarry Smith */ 7782d53ad75SBarry Smith #define PetscRegister__FUNCT__() do { \ 7792d53ad75SBarry Smith static PetscBool __chked = PETSC_FALSE; \ 7802d53ad75SBarry Smith if (!__chked) {\ 7810298fd71SBarry Smith void *ptr; PetscDLSym(NULL,__FUNCT__,&ptr);\ 7822d53ad75SBarry Smith __chked = PETSC_TRUE;\ 7832d53ad75SBarry Smith }} while (0) 7842d53ad75SBarry Smith #else 7852d53ad75SBarry Smith #define PetscRegister__FUNCT__() 7862d53ad75SBarry Smith #endif 7872d53ad75SBarry Smith 788573b0fb4SBarry Smith #define PetscCheck__FUNCT__() do { PetscBool _sc1,_sc2; \ 789573b0fb4SBarry Smith PetscStrcmpNoError(PETSC_FUNCTION_NAME,__FUNCT__,&_sc1);\ 790573b0fb4SBarry Smith PetscStrcmpNoError(__FUNCT__,"User provided function",&_sc2);\ 791573b0fb4SBarry Smith if (!_sc1 && !_sc2) { \ 792e9f0693fSJed Brown printf("%s:%d: __FUNCT__=\"%s\" does not agree with %s=\"%s\"\n",__FILE__,__LINE__,__FUNCT__,PetscStringize(PETSC_FUNCTION_NAME),PETSC_FUNCTION_NAME); \ 79353c77d0aSJed Brown } \ 79453c77d0aSJed Brown } while (0) 7953a40ed3dSBarry Smith 7965cd90555SBarry Smith #define PetscStackPush(n) \ 79761d886c9SShri Abhyankar do { \ 798a2f94806SJed Brown PetscStackPushNoCheck(n,PETSC_FALSE,PETSC_FALSE); \ 79915681b3cSBarry Smith CHKMEMQ; \ 80015681b3cSBarry Smith } while (0) 8013a40ed3dSBarry Smith 802d64ed03dSBarry Smith #define PetscStackPop \ 803441dd030SJed Brown do { \ 804441dd030SJed Brown CHKMEMQ; \ 805441dd030SJed Brown PetscStackPopNoCheck; \ 80615681b3cSBarry Smith } while (0) 807d64ed03dSBarry Smith 80830de9b25SBarry Smith /*MC 80930de9b25SBarry Smith PetscFunctionReturn - Last executable line of each PETSc function 81030de9b25SBarry Smith used for error handling. Replaces return() 81130de9b25SBarry Smith 81230de9b25SBarry Smith Synopsis: 813aaa7dc30SBarry Smith #include <petscsys.h> 81430de9b25SBarry Smith void PetscFunctionReturn(0); 81530de9b25SBarry Smith 816eca87e8dSBarry Smith Not Collective 817eca87e8dSBarry Smith 81830de9b25SBarry Smith Usage: 81930de9b25SBarry Smith .vb 82030de9b25SBarry Smith .... 82130de9b25SBarry Smith PetscFunctionReturn(0); 82230de9b25SBarry Smith } 82330de9b25SBarry Smith .ve 82430de9b25SBarry Smith 82530de9b25SBarry Smith Notes: 82630de9b25SBarry Smith Not available in Fortran 82730de9b25SBarry Smith 82830de9b25SBarry Smith Level: developer 82930de9b25SBarry Smith 83030de9b25SBarry Smith .seealso: PetscFunctionBegin() 83130de9b25SBarry Smith 83230de9b25SBarry Smith .keywords: traceback, error handling 83330de9b25SBarry Smith M*/ 8345cd90555SBarry Smith #define PetscFunctionReturn(a) \ 8358246ba0dSJed Brown do { \ 836441dd030SJed Brown PetscStackPopNoCheck; \ 8378246ba0dSJed Brown return(a);} while (0) 838d64ed03dSBarry Smith 839ff94ddecSSatish Balay #define PetscFunctionReturnVoid() \ 8408246ba0dSJed Brown do { \ 841441dd030SJed Brown PetscStackPopNoCheck; \ 8428246ba0dSJed Brown return;} while (0) 84376386721SLisandro Dalcin 8446d385327SIbrahima Ba #else 8456d385327SIbrahima Ba 846c82b4e47SJed Brown PETSC_STATIC_INLINE PetscBool PetscStackActive(void) {return PETSC_FALSE;} 847a2f94806SJed Brown #define PetscStackPushNoCheck(funct,petsc_routine,hot) do {} while (0) 848441dd030SJed Brown #define PetscStackPopNoCheck do {} while (0) 8493a40ed3dSBarry Smith #define PetscFunctionBegin 8500bdf7c52SPeter Brune #define PetscFunctionBeginUser 851a2f94806SJed Brown #define PetscFunctionBeginHot 8523a40ed3dSBarry Smith #define PetscFunctionReturn(a) return(a) 8535665465eSBarry Smith #define PetscFunctionReturnVoid() return 854812af9f3SBarry Smith #define PetscStackPop CHKMEMQ 855812af9f3SBarry Smith #define PetscStackPush(f) CHKMEMQ 8563a40ed3dSBarry Smith 8573a40ed3dSBarry Smith #endif 8583a40ed3dSBarry Smith 859eb6b5d47SBarry Smith /* 860eb6b5d47SBarry Smith PetscStackCall - Calls an external library routine or user function after pushing the name of the routine on the stack. 861eb6b5d47SBarry Smith 862eb6b5d47SBarry Smith Input Parameters: 863eb6b5d47SBarry Smith + name - string that gives the name of the function being called 864fd3f9acdSBarry Smith - routine - actual call to the routine, including ierr = and CHKERRQ(ierr); 865fd3f9acdSBarry Smith 866dbf62e16SBarry Smith Note: Often one should use PetscStackCallStandard() instead. This routine is intended for external library routines that DO NOT return error codes 867eb6b5d47SBarry Smith 868eb6b5d47SBarry 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. 869eb6b5d47SBarry Smith 870fd3f9acdSBarry Smith 871fd3f9acdSBarry Smith 872eb6b5d47SBarry Smith */ 87330ecc5abSKarl Rupp #define PetscStackCall(name,routine) do { PetscStackPush(name);routine;PetscStackPop; } while(0) 874eb6b5d47SBarry Smith 875fd3f9acdSBarry Smith /* 876fd3f9acdSBarry Smith PetscStackCallStandard - Calls an external library routine after pushing the name of the routine on the stack. 877fd3f9acdSBarry Smith 878fd3f9acdSBarry Smith Input Parameters: 879fd3f9acdSBarry Smith + func- name of the routine 880fd3f9acdSBarry Smith - args - arguments to the routine surrounded by () 881fd3f9acdSBarry Smith 882dbf62e16SBarry Smith Notes: This is intended for external package routines that return error codes. Use PetscStackCall() for those that do not. 883dbf62e16SBarry Smith 884dbf62e16SBarry 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. 885fd3f9acdSBarry Smith 886fd3f9acdSBarry Smith */ 887fd3f9acdSBarry Smith #define PetscStackCallStandard(func,args) do { \ 888fd3f9acdSBarry Smith PetscStackPush(#func);ierr = func args;PetscStackPop; if (ierr) SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_LIB,"Error in %s()",#func); \ 889fd3f9acdSBarry Smith } while (0) 890fd3f9acdSBarry Smith 891014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscStackCreate(void); 892639ff905SBarry Smith PETSC_EXTERN PetscErrorCode PetscStackView(FILE*); 893014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscStackDestroy(void); 89406d1fe2cSBarry Smith 89506d1fe2cSBarry Smith #endif 896