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 7059aaf355SLisandro Dalcin #define PetscStringizeArg(a) #a 7159aaf355SLisandro Dalcin #define PetscStringize(a) PetscStringizeArg(a) 72330cf3c9SBarry Smith 73e8b7e333SSatish Balay #if defined(PETSC_USE_ERRORCHECKING) 74e8b7e333SSatish Balay 7530de9b25SBarry Smith /*MC 761957e957SBarry Smith SETERRQ - Macro to be called when an error has been detected, 7730de9b25SBarry Smith 7830de9b25SBarry Smith Synopsis: 79aaa7dc30SBarry Smith #include <petscsys.h> 80e7e72b3dSBarry Smith PetscErrorCode SETERRQ(MPI_Comm comm,PetscErrorCode errorcode,char *message) 8130de9b25SBarry Smith 82eca87e8dSBarry Smith Not Collective 8330de9b25SBarry Smith 8430de9b25SBarry Smith Input Parameters: 85*fa190f98SMatthew G. Knepley + comm - A communicator, so that the error can be collective 86*fa190f98SMatthew G. Knepley . errorcode - nonzero error code, see the list of standard error codes in include/petscerror.h 8730de9b25SBarry Smith - message - error message 8830de9b25SBarry Smith 8930de9b25SBarry Smith Level: beginner 9030de9b25SBarry Smith 9130de9b25SBarry Smith Notes: 9230de9b25SBarry Smith Once the error handler is called the calling function is then returned from with the given error code. 9330de9b25SBarry Smith 9430de9b25SBarry Smith See SETERRQ1(), SETERRQ2(), SETERRQ3() for versions that take arguments 9530de9b25SBarry Smith 9658ebbce7SBarry Smith In Fortran MPI_Abort() is always called 9730de9b25SBarry Smith 9830de9b25SBarry Smith Experienced users can set the error handler with PetscPushErrorHandler(). 9930de9b25SBarry Smith 10030de9b25SBarry Smith Concepts: error^setting condition 10130de9b25SBarry Smith 10291d3bdf4SKris Buschelman .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), CHKERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2(), SETERRQ3() 10330de9b25SBarry Smith M*/ 104efca3c55SSatish Balay #define SETERRQ(comm,n,s) return PetscError(comm,__LINE__,PETSC_FUNCTION_NAME,__FILE__,n,PETSC_ERROR_INITIAL,s) 10530de9b25SBarry Smith 10630de9b25SBarry Smith /*MC 10730de9b25SBarry Smith SETERRQ1 - Macro that is called when an error has been detected, 10830de9b25SBarry Smith 10930de9b25SBarry Smith Synopsis: 110aaa7dc30SBarry Smith #include <petscsys.h> 111e32f2f54SBarry Smith PetscErrorCode SETERRQ1(MPI_Comm comm,PetscErrorCode errorcode,char *formatmessage,arg) 11230de9b25SBarry Smith 113eca87e8dSBarry Smith Not Collective 11430de9b25SBarry Smith 11530de9b25SBarry Smith Input Parameters: 116*fa190f98SMatthew G. Knepley + comm - A communicator, so that the error can be collective 117*fa190f98SMatthew G. Knepley . errorcode - nonzero error code, see the list of standard error codes in include/petscerror.h 11830de9b25SBarry Smith . message - error message in the printf format 11930de9b25SBarry Smith - arg - argument (for example an integer, string or double) 12030de9b25SBarry Smith 12130de9b25SBarry Smith Level: beginner 12230de9b25SBarry Smith 12330de9b25SBarry Smith Notes: 12430de9b25SBarry Smith Once the error handler is called the calling function is then returned from with the given error code. 12530de9b25SBarry Smith 12630de9b25SBarry Smith Experienced users can set the error handler with PetscPushErrorHandler(). 12730de9b25SBarry Smith 12830de9b25SBarry Smith Concepts: error^setting condition 12930de9b25SBarry Smith 13091d3bdf4SKris Buschelman .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), CHKERRQ(), CHKMEMQ, SETERRQ(), SETERRQ2(), SETERRQ3() 13130de9b25SBarry Smith M*/ 132efca3c55SSatish Balay #define SETERRQ1(comm,n,s,a1) return PetscError(comm,__LINE__,PETSC_FUNCTION_NAME,__FILE__,n,PETSC_ERROR_INITIAL,s,a1) 13330de9b25SBarry Smith 13430de9b25SBarry Smith /*MC 13530de9b25SBarry Smith SETERRQ2 - Macro that is called when an error has been detected, 13630de9b25SBarry Smith 13730de9b25SBarry Smith Synopsis: 138aaa7dc30SBarry Smith #include <petscsys.h> 139*fa190f98SMatthew G. Knepley PetscErrorCode SETERRQ2(MPI_Comm comm,PetscErrorCode errorcode,char *formatmessage,arg1,arg2) 14030de9b25SBarry Smith 141eca87e8dSBarry Smith Not Collective 14230de9b25SBarry Smith 14330de9b25SBarry Smith Input Parameters: 144*fa190f98SMatthew G. Knepley + comm - A communicator, so that the error can be collective 145*fa190f98SMatthew G. Knepley . errorcode - nonzero error code, see the list of standard error codes in include/petscerror.h 14630de9b25SBarry Smith . message - error message in the printf format 14730de9b25SBarry Smith . arg1 - argument (for example an integer, string or double) 14830de9b25SBarry Smith - arg2 - argument (for example an integer, string or double) 14930de9b25SBarry Smith 15030de9b25SBarry Smith Level: beginner 15130de9b25SBarry Smith 15230de9b25SBarry Smith Notes: 15330de9b25SBarry Smith Once the error handler is called the calling function is then returned from with the given error code. 15430de9b25SBarry Smith 15530de9b25SBarry Smith Experienced users can set the error handler with PetscPushErrorHandler(). 15630de9b25SBarry Smith 15730de9b25SBarry Smith Concepts: error^setting condition 15830de9b25SBarry Smith 1596024bd2cSBarry Smith .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), CHKERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ3() 16030de9b25SBarry Smith M*/ 161efca3c55SSatish Balay #define SETERRQ2(comm,n,s,a1,a2) return PetscError(comm,__LINE__,PETSC_FUNCTION_NAME,__FILE__,n,PETSC_ERROR_INITIAL,s,a1,a2) 16230de9b25SBarry Smith 16330de9b25SBarry Smith /*MC 16430de9b25SBarry Smith SETERRQ3 - Macro that is called when an error has been detected, 16530de9b25SBarry Smith 16630de9b25SBarry Smith Synopsis: 167aaa7dc30SBarry Smith #include <petscsys.h> 168*fa190f98SMatthew G. Knepley PetscErrorCode SETERRQ3(MPI_Comm comm,PetscErrorCode errorcode,char *formatmessage,arg1,arg2,arg3) 16930de9b25SBarry Smith 170eca87e8dSBarry Smith Not Collective 17130de9b25SBarry Smith 17230de9b25SBarry Smith Input Parameters: 173*fa190f98SMatthew G. Knepley + comm - A communicator, so that the error can be collective 174*fa190f98SMatthew G. Knepley . errorcode - nonzero error code, see the list of standard error codes in include/petscerror.h 17530de9b25SBarry Smith . message - error message in the printf format 17630de9b25SBarry Smith . arg1 - argument (for example an integer, string or double) 17730de9b25SBarry Smith . arg2 - argument (for example an integer, string or double) 17830de9b25SBarry Smith - arg3 - argument (for example an integer, string or double) 17930de9b25SBarry Smith 18030de9b25SBarry Smith Level: beginner 18130de9b25SBarry Smith 18230de9b25SBarry Smith Notes: 18330de9b25SBarry Smith Once the error handler is called the calling function is then returned from with the given error code. 18430de9b25SBarry Smith 185f621e05eSBarry Smith There are also versions for 4, 5, 6 and 7 arguments. 186f621e05eSBarry Smith 18730de9b25SBarry Smith Experienced users can set the error handler with PetscPushErrorHandler(). 18830de9b25SBarry Smith 18930de9b25SBarry Smith Concepts: error^setting condition 19030de9b25SBarry Smith 1916024bd2cSBarry Smith .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), CHKERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2() 19230de9b25SBarry Smith M*/ 193efca3c55SSatish 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) 19430de9b25SBarry Smith 195*fa190f98SMatthew G. Knepley /*MC 196*fa190f98SMatthew G. Knepley SETERRQ4 - Macro that is called when an error has been detected, 197*fa190f98SMatthew G. Knepley 198*fa190f98SMatthew G. Knepley Synopsis: 199*fa190f98SMatthew G. Knepley #include <petscsys.h> 200*fa190f98SMatthew G. Knepley PetscErrorCode SETERRQ4(MPI_Comm comm,PetscErrorCode errorcode,char *formatmessage,arg1,arg2,arg3) 201*fa190f98SMatthew G. Knepley 202*fa190f98SMatthew G. Knepley Not Collective 203*fa190f98SMatthew G. Knepley 204*fa190f98SMatthew G. Knepley Input Parameters: 205*fa190f98SMatthew G. Knepley + comm - A communicator, so that the error can be collective 206*fa190f98SMatthew G. Knepley . errorcode - nonzero error code, see the list of standard error codes in include/petscerror.h 207*fa190f98SMatthew G. Knepley . message - error message in the printf format 208*fa190f98SMatthew G. Knepley . arg1 - argument (for example an integer, string or double) 209*fa190f98SMatthew G. Knepley . arg2 - argument (for example an integer, string or double) 210*fa190f98SMatthew G. Knepley . arg3 - argument (for example an integer, string or double) 211*fa190f98SMatthew G. Knepley - arg4 - argument (for example an integer, string or double) 212*fa190f98SMatthew G. Knepley 213*fa190f98SMatthew G. Knepley Level: beginner 214*fa190f98SMatthew G. Knepley 215*fa190f98SMatthew G. Knepley Notes: 216*fa190f98SMatthew G. Knepley Once the error handler is called the calling function is then returned from with the given error code. 217*fa190f98SMatthew G. Knepley 218*fa190f98SMatthew G. Knepley There are also versions for 4, 5, 6 and 7 arguments. 219*fa190f98SMatthew G. Knepley 220*fa190f98SMatthew G. Knepley Experienced users can set the error handler with PetscPushErrorHandler(). 221*fa190f98SMatthew G. Knepley 222*fa190f98SMatthew G. Knepley Concepts: error^setting condition 223*fa190f98SMatthew G. Knepley 224*fa190f98SMatthew G. Knepley .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), CHKERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2() 225*fa190f98SMatthew G. Knepley M*/ 226efca3c55SSatish 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) 227*fa190f98SMatthew G. Knepley 228*fa190f98SMatthew G. Knepley /*MC 229*fa190f98SMatthew G. Knepley SETERRQ5 - Macro that is called when an error has been detected, 230*fa190f98SMatthew G. Knepley 231*fa190f98SMatthew G. Knepley Synopsis: 232*fa190f98SMatthew G. Knepley #include <petscsys.h> 233*fa190f98SMatthew G. Knepley PetscErrorCode SETERRQ5(MPI_Comm comm,PetscErrorCode errorcode,char *formatmessage,arg1,arg2,arg3) 234*fa190f98SMatthew G. Knepley 235*fa190f98SMatthew G. Knepley Not Collective 236*fa190f98SMatthew G. Knepley 237*fa190f98SMatthew G. Knepley Input Parameters: 238*fa190f98SMatthew G. Knepley + comm - A communicator, so that the error can be collective 239*fa190f98SMatthew G. Knepley . errorcode - nonzero error code, see the list of standard error codes in include/petscerror.h 240*fa190f98SMatthew G. Knepley . message - error message in the printf format 241*fa190f98SMatthew G. Knepley . arg1 - argument (for example an integer, string or double) 242*fa190f98SMatthew G. Knepley . arg2 - argument (for example an integer, string or double) 243*fa190f98SMatthew G. Knepley . arg3 - argument (for example an integer, string or double) 244*fa190f98SMatthew G. Knepley . arg4 - argument (for example an integer, string or double) 245*fa190f98SMatthew G. Knepley - arg5 - argument (for example an integer, string or double) 246*fa190f98SMatthew G. Knepley 247*fa190f98SMatthew G. Knepley Level: beginner 248*fa190f98SMatthew G. Knepley 249*fa190f98SMatthew G. Knepley Notes: 250*fa190f98SMatthew G. Knepley Once the error handler is called the calling function is then returned from with the given error code. 251*fa190f98SMatthew G. Knepley 252*fa190f98SMatthew G. Knepley There are also versions for 4, 5, 6 and 7 arguments. 253*fa190f98SMatthew G. Knepley 254*fa190f98SMatthew G. Knepley Experienced users can set the error handler with PetscPushErrorHandler(). 255*fa190f98SMatthew G. Knepley 256*fa190f98SMatthew G. Knepley Concepts: error^setting condition 257*fa190f98SMatthew G. Knepley 258*fa190f98SMatthew G. Knepley .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), CHKERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2() 259*fa190f98SMatthew G. Knepley M*/ 260efca3c55SSatish 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) 261*fa190f98SMatthew G. Knepley 262*fa190f98SMatthew G. Knepley /*MC 263*fa190f98SMatthew G. Knepley SETERRQ6 - Macro that is called when an error has been detected, 264*fa190f98SMatthew G. Knepley 265*fa190f98SMatthew G. Knepley Synopsis: 266*fa190f98SMatthew G. Knepley #include <petscsys.h> 267*fa190f98SMatthew G. Knepley PetscErrorCode SETERRQ6(MPI_Comm comm,PetscErrorCode errorcode,char *formatmessage,arg1,arg2,arg3) 268*fa190f98SMatthew G. Knepley 269*fa190f98SMatthew G. Knepley Not Collective 270*fa190f98SMatthew G. Knepley 271*fa190f98SMatthew G. Knepley Input Parameters: 272*fa190f98SMatthew G. Knepley + comm - A communicator, so that the error can be collective 273*fa190f98SMatthew G. Knepley . errorcode - nonzero error code, see the list of standard error codes in include/petscerror.h 274*fa190f98SMatthew G. Knepley . message - error message in the printf format 275*fa190f98SMatthew G. Knepley . arg1 - argument (for example an integer, string or double) 276*fa190f98SMatthew G. Knepley . arg2 - argument (for example an integer, string or double) 277*fa190f98SMatthew G. Knepley . arg3 - argument (for example an integer, string or double) 278*fa190f98SMatthew G. Knepley . arg4 - argument (for example an integer, string or double) 279*fa190f98SMatthew G. Knepley . arg5 - argument (for example an integer, string or double) 280*fa190f98SMatthew G. Knepley - arg6 - argument (for example an integer, string or double) 281*fa190f98SMatthew G. Knepley 282*fa190f98SMatthew G. Knepley Level: beginner 283*fa190f98SMatthew G. Knepley 284*fa190f98SMatthew G. Knepley Notes: 285*fa190f98SMatthew G. Knepley Once the error handler is called the calling function is then returned from with the given error code. 286*fa190f98SMatthew G. Knepley 287*fa190f98SMatthew G. Knepley There are also versions for 4, 5, 6 and 7 arguments. 288*fa190f98SMatthew G. Knepley 289*fa190f98SMatthew G. Knepley Experienced users can set the error handler with PetscPushErrorHandler(). 290*fa190f98SMatthew G. Knepley 291*fa190f98SMatthew G. Knepley Concepts: error^setting condition 292*fa190f98SMatthew G. Knepley 293*fa190f98SMatthew G. Knepley .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), CHKERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2() 294*fa190f98SMatthew G. Knepley M*/ 295efca3c55SSatish 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) 296*fa190f98SMatthew G. Knepley 297*fa190f98SMatthew G. Knepley /*MC 298*fa190f98SMatthew G. Knepley SETERRQ7 - Macro that is called when an error has been detected, 299*fa190f98SMatthew G. Knepley 300*fa190f98SMatthew G. Knepley Synopsis: 301*fa190f98SMatthew G. Knepley #include <petscsys.h> 302*fa190f98SMatthew G. Knepley PetscErrorCode SETERRQ7(MPI_Comm comm,PetscErrorCode errorcode,char *formatmessage,arg1,arg2,arg3) 303*fa190f98SMatthew G. Knepley 304*fa190f98SMatthew G. Knepley Not Collective 305*fa190f98SMatthew G. Knepley 306*fa190f98SMatthew G. Knepley Input Parameters: 307*fa190f98SMatthew G. Knepley + comm - A communicator, so that the error can be collective 308*fa190f98SMatthew G. Knepley . errorcode - nonzero error code, see the list of standard error codes in include/petscerror.h 309*fa190f98SMatthew G. Knepley . message - error message in the printf format 310*fa190f98SMatthew G. Knepley . arg1 - argument (for example an integer, string or double) 311*fa190f98SMatthew G. Knepley . arg2 - argument (for example an integer, string or double) 312*fa190f98SMatthew G. Knepley . arg3 - argument (for example an integer, string or double) 313*fa190f98SMatthew G. Knepley . arg4 - argument (for example an integer, string or double) 314*fa190f98SMatthew G. Knepley . arg5 - argument (for example an integer, string or double) 315*fa190f98SMatthew G. Knepley . arg6 - argument (for example an integer, string or double) 316*fa190f98SMatthew G. Knepley - arg7 - argument (for example an integer, string or double) 317*fa190f98SMatthew G. Knepley 318*fa190f98SMatthew G. Knepley Level: beginner 319*fa190f98SMatthew G. Knepley 320*fa190f98SMatthew G. Knepley Notes: 321*fa190f98SMatthew G. Knepley Once the error handler is called the calling function is then returned from with the given error code. 322*fa190f98SMatthew G. Knepley 323*fa190f98SMatthew G. Knepley There are also versions for 4, 5, 6 and 7 arguments. 324*fa190f98SMatthew G. Knepley 325*fa190f98SMatthew G. Knepley Experienced users can set the error handler with PetscPushErrorHandler(). 326*fa190f98SMatthew G. Knepley 327*fa190f98SMatthew G. Knepley Concepts: error^setting condition 328*fa190f98SMatthew G. Knepley 329*fa190f98SMatthew G. Knepley .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), CHKERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2() 330*fa190f98SMatthew G. Knepley M*/ 331efca3c55SSatish 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) 332*fa190f98SMatthew G. Knepley 333*fa190f98SMatthew G. Knepley /*MC 334*fa190f98SMatthew G. Knepley SETERRQ8 - Macro that is called when an error has been detected, 335*fa190f98SMatthew G. Knepley 336*fa190f98SMatthew G. Knepley Synopsis: 337*fa190f98SMatthew G. Knepley #include <petscsys.h> 338*fa190f98SMatthew G. Knepley PetscErrorCode SETERRQ8(MPI_Comm comm,PetscErrorCode errorcode,char *formatmessage,arg1,arg2,arg3) 339*fa190f98SMatthew G. Knepley 340*fa190f98SMatthew G. Knepley Not Collective 341*fa190f98SMatthew G. Knepley 342*fa190f98SMatthew G. Knepley Input Parameters: 343*fa190f98SMatthew G. Knepley + comm - A communicator, so that the error can be collective 344*fa190f98SMatthew G. Knepley . errorcode - nonzero error code, see the list of standard error codes in include/petscerror.h 345*fa190f98SMatthew G. Knepley . message - error message in the printf format 346*fa190f98SMatthew G. Knepley . arg1 - argument (for example an integer, string or double) 347*fa190f98SMatthew G. Knepley . arg2 - argument (for example an integer, string or double) 348*fa190f98SMatthew G. Knepley . arg3 - argument (for example an integer, string or double) 349*fa190f98SMatthew G. Knepley . arg4 - argument (for example an integer, string or double) 350*fa190f98SMatthew G. Knepley . arg5 - argument (for example an integer, string or double) 351*fa190f98SMatthew G. Knepley . arg6 - argument (for example an integer, string or double) 352*fa190f98SMatthew G. Knepley . arg7 - argument (for example an integer, string or double) 353*fa190f98SMatthew G. Knepley - arg8 - argument (for example an integer, string or double) 354*fa190f98SMatthew G. Knepley 355*fa190f98SMatthew G. Knepley Level: beginner 356*fa190f98SMatthew G. Knepley 357*fa190f98SMatthew G. Knepley Notes: 358*fa190f98SMatthew G. Knepley Once the error handler is called the calling function is then returned from with the given error code. 359*fa190f98SMatthew G. Knepley 360*fa190f98SMatthew G. Knepley There are also versions for 4, 5, 6 and 7 arguments. 361*fa190f98SMatthew G. Knepley 362*fa190f98SMatthew G. Knepley Experienced users can set the error handler with PetscPushErrorHandler(). 363*fa190f98SMatthew G. Knepley 364*fa190f98SMatthew G. Knepley Concepts: error^setting condition 365*fa190f98SMatthew G. Knepley 366*fa190f98SMatthew G. Knepley .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), CHKERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2() 367*fa190f98SMatthew G. Knepley M*/ 368efca3c55SSatish 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) 369*fa190f98SMatthew G. Knepley 370*fa190f98SMatthew G. Knepley /*MC 371*fa190f98SMatthew G. Knepley SETERRABORT - Macro that can be called when an error has been detected, 372*fa190f98SMatthew G. Knepley 373*fa190f98SMatthew G. Knepley Synopsis: 374*fa190f98SMatthew G. Knepley #include <petscsys.h> 375*fa190f98SMatthew G. Knepley PetscErrorCode SETERRABORT(MPI_Comm comm,PetscErrorCode errorcode,char *message) 376*fa190f98SMatthew G. Knepley 377*fa190f98SMatthew G. Knepley Not Collective 378*fa190f98SMatthew G. Knepley 379*fa190f98SMatthew G. Knepley Input Parameters: 380*fa190f98SMatthew G. Knepley + comm - A communicator, so that the error can be collective 381*fa190f98SMatthew G. Knepley . errorcode - nonzero error code, see the list of standard error codes in include/petscerror.h 382*fa190f98SMatthew G. Knepley - message - error message in the printf format 383*fa190f98SMatthew G. Knepley 384*fa190f98SMatthew G. Knepley Level: beginner 385*fa190f98SMatthew G. Knepley 386*fa190f98SMatthew G. Knepley Notes: 387*fa190f98SMatthew G. Knepley This function just calls MPI_Abort(). 388*fa190f98SMatthew G. Knepley 389*fa190f98SMatthew G. Knepley Concepts: error^setting condition 390*fa190f98SMatthew G. Knepley 391*fa190f98SMatthew G. Knepley .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), CHKERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2() 392*fa190f98SMatthew G. Knepley M*/ 393efca3c55SSatish 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) 3949a00fa46SSatish Balay 39530de9b25SBarry Smith /*MC 39630de9b25SBarry Smith CHKERRQ - Checks error code, if non-zero it calls the error handler and then returns 39730de9b25SBarry Smith 39830de9b25SBarry Smith Synopsis: 399aaa7dc30SBarry Smith #include <petscsys.h> 400f4442326SMatthew Knepley PetscErrorCode CHKERRQ(PetscErrorCode errorcode) 40130de9b25SBarry Smith 402eca87e8dSBarry Smith Not Collective 40330de9b25SBarry Smith 40430de9b25SBarry Smith Input Parameters: 40530de9b25SBarry Smith . errorcode - nonzero error code, see the list of standard error codes in include/petscerror.h 40630de9b25SBarry Smith 40730de9b25SBarry Smith Level: beginner 40830de9b25SBarry Smith 40930de9b25SBarry Smith Notes: 41030de9b25SBarry Smith Once the error handler is called the calling function is then returned from with the given error code. 41130de9b25SBarry Smith 41230de9b25SBarry Smith Experienced users can set the error handler with PetscPushErrorHandler(). 4135324ea47SKris Buschelman 414fcecf507SKris Buschelman CHKERRQ(n) is fundamentally a macro replacement for 4155324ea47SKris Buschelman if (n) return(PetscError(...,n,...)); 4165324ea47SKris Buschelman 4175324ea47SKris Buschelman Although typical usage resembles "void CHKERRQ(PetscErrorCode)" as described above, for certain uses it is 4185324ea47SKris Buschelman highly inappropriate to use it in this manner as it invokes return(PetscErrorCode). In particular, 4195324ea47SKris Buschelman it cannot be used in functions which return(void) or any other datatype. In these types of functions, 42058ebbce7SBarry Smith you can use CHKERRV() which returns without an error code (bad idea since the error is ignored or 4215324ea47SKris Buschelman if (n) {PetscError(....); return(YourReturnType);} 4220298fd71SBarry Smith where you may pass back a NULL to indicate an error. You can also call CHKERRABORT(comm,n) to have 42358ebbce7SBarry Smith MPI_Abort() returned immediately. 42458ebbce7SBarry Smith 42558ebbce7SBarry Smith In Fortran MPI_Abort() is always called 42630de9b25SBarry Smith 42730de9b25SBarry Smith Concepts: error^setting condition 42830de9b25SBarry Smith 42991d3bdf4SKris Buschelman .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), SETERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2(), SETERRQ2() 43030de9b25SBarry Smith M*/ 431efca3c55SSatish Balay #define CHKERRQ(n) do {if (PetscUnlikely(n)) return PetscError(PETSC_COMM_SELF,__LINE__,PETSC_FUNCTION_NAME,__FILE__,n,PETSC_ERROR_REPEAT," ");} while (0) 43230de9b25SBarry Smith 433efca3c55SSatish 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) 434efca3c55SSatish 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) 435efca3c55SSatish Balay #define CHKERRCONTINUE(n) do {if (PetscUnlikely(n)) {PetscError(PETSC_COMM_SELF,__LINE__,PETSC_FUNCTION_NAME,__FILE__,n,PETSC_ERROR_REPEAT," ");}} while (0) 43685614651SBarry Smith 437fd705b32SMatthew Knepley #ifdef PETSC_CLANGUAGE_CXX 438fd705b32SMatthew Knepley 439cc26af49SMatthew Knepley /*MC 440cc26af49SMatthew Knepley CHKERRXX - Checks error code, if non-zero it calls the C++ error handler which throws an exception 441cc26af49SMatthew Knepley 442cc26af49SMatthew Knepley Synopsis: 443aaa7dc30SBarry Smith #include <petscsys.h> 444cc26af49SMatthew Knepley void CHKERRXX(PetscErrorCode errorcode) 445cc26af49SMatthew Knepley 446eca87e8dSBarry Smith Not Collective 447cc26af49SMatthew Knepley 448cc26af49SMatthew Knepley Input Parameters: 449cc26af49SMatthew Knepley . errorcode - nonzero error code, see the list of standard error codes in include/petscerror.h 450cc26af49SMatthew Knepley 451cc26af49SMatthew Knepley Level: beginner 452cc26af49SMatthew Knepley 453cc26af49SMatthew Knepley Notes: 454cc26af49SMatthew Knepley Once the error handler throws a ??? exception. 455cc26af49SMatthew Knepley 456cc26af49SMatthew Knepley You can use CHKERRV() which returns without an error code (bad idea since the error is ignored) 457cc26af49SMatthew Knepley or CHKERRABORT(comm,n) to have MPI_Abort() returned immediately. 458cc26af49SMatthew Knepley 459cc26af49SMatthew Knepley Concepts: error^setting condition 460cc26af49SMatthew Knepley 461cc26af49SMatthew Knepley .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), SETERRQ(), CHKERRQ(), CHKMEMQ 462cc26af49SMatthew Knepley M*/ 463efca3c55SSatish 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) 464fd705b32SMatthew Knepley 465fd705b32SMatthew Knepley #endif 466fd705b32SMatthew Knepley 46730de9b25SBarry Smith /*MC 46830de9b25SBarry Smith CHKMEMQ - Checks the memory for corruption, calls error handler if any is detected 46930de9b25SBarry Smith 47030de9b25SBarry Smith Synopsis: 471aaa7dc30SBarry Smith #include <petscsys.h> 47291d3bdf4SKris Buschelman CHKMEMQ; 47330de9b25SBarry Smith 474eca87e8dSBarry Smith Not Collective 475eca87e8dSBarry Smith 47630de9b25SBarry Smith Level: beginner 47730de9b25SBarry Smith 47830de9b25SBarry Smith Notes: 4791957e957SBarry Smith We highly recommend using valgrind http://www.mcs.anl.gov/petsc/documentation/faq.html#valgrind for finding memory problems. This is useful 4801957e957SBarry Smith on systems that do not have valgrind, but much much less useful. 4811957e957SBarry Smith 482ff002950SBarry Smith Must run with the option -malloc_debug to enable this option 48330de9b25SBarry Smith 48430de9b25SBarry Smith Once the error handler is called the calling function is then returned from with the given error code. 48530de9b25SBarry Smith 48630de9b25SBarry Smith By defaults prints location where memory that is corrupted was allocated. 48730de9b25SBarry Smith 488f621e05eSBarry Smith Use CHKMEMA for functions that return void 489f621e05eSBarry Smith 49030de9b25SBarry Smith Concepts: memory corruption 49130de9b25SBarry Smith 4926024bd2cSBarry Smith .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), SETERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2(), SETERRQ3(), 493ff002950SBarry Smith PetscMallocValidate() 49430de9b25SBarry Smith M*/ 495efca3c55SSatish Balay #define CHKMEMQ do {PetscErrorCode _7_ierr = PetscMallocValidate(__LINE__,PETSC_FUNCTION_NAME,__FILE__);CHKERRQ(_7_ierr);} while(0) 49685614651SBarry Smith 497efca3c55SSatish Balay #define CHKMEMA PetscMallocValidate(__LINE__,PETSC_FUNCTION_NAME,__FILE__) 498e68848bdSBarry Smith 499f8e50935SSatish Balay #else /* PETSC_USE_ERRORCHECKING */ 500f621e05eSBarry Smith 501f621e05eSBarry Smith /* 502e2e64c6bSBarry Smith These are defined to be empty for when error checking is turned off, with ./configure --with-errorchecking=0 503f621e05eSBarry Smith */ 504f621e05eSBarry Smith 5054b209cf6SBarry Smith #define SETERRQ(c,n,s) 5064b209cf6SBarry Smith #define SETERRQ1(c,n,s,a1) 5074b209cf6SBarry Smith #define SETERRQ2(c,n,s,a1,a2) 5084b209cf6SBarry Smith #define SETERRQ3(c,n,s,a1,a2,a3) 5094b209cf6SBarry Smith #define SETERRQ4(c,n,s,a1,a2,a3,a4) 5104b209cf6SBarry Smith #define SETERRQ5(c,n,s,a1,a2,a3,a4,a5) 5114b209cf6SBarry Smith #define SETERRQ6(c,n,s,a1,a2,a3,a4,a5,a6) 5124ef524e9SStefano Zampini #define SETERRQ7(c,n,s,a1,a2,a3,a4,a5,a6,a7) 5134ef524e9SStefano Zampini #define SETERRQ8(c,n,s,a1,a2,a3,a4,a5,a6,a7,a8) 5144b209cf6SBarry Smith #define SETERRABORT(comm,n,s) 51585614651SBarry Smith 5164f227f7cSBarry Smith #define CHKERRQ(n) ; 5171ee4faa0SMatthew Knepley #define CHKERRABORT(comm,n) ; 5181ee4faa0SMatthew Knepley #define CHKERRCONTINUE(n) ; 51985614651SBarry Smith #define CHKMEMQ ; 52085614651SBarry Smith 5218cabf42eSMatthew G Knepley #ifdef PETSC_CLANGUAGE_CXX 5228cabf42eSMatthew G Knepley #define CHKERRXX(n) ; 5238cabf42eSMatthew G Knepley #endif 5248cabf42eSMatthew G Knepley 525f8e50935SSatish Balay #endif /* PETSC_USE_ERRORCHECKING */ 52654a8ef01SBarry Smith 527668f157eSBarry Smith /*E 528668f157eSBarry Smith PetscErrorType - passed to the PETSc error handling routines indicating if this is the first or a later call to the error handlers 529668f157eSBarry Smith 530668f157eSBarry Smith Level: advanced 531668f157eSBarry Smith 532d736bfebSBarry Smith PETSC_ERROR_IN_CXX indicates the error was detected in C++ and an exception should be generated 533d736bfebSBarry Smith 53461b0d812SBarry Smith Developer Notes: This is currently used to decide when to print the detailed information about the run in PetscTraceBackErrorHandler() 535668f157eSBarry Smith 536d736bfebSBarry Smith .seealso: PetscError(), SETERRXX() 537668f157eSBarry Smith E*/ 538d736bfebSBarry Smith typedef enum {PETSC_ERROR_INITIAL=0,PETSC_ERROR_REPEAT=1,PETSC_ERROR_IN_CXX = 2} PetscErrorType; 5394b209cf6SBarry Smith 540eb9e708aSLisandro Dalcin #if defined(__clang_analyzer__) 541eb9e708aSLisandro Dalcin __attribute__((analyzer_noreturn)) 542eb9e708aSLisandro Dalcin #endif 543eb9e708aSLisandro Dalcin PETSC_EXTERN PetscErrorCode PetscError(MPI_Comm,int,const char*,const char*,PetscErrorCode,PetscErrorType,const char*,...); 544eb9e708aSLisandro Dalcin 545014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscErrorPrintfInitialize(void); 546014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscErrorMessage(int,const char*[],char **); 547efca3c55SSatish Balay PETSC_EXTERN PetscErrorCode PetscTraceBackErrorHandler(MPI_Comm,int,const char*,const char*,PetscErrorCode,PetscErrorType,const char*,void*); 548efca3c55SSatish Balay PETSC_EXTERN PetscErrorCode PetscIgnoreErrorHandler(MPI_Comm,int,const char*,const char*,PetscErrorCode,PetscErrorType,const char*,void*); 549efca3c55SSatish Balay PETSC_EXTERN PetscErrorCode PetscEmacsClientErrorHandler(MPI_Comm,int,const char*,const char*,PetscErrorCode,PetscErrorType,const char*,void*); 550efca3c55SSatish Balay PETSC_EXTERN PetscErrorCode PetscMPIAbortErrorHandler(MPI_Comm,int,const char*,const char*,PetscErrorCode,PetscErrorType,const char*,void*); 551efca3c55SSatish Balay PETSC_EXTERN PetscErrorCode PetscAbortErrorHandler(MPI_Comm,int,const char*,const char*,PetscErrorCode,PetscErrorType,const char*,void*); 552efca3c55SSatish Balay PETSC_EXTERN PetscErrorCode PetscAttachDebuggerErrorHandler(MPI_Comm,int,const char*,const char*,PetscErrorCode,PetscErrorType,const char*,void*); 553efca3c55SSatish Balay PETSC_EXTERN PetscErrorCode PetscReturnErrorHandler(MPI_Comm,int,const char*,const char*,PetscErrorCode,PetscErrorType,const char*,void*); 554efca3c55SSatish Balay PETSC_EXTERN PetscErrorCode PetscPushErrorHandler(PetscErrorCode (*handler)(MPI_Comm,int,const char*,const char*,PetscErrorCode,PetscErrorType,const char*,void*),void*); 555014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscPopErrorHandler(void); 5568d359177SBarry Smith PETSC_EXTERN PetscErrorCode PetscSignalHandlerDefault(int,void*); 557014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscPushSignalHandler(PetscErrorCode (*)(int,void *),void*); 558014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscPopSignalHandler(void); 55928559dc8SJed Brown PETSC_EXTERN PetscErrorCode PetscCheckPointerSetIntensity(PetscInt); 560329f5518SBarry Smith 561639ff905SBarry Smith /*MC 562639ff905SBarry Smith PetscErrorPrintf - Prints error messages. 563639ff905SBarry Smith 564639ff905SBarry Smith Synopsis: 565aaa7dc30SBarry Smith #include <petscsys.h> 566639ff905SBarry Smith PetscErrorCode (*PetscErrorPrintf)(const char format[],...); 567639ff905SBarry Smith 568639ff905SBarry Smith Not Collective 569639ff905SBarry Smith 570639ff905SBarry Smith Input Parameters: 571639ff905SBarry Smith . format - the usual printf() format string 572639ff905SBarry Smith 573639ff905SBarry Smith Options Database Keys: 5741957e957SBarry Smith + -error_output_stdout - cause error messages to be printed to stdout instead of the (default) stderr 575e1bc860dSBarry Smith - -error_output_none - to turn off all printing of error messages (does not change the way the error is handled.) 576639ff905SBarry Smith 577639ff905SBarry Smith Notes: Use 578639ff905SBarry Smith $ PetscErrorPrintf = PetscErrorPrintfNone; to turn off all printing of error messages (does not change the way the 579639ff905SBarry Smith $ error is handled.) and 5801957e957SBarry Smith $ PetscErrorPrintf = PetscErrorPrintfDefault; to turn it back on or you can use your own function 581639ff905SBarry Smith 582639ff905SBarry Smith Use 583639ff905SBarry Smith PETSC_STDERR = FILE* obtained from a file open etc. to have stderr printed to the file. 584639ff905SBarry Smith PETSC_STDOUT = FILE* obtained from a file open etc. to have stdout printed to the file. 585639ff905SBarry Smith 586639ff905SBarry Smith Use 587639ff905SBarry Smith PetscPushErrorHandler() to provide your own error handler that determines what kind of messages to print 588639ff905SBarry Smith 589639ff905SBarry Smith Level: developer 590639ff905SBarry Smith 591639ff905SBarry Smith Fortran Note: 592639ff905SBarry Smith This routine is not supported in Fortran. 593639ff905SBarry Smith 594639ff905SBarry Smith Concepts: error messages^printing 595639ff905SBarry Smith Concepts: printing^error messages 596639ff905SBarry Smith 597639ff905SBarry Smith .seealso: PetscFPrintf(), PetscSynchronizedPrintf(), PetscHelpPrintf(), PetscPrintf(), PetscErrorHandlerPush(), PetscVFPrintf(), PetscHelpPrintf() 598639ff905SBarry Smith M*/ 599639ff905SBarry Smith PETSC_EXTERN PetscErrorCode (*PetscErrorPrintf)(const char[],...); 600639ff905SBarry Smith 601329f5518SBarry Smith typedef enum {PETSC_FP_TRAP_OFF=0,PETSC_FP_TRAP_ON=1} PetscFPTrap; 602014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscSetFPTrap(PetscFPTrap); 603014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscFPTrapPush(PetscFPTrap); 604014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscFPTrapPop(void); 60554a8ef01SBarry Smith 6063a40ed3dSBarry Smith /* 6073a40ed3dSBarry Smith Allows the code to build a stack frame as it runs 6083a40ed3dSBarry Smith */ 6093a40ed3dSBarry Smith 61099cd645aSJed Brown #define PETSCSTACKSIZE 64 611184914b5SBarry Smith 6123a40ed3dSBarry Smith typedef struct { 6130e33f6ddSBarry Smith const char *function[PETSCSTACKSIZE]; 6140e33f6ddSBarry Smith const char *file[PETSCSTACKSIZE]; 615184914b5SBarry Smith int line[PETSCSTACKSIZE]; 616a8d2bbe5SBarry Smith PetscBool petscroutine[PETSCSTACKSIZE]; 617184914b5SBarry Smith int currentsize; 618a2f94806SJed Brown int hotdepth; 6193a40ed3dSBarry Smith } PetscStack; 6203a40ed3dSBarry Smith 6211f46d60fSShri Abhyankar PETSC_EXTERN PetscStack *petscstack; 622184914b5SBarry Smith 6236f5c2d7aSBarry Smith PetscErrorCode PetscStackCopy(PetscStack*,PetscStack*); 6246f5c2d7aSBarry Smith PetscErrorCode PetscStackPrint(PetscStack *,FILE*); 6252d7c6352SJed Brown #if defined(PETSC_USE_DEBUG) 626dbf62e16SBarry Smith PETSC_STATIC_INLINE PetscBool PetscStackActive(void) 627dbf62e16SBarry Smith { 6285c25fcd7SBarry Smith return(petscstack ? PETSC_TRUE : PETSC_FALSE); 629dbf62e16SBarry Smith } 6303a40ed3dSBarry Smith 631441dd030SJed Brown /* Stack handling is based on the following two "NoCheck" macros. These should only be called directly by other error 632441dd030SJed Brown * handling macros. We record the line of the call, which may or may not be the location of the definition. But is at 633441dd030SJed Brown * least more useful than "unknown" because it can distinguish multiple calls from the same function. 634441dd030SJed Brown */ 635441dd030SJed Brown 636a2f94806SJed Brown #define PetscStackPushNoCheck(funct,petsc_routine,hot) \ 637441dd030SJed Brown do { \ 638e04113cfSBarry Smith PetscStackSAWsTakeAccess(); \ 6395c25fcd7SBarry Smith if (petscstack && (petscstack->currentsize < PETSCSTACKSIZE)) { \ 6405c25fcd7SBarry Smith petscstack->function[petscstack->currentsize] = funct; \ 6415c25fcd7SBarry Smith petscstack->file[petscstack->currentsize] = __FILE__; \ 6425c25fcd7SBarry Smith petscstack->line[petscstack->currentsize] = __LINE__; \ 6435c25fcd7SBarry Smith petscstack->petscroutine[petscstack->currentsize] = petsc_routine; \ 6445c25fcd7SBarry Smith petscstack->currentsize++; \ 645441dd030SJed Brown } \ 6465c25fcd7SBarry Smith if (petscstack) { \ 6475c25fcd7SBarry Smith petscstack->hotdepth += (hot || petscstack->hotdepth); \ 648a2f94806SJed Brown } \ 649e04113cfSBarry Smith PetscStackSAWsGrantAccess(); \ 650441dd030SJed Brown } while (0) 651441dd030SJed Brown 652441dd030SJed Brown #define PetscStackPopNoCheck \ 6535c25fcd7SBarry Smith do { \ 654e04113cfSBarry Smith PetscStackSAWsTakeAccess(); \ 6555c25fcd7SBarry Smith if (petscstack && petscstack->currentsize > 0) { \ 6565c25fcd7SBarry Smith petscstack->currentsize--; \ 6575c25fcd7SBarry Smith petscstack->function[petscstack->currentsize] = 0; \ 6585c25fcd7SBarry Smith petscstack->file[petscstack->currentsize] = 0; \ 6595c25fcd7SBarry Smith petscstack->line[petscstack->currentsize] = 0; \ 6605c25fcd7SBarry Smith petscstack->petscroutine[petscstack->currentsize] = PETSC_FALSE;\ 661441dd030SJed Brown } \ 6625c25fcd7SBarry Smith if (petscstack) { \ 6635c25fcd7SBarry Smith petscstack->hotdepth = PetscMax(petscstack->hotdepth-1,0); \ 664a2f94806SJed Brown } \ 665e04113cfSBarry Smith PetscStackSAWsGrantAccess(); \ 666441dd030SJed Brown } while (0) 667441dd030SJed Brown 66830de9b25SBarry Smith /*MC 6691957e957SBarry Smith PetscFunctionBegin - First executable line of each PETSc function, used for error handling. Final 6701957e957SBarry Smith line of PETSc functions should be PetscFunctionReturn(0); 67130de9b25SBarry Smith 67230de9b25SBarry Smith Synopsis: 673aaa7dc30SBarry Smith #include <petscsys.h> 67430de9b25SBarry Smith void PetscFunctionBegin; 67530de9b25SBarry Smith 676eca87e8dSBarry Smith Not Collective 677eca87e8dSBarry Smith 67830de9b25SBarry Smith Usage: 67930de9b25SBarry Smith .vb 68030de9b25SBarry Smith int something; 68130de9b25SBarry Smith 68230de9b25SBarry Smith PetscFunctionBegin; 68330de9b25SBarry Smith .ve 68430de9b25SBarry Smith 68530de9b25SBarry Smith Notes: 6861957e957SBarry Smith Use PetscFunctionBeginUser for application codes. 6871957e957SBarry Smith 68830de9b25SBarry Smith Not available in Fortran 68930de9b25SBarry Smith 69030de9b25SBarry Smith Level: developer 69130de9b25SBarry Smith 6921957e957SBarry Smith .seealso: PetscFunctionReturn(), PetscFunctionBeginHot(), PetscFunctionBeginUser() 69330de9b25SBarry Smith 69430de9b25SBarry Smith .keywords: traceback, error handling 69530de9b25SBarry Smith M*/ 696441dd030SJed Brown #define PetscFunctionBegin do { \ 697a2f94806SJed Brown PetscStackPushNoCheck(PETSC_FUNCTION_NAME,PETSC_TRUE,PETSC_FALSE); \ 698a2f94806SJed Brown PetscCheck__FUNCT__(); \ 699a2f94806SJed Brown PetscRegister__FUNCT__(); \ 700a2f94806SJed Brown } while (0) 701a2f94806SJed Brown 702a2f94806SJed Brown /*MC 703a2f94806SJed Brown PetscFunctionBeginHot - Substitute for PetscFunctionBegin to be used in functions that are called in 704a2f94806SJed Brown performance-critical circumstances. Use of this function allows for lighter profiling by default. 705a2f94806SJed Brown 706a2f94806SJed Brown Synopsis: 707aaa7dc30SBarry Smith #include <petscsys.h> 708a2f94806SJed Brown void PetscFunctionBeginHot; 709a2f94806SJed Brown 710a2f94806SJed Brown Not Collective 711a2f94806SJed Brown 712a2f94806SJed Brown Usage: 713a2f94806SJed Brown .vb 714a2f94806SJed Brown int something; 715a2f94806SJed Brown 716a2f94806SJed Brown PetscFunctionBeginHot; 717a2f94806SJed Brown .ve 718a2f94806SJed Brown 719a2f94806SJed Brown Notes: 720a2f94806SJed Brown Not available in Fortran 721a2f94806SJed Brown 722a2f94806SJed Brown Level: developer 723a2f94806SJed Brown 724a2f94806SJed Brown .seealso: PetscFunctionBegin, PetscFunctionReturn() 725a2f94806SJed Brown 726a2f94806SJed Brown .keywords: traceback, error handling 727a2f94806SJed Brown M*/ 728a2f94806SJed Brown #define PetscFunctionBeginHot do { \ 729a2f94806SJed Brown PetscStackPushNoCheck(PETSC_FUNCTION_NAME,PETSC_TRUE,PETSC_TRUE); \ 73053c77d0aSJed Brown PetscCheck__FUNCT__(); \ 7312d53ad75SBarry Smith PetscRegister__FUNCT__(); \ 73253c77d0aSJed Brown } while (0) 73353c77d0aSJed Brown 734a8d2bbe5SBarry Smith /*MC 735a8d2bbe5SBarry Smith PetscFunctionBeginUser - First executable line of user provided PETSc routine 736a8d2bbe5SBarry Smith 737a8d2bbe5SBarry Smith Synopsis: 738aaa7dc30SBarry Smith #include <petscsys.h> 739a8d2bbe5SBarry Smith void PetscFunctionBeginUser; 740a8d2bbe5SBarry Smith 741a8d2bbe5SBarry Smith Not Collective 742a8d2bbe5SBarry Smith 743a8d2bbe5SBarry Smith Usage: 744a8d2bbe5SBarry Smith .vb 745a8d2bbe5SBarry Smith int something; 746a8d2bbe5SBarry Smith 747a8d2bbe5SBarry Smith PetscFunctionBegin; 748a8d2bbe5SBarry Smith .ve 749a8d2bbe5SBarry Smith 750a8d2bbe5SBarry Smith Notes: 7511957e957SBarry Smith Final line of PETSc functions should be PetscFunctionReturn(0) except for main(). 7521957e957SBarry Smith 753a8d2bbe5SBarry Smith Not available in Fortran 754a8d2bbe5SBarry Smith 755a2f94806SJed Brown Level: intermediate 756a8d2bbe5SBarry Smith 757a2f94806SJed Brown .seealso: PetscFunctionReturn(), PetscFunctionBegin, PetscFunctionBeginHot 758a8d2bbe5SBarry Smith 759a8d2bbe5SBarry Smith .keywords: traceback, error handling 760a8d2bbe5SBarry Smith M*/ 761a8d2bbe5SBarry Smith #define PetscFunctionBeginUser \ 762a8d2bbe5SBarry Smith do { \ 763a2f94806SJed Brown PetscStackPushNoCheck(PETSC_FUNCTION_NAME,PETSC_FALSE,PETSC_FALSE); \ 764a8d2bbe5SBarry Smith PetscCheck__FUNCT__(); \ 765a8d2bbe5SBarry Smith PetscRegister__FUNCT__(); \ 766a8d2bbe5SBarry Smith } while (0) 767a8d2bbe5SBarry Smith 768a8d2bbe5SBarry Smith 7692d53ad75SBarry Smith #if defined(PETSC_SERIALIZE_FUNCTIONS) 770af0996ceSBarry Smith #include <petsc/private/petscfptimpl.h> 7712d53ad75SBarry Smith /* 7722d53ad75SBarry Smith Registers the current function into the global function pointer to function name table 7732d53ad75SBarry Smith 7742d53ad75SBarry Smith Have to fix this to handle errors but cannot return error since used in PETSC_VIEWER_DRAW_() etc 7752d53ad75SBarry Smith */ 7762d53ad75SBarry Smith #define PetscRegister__FUNCT__() do { \ 7772d53ad75SBarry Smith static PetscBool __chked = PETSC_FALSE; \ 7782d53ad75SBarry Smith if (!__chked) {\ 7790298fd71SBarry Smith void *ptr; PetscDLSym(NULL,__FUNCT__,&ptr);\ 7802d53ad75SBarry Smith __chked = PETSC_TRUE;\ 7812d53ad75SBarry Smith }} while (0) 7822d53ad75SBarry Smith #else 7832d53ad75SBarry Smith #define PetscRegister__FUNCT__() 7842d53ad75SBarry Smith #endif 7852d53ad75SBarry Smith 786573b0fb4SBarry Smith #define PetscCheck__FUNCT__() do { PetscBool _sc1,_sc2; \ 787573b0fb4SBarry Smith PetscStrcmpNoError(PETSC_FUNCTION_NAME,__FUNCT__,&_sc1);\ 788573b0fb4SBarry Smith PetscStrcmpNoError(__FUNCT__,"User provided function",&_sc2);\ 789573b0fb4SBarry Smith if (!_sc1 && !_sc2) { \ 790e9f0693fSJed Brown printf("%s:%d: __FUNCT__=\"%s\" does not agree with %s=\"%s\"\n",__FILE__,__LINE__,__FUNCT__,PetscStringize(PETSC_FUNCTION_NAME),PETSC_FUNCTION_NAME); \ 79153c77d0aSJed Brown } \ 79253c77d0aSJed Brown } while (0) 7933a40ed3dSBarry Smith 7945cd90555SBarry Smith #define PetscStackPush(n) \ 79561d886c9SShri Abhyankar do { \ 796a2f94806SJed Brown PetscStackPushNoCheck(n,PETSC_FALSE,PETSC_FALSE); \ 79715681b3cSBarry Smith CHKMEMQ; \ 79815681b3cSBarry Smith } while (0) 7993a40ed3dSBarry Smith 800d64ed03dSBarry Smith #define PetscStackPop \ 801441dd030SJed Brown do { \ 802441dd030SJed Brown CHKMEMQ; \ 803441dd030SJed Brown PetscStackPopNoCheck; \ 80415681b3cSBarry Smith } while (0) 805d64ed03dSBarry Smith 80630de9b25SBarry Smith /*MC 80730de9b25SBarry Smith PetscFunctionReturn - Last executable line of each PETSc function 80830de9b25SBarry Smith used for error handling. Replaces return() 80930de9b25SBarry Smith 81030de9b25SBarry Smith Synopsis: 811aaa7dc30SBarry Smith #include <petscsys.h> 81230de9b25SBarry Smith void PetscFunctionReturn(0); 81330de9b25SBarry Smith 814eca87e8dSBarry Smith Not Collective 815eca87e8dSBarry Smith 81630de9b25SBarry Smith Usage: 81730de9b25SBarry Smith .vb 81830de9b25SBarry Smith .... 81930de9b25SBarry Smith PetscFunctionReturn(0); 82030de9b25SBarry Smith } 82130de9b25SBarry Smith .ve 82230de9b25SBarry Smith 82330de9b25SBarry Smith Notes: 82430de9b25SBarry Smith Not available in Fortran 82530de9b25SBarry Smith 82630de9b25SBarry Smith Level: developer 82730de9b25SBarry Smith 82830de9b25SBarry Smith .seealso: PetscFunctionBegin() 82930de9b25SBarry Smith 83030de9b25SBarry Smith .keywords: traceback, error handling 83130de9b25SBarry Smith M*/ 8325cd90555SBarry Smith #define PetscFunctionReturn(a) \ 8338246ba0dSJed Brown do { \ 834441dd030SJed Brown PetscStackPopNoCheck; \ 8358246ba0dSJed Brown return(a);} while (0) 836d64ed03dSBarry Smith 837ff94ddecSSatish Balay #define PetscFunctionReturnVoid() \ 8388246ba0dSJed Brown do { \ 839441dd030SJed Brown PetscStackPopNoCheck; \ 8408246ba0dSJed Brown return;} while (0) 84176386721SLisandro Dalcin 8426d385327SIbrahima Ba #else 8436d385327SIbrahima Ba 844c82b4e47SJed Brown PETSC_STATIC_INLINE PetscBool PetscStackActive(void) {return PETSC_FALSE;} 845a2f94806SJed Brown #define PetscStackPushNoCheck(funct,petsc_routine,hot) do {} while (0) 846441dd030SJed Brown #define PetscStackPopNoCheck do {} while (0) 8473a40ed3dSBarry Smith #define PetscFunctionBegin 8480bdf7c52SPeter Brune #define PetscFunctionBeginUser 849a2f94806SJed Brown #define PetscFunctionBeginHot 8503a40ed3dSBarry Smith #define PetscFunctionReturn(a) return(a) 8515665465eSBarry Smith #define PetscFunctionReturnVoid() return 852812af9f3SBarry Smith #define PetscStackPop CHKMEMQ 853812af9f3SBarry Smith #define PetscStackPush(f) CHKMEMQ 8543a40ed3dSBarry Smith 8553a40ed3dSBarry Smith #endif 8563a40ed3dSBarry Smith 857eb6b5d47SBarry Smith /* 858eb6b5d47SBarry Smith PetscStackCall - Calls an external library routine or user function after pushing the name of the routine on the stack. 859eb6b5d47SBarry Smith 860eb6b5d47SBarry Smith Input Parameters: 861eb6b5d47SBarry Smith + name - string that gives the name of the function being called 862fd3f9acdSBarry Smith - routine - actual call to the routine, including ierr = and CHKERRQ(ierr); 863fd3f9acdSBarry Smith 864dbf62e16SBarry Smith Note: Often one should use PetscStackCallStandard() instead. This routine is intended for external library routines that DO NOT return error codes 865eb6b5d47SBarry Smith 866eb6b5d47SBarry 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. 867eb6b5d47SBarry Smith 868fd3f9acdSBarry Smith 869fd3f9acdSBarry Smith 870eb6b5d47SBarry Smith */ 87130ecc5abSKarl Rupp #define PetscStackCall(name,routine) do { PetscStackPush(name);routine;PetscStackPop; } while(0) 872eb6b5d47SBarry Smith 873fd3f9acdSBarry Smith /* 874fd3f9acdSBarry Smith PetscStackCallStandard - Calls an external library routine after pushing the name of the routine on the stack. 875fd3f9acdSBarry Smith 876fd3f9acdSBarry Smith Input Parameters: 877fd3f9acdSBarry Smith + func- name of the routine 878fd3f9acdSBarry Smith - args - arguments to the routine surrounded by () 879fd3f9acdSBarry Smith 880dbf62e16SBarry Smith Notes: This is intended for external package routines that return error codes. Use PetscStackCall() for those that do not. 881dbf62e16SBarry Smith 882dbf62e16SBarry 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. 883fd3f9acdSBarry Smith 884fd3f9acdSBarry Smith */ 885fd3f9acdSBarry Smith #define PetscStackCallStandard(func,args) do { \ 886fd3f9acdSBarry Smith PetscStackPush(#func);ierr = func args;PetscStackPop; if (ierr) SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_LIB,"Error in %s()",#func); \ 887fd3f9acdSBarry Smith } while (0) 888fd3f9acdSBarry Smith 889014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscStackCreate(void); 890639ff905SBarry Smith PETSC_EXTERN PetscErrorCode PetscStackView(FILE*); 891014dd563SJed Brown PETSC_EXTERN PetscErrorCode PetscStackDestroy(void); 89206d1fe2cSBarry Smith 89306d1fe2cSBarry Smith #endif 894