Actual source code: petscerror.h

petsc-3.6.0 2015-06-09
Report Typos and Errors
  1: /*
  2:     Contains all error handling interfaces for PETSc.
  3: */

  7: /*
  8:    Defines the function where the compiled source is located; used
  9:    in printing error messages. This is defined here in case the user
 10:    does not declare it.
 11: */
 14: #endif

 16: /*
 17:      These are the generic error codes. These error codes are used
 18:      many different places in the PETSc source code. The string versions are
 19:      at src/sys/error/err.c any changes here must also be made there
 20:      These are also define in include/petsc/finclude/petscerror.h any CHANGES here
 21:      must be also made there.

 23: */
 24: #define PETSC_ERR_MIN_VALUE        54   /* should always be one less then the smallest value */

 26: #define PETSC_ERR_MEM              55   /* unable to allocate requested memory */
 27: #define PETSC_ERR_SUP              56   /* no support for requested operation */
 28: #define PETSC_ERR_SUP_SYS          57   /* no support for requested operation on this computer system */
 29: #define PETSC_ERR_ORDER            58   /* operation done in wrong order */
 30: #define PETSC_ERR_SIG              59   /* signal received */
 31: #define PETSC_ERR_FP               72   /* floating point exception */
 32: #define PETSC_ERR_COR              74   /* corrupted PETSc object */
 33: #define PETSC_ERR_LIB              76   /* error in library called by PETSc */
 34: #define PETSC_ERR_PLIB             77   /* PETSc library generated inconsistent data */
 35: #define PETSC_ERR_MEMC             78   /* memory corruption */
 36: #define PETSC_ERR_CONV_FAILED      82   /* iterative method (KSP or SNES) failed */
 37: #define PETSC_ERR_USER             83   /* user has not provided needed function */
 38: #define PETSC_ERR_SYS              88   /* error in system call */
 39: #define PETSC_ERR_POINTER          70   /* pointer does not point to valid address */

 41: #define PETSC_ERR_ARG_SIZ          60   /* nonconforming object sizes used in operation */
 42: #define PETSC_ERR_ARG_IDN          61   /* two arguments not allowed to be the same */
 43: #define PETSC_ERR_ARG_WRONG        62   /* wrong argument (but object probably ok) */
 44: #define PETSC_ERR_ARG_CORRUPT      64   /* null or corrupted PETSc object as argument */
 45: #define PETSC_ERR_ARG_OUTOFRANGE   63   /* input argument, out of range */
 46: #define PETSC_ERR_ARG_BADPTR       68   /* invalid pointer argument */
 47: #define PETSC_ERR_ARG_NOTSAMETYPE  69   /* two args must be same object type */
 48: #define PETSC_ERR_ARG_NOTSAMECOMM  80   /* two args must be same communicators */
 49: #define PETSC_ERR_ARG_WRONGSTATE   73   /* object in argument is in wrong state, e.g. unassembled mat */
 50: #define PETSC_ERR_ARG_TYPENOTSET   89   /* the type of the object has not yet been set */
 51: #define PETSC_ERR_ARG_INCOMP       75   /* two arguments are incompatible */
 52: #define PETSC_ERR_ARG_NULL         85   /* argument is null that should not be */
 53: #define PETSC_ERR_ARG_UNKNOWN_TYPE 86   /* type name doesn't match any registered type */

 55: #define PETSC_ERR_FILE_OPEN        65   /* unable to open file */
 56: #define PETSC_ERR_FILE_READ        66   /* unable to read from file */
 57: #define PETSC_ERR_FILE_WRITE       67   /* unable to write to file */
 58: #define PETSC_ERR_FILE_UNEXPECTED  79   /* unexpected data in file */

 60: #define PETSC_ERR_MAT_LU_ZRPVT     71   /* detected a zero pivot during LU factorization */
 61: #define PETSC_ERR_MAT_CH_ZRPVT     81   /* detected a zero pivot during Cholesky factorization */

 63: #define PETSC_ERR_INT_OVERFLOW     84

 65: #define PETSC_ERR_FLOP_COUNT       90
 66: #define PETSC_ERR_NOT_CONVERGED    91  /* solver did not converge */
 67: #define PETSC_ERR_MISSING_FACTOR   92  /* MatGetFactor() failed */
 68: #define PETSC_ERR_MAX_VALUE        93  /* this is always the one more than the largest error code */

 70: #define PetscStringizeArg(a) #a
 71: #define PetscStringize(a) PetscStringizeArg(a)

 73: #if defined(PETSC_USE_ERRORCHECKING)

 75: /*MC
 76:    SETERRQ - Macro to be called when an error has been detected,

 78:    Synopsis:
 79:    #include <petscsys.h>
 80:    PetscErrorCode SETERRQ(MPI_Comm comm,PetscErrorCode errorcode,char *message)

 82:    Not Collective

 84:    Input Parameters:
 85: +  errorcode - nonzero error code, see the list of standard error codes in include/petscerror.h
 86: -  message - error message

 88:   Level: beginner

 90:    Notes:
 91:     Once the error handler is called the calling function is then returned from with the given error code.

 93:     See SETERRQ1(), SETERRQ2(), SETERRQ3() for versions that take arguments

 95:     In Fortran MPI_Abort() is always called

 97:     Experienced users can set the error handler with PetscPushErrorHandler().

 99:    Concepts: error^setting condition

101: .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), CHKERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2(), SETERRQ3()
102: M*/
103: #define SETERRQ(comm,n,s)              return PetscError(comm,__LINE__,PETSC_FUNCTION_NAME,__FILE__,n,PETSC_ERROR_INITIAL,s)

105: /*MC
106:    SETERRQ1 - Macro that is called when an error has been detected,

108:    Synopsis:
109:    #include <petscsys.h>
110:    PetscErrorCode SETERRQ1(MPI_Comm comm,PetscErrorCode errorcode,char *formatmessage,arg)

112:    Not Collective

114:    Input Parameters:
115: +  errorcode - nonzero error code, see the list of standard error codes in include/petscerror.h
116: .  message - error message in the printf format
117: -  arg - argument (for example an integer, string or double)

119:   Level: beginner

121:    Notes:
122:     Once the error handler is called the calling function is then returned from with the given error code.

124:    Experienced users can set the error handler with PetscPushErrorHandler().

126:    Concepts: error^setting condition

128: .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), CHKERRQ(), CHKMEMQ, SETERRQ(), SETERRQ2(), SETERRQ3()
129: M*/
130: #define SETERRQ1(comm,n,s,a1)          return PetscError(comm,__LINE__,PETSC_FUNCTION_NAME,__FILE__,n,PETSC_ERROR_INITIAL,s,a1)

132: /*MC
133:    SETERRQ2 - Macro that is called when an error has been detected,

135:    Synopsis:
136:    #include <petscsys.h>
137:    PetscErrorCode SETERRQ2(PetscErrorCode errorcode,char *formatmessage,arg1,arg2)

139:    Not Collective

141:    Input Parameters:
142: +  errorcode - nonzero error code, see the list of standard error codes in include/petscerror.h
143: .  message - error message in the printf format
144: .  arg1 - argument (for example an integer, string or double)
145: -  arg2 - argument (for example an integer, string or double)

147:   Level: beginner

149:    Notes:
150:     Once the error handler is called the calling function is then returned from with the given error code.

152:    Experienced users can set the error handler with PetscPushErrorHandler().

154:    Concepts: error^setting condition

156: .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), CHKERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ3()
157: M*/
158: #define SETERRQ2(comm,n,s,a1,a2)       return PetscError(comm,__LINE__,PETSC_FUNCTION_NAME,__FILE__,n,PETSC_ERROR_INITIAL,s,a1,a2)

160: /*MC
161:    SETERRQ3 - Macro that is called when an error has been detected,

163:    Synopsis:
164:    #include <petscsys.h>
165:    PetscErrorCode SETERRQ3(PetscErrorCode errorcode,char *formatmessage,arg1,arg2,arg3)

167:    Not Collective

169:    Input Parameters:
170: +  errorcode - nonzero error code, see the list of standard error codes in include/petscerror.h
171: .  message - error message in the printf format
172: .  arg1 - argument (for example an integer, string or double)
173: .  arg2 - argument (for example an integer, string or double)
174: -  arg3 - argument (for example an integer, string or double)

176:   Level: beginner

178:    Notes:
179:     Once the error handler is called the calling function is then returned from with the given error code.

181:     There are also versions for 4, 5, 6 and 7 arguments.

183:    Experienced users can set the error handler with PetscPushErrorHandler().

185:    Concepts: error^setting condition

187: .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), CHKERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2()
188: M*/
189: #define SETERRQ3(comm,n,s,a1,a2,a3)    return PetscError(comm,__LINE__,PETSC_FUNCTION_NAME,__FILE__,n,PETSC_ERROR_INITIAL,s,a1,a2,a3)

191: #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)
192: #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)
193: #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)
194: #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)
195: #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)
196: #define SETERRABORT(comm,n,s)     do {PetscError(comm,__LINE__,PETSC_FUNCTION_NAME,__FILE__,n,PETSC_ERROR_INITIAL,s);MPI_Abort(comm,n);} while (0)

198: /*MC
199:    CHKERRQ - Checks error code, if non-zero it calls the error handler and then returns

201:    Synopsis:
202:    #include <petscsys.h>
203:    PetscErrorCode CHKERRQ(PetscErrorCode errorcode)

205:    Not Collective

207:    Input Parameters:
208: .  errorcode - nonzero error code, see the list of standard error codes in include/petscerror.h

210:   Level: beginner

212:    Notes:
213:     Once the error handler is called the calling function is then returned from with the given error code.

215:     Experienced users can set the error handler with PetscPushErrorHandler().

217:     CHKERRQ(n) is fundamentally a macro replacement for
218:          if (n) return(PetscError(...,n,...));

220:     Although typical usage resembles "void CHKERRQ(PetscErrorCode)" as described above, for certain uses it is
221:     highly inappropriate to use it in this manner as it invokes return(PetscErrorCode). In particular,
222:     it cannot be used in functions which return(void) or any other datatype.  In these types of functions,
223:     you can use CHKERRV() which returns without an error code (bad idea since the error is ignored or
224:          if (n) {PetscError(....); return(YourReturnType);}
225:     where you may pass back a NULL to indicate an error. You can also call CHKERRABORT(comm,n) to have
226:     MPI_Abort() returned immediately.

228:     In Fortran MPI_Abort() is always called

230:    Concepts: error^setting condition

232: .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), SETERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2(), SETERRQ2()
233: M*/
234: #define CHKERRQ(n)             do {if (PetscUnlikely(n)) return PetscError(PETSC_COMM_SELF,__LINE__,PETSC_FUNCTION_NAME,__FILE__,n,PETSC_ERROR_REPEAT," ");} while (0)

236: #define CHKERRV(n)             do {if (PetscUnlikely(n)) {n = PetscError(PETSC_COMM_SELF,__LINE__,PETSC_FUNCTION_NAME,__FILE__,n,PETSC_ERROR_REPEAT," ");return;}} while(0)
237: #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)
238: #define CHKERRCONTINUE(n)      do {if (PetscUnlikely(n)) {PetscError(PETSC_COMM_SELF,__LINE__,PETSC_FUNCTION_NAME,__FILE__,n,PETSC_ERROR_REPEAT," ");}} while (0)

240: #ifdef PETSC_CLANGUAGE_CXX

242: /*MC
243:    CHKERRXX - Checks error code, if non-zero it calls the C++ error handler which throws an exception

245:    Synopsis:
246:    #include <petscsys.h>
247:    void CHKERRXX(PetscErrorCode errorcode)

249:    Not Collective

251:    Input Parameters:
252: .  errorcode - nonzero error code, see the list of standard error codes in include/petscerror.h

254:   Level: beginner

256:    Notes:
257:     Once the error handler throws a ??? exception.

259:     You can use CHKERRV() which returns without an error code (bad idea since the error is ignored)
260:     or CHKERRABORT(comm,n) to have MPI_Abort() returned immediately.

262:    Concepts: error^setting condition

264: .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), SETERRQ(), CHKERRQ(), CHKMEMQ
265: M*/
266: #define CHKERRXX(n)            do {if (PetscUnlikely(n)) {PetscError(PETSC_COMM_SELF,__LINE__,PETSC_FUNCTION_NAME,__FILE__,n,PETSC_ERROR_IN_CXX,0);}} while(0)

268: #endif

270: /*MC
271:    CHKMEMQ - Checks the memory for corruption, calls error handler if any is detected

273:    Synopsis:
274:    #include <petscsys.h>
275:    CHKMEMQ;

277:    Not Collective

279:   Level: beginner

281:    Notes:
282:     We highly recommend using valgrind http://www.mcs.anl.gov/petsc/documentation/faq.html#valgrind for finding memory problems. This is useful
283:     on systems that do not have valgrind, but much much less useful.

285:     Must run with the option -malloc_debug to enable this option

287:     Once the error handler is called the calling function is then returned from with the given error code.

289:     By defaults prints location where memory that is corrupted was allocated.

291:     Use CHKMEMA for functions that return void

293:    Concepts: memory corruption

295: .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), SETERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2(), SETERRQ3(),
296:           PetscMallocValidate()
297: M*/
298: #define CHKMEMQ do {PetscErrorCode _7_PetscMallocValidate(__LINE__,PETSC_FUNCTION_NAME,__FILE__);CHKERRQ(_7_ierr);} while(0)

300: #define CHKMEMA PetscMallocValidate(__LINE__,PETSC_FUNCTION_NAME,__FILE__)

302: #else /* PETSC_USE_ERRORCHECKING */

304: /*
305:     These are defined to be empty for when error checking is turned off, with ./configure --with-errorchecking=0
306: */

308: #define SETERRQ(c,n,s)
309: #define SETERRQ1(c,n,s,a1)
310: #define SETERRQ2(c,n,s,a1,a2)
311: #define SETERRQ3(c,n,s,a1,a2,a3)
312: #define SETERRQ4(c,n,s,a1,a2,a3,a4)
313: #define SETERRQ5(c,n,s,a1,a2,a3,a4,a5)
314: #define SETERRQ6(c,n,s,a1,a2,a3,a4,a5,a6)
315: #define SETERRQ7(c,n,s,a1,a2,a3,a4,a5,a6,a7)
316: #define SETERRQ8(c,n,s,a1,a2,a3,a4,a5,a6,a7,a8)
317: #define SETERRABORT(comm,n,s)

319: #define CHKERRQ(n)     ;
320: #define CHKERRABORT(comm,n) ;
321: #define CHKERRCONTINUE(n) ;
322: #define CHKMEMQ        ;

324: #ifdef PETSC_CLANGUAGE_CXX
325: #define CHKERRXX(n) ;
326: #endif

328: #endif /* PETSC_USE_ERRORCHECKING */

330: /*E
331:   PetscErrorType - passed to the PETSc error handling routines indicating if this is the first or a later call to the error handlers

333:   Level: advanced

335:   PETSC_ERROR_IN_CXX indicates the error was detected in C++ and an exception should be generated

337:   Developer Notes: This is currently used to decide when to print the detailed information about the run in PetscTraceBackErrorHandler()

339: .seealso: PetscError(), SETERRXX()
340: E*/
341: typedef enum {PETSC_ERROR_INITIAL=0,PETSC_ERROR_REPEAT=1,PETSC_ERROR_IN_CXX = 2} PetscErrorType;

343: #if defined(__clang_analyzer__)
344: __attribute__((analyzer_noreturn))
345: #endif
346: PETSC_EXTERN PetscErrorCode PetscError(MPI_Comm,int,const char*,const char*,PetscErrorCode,PetscErrorType,const char*,...);

348: PETSC_EXTERN PetscErrorCode PetscErrorPrintfInitialize(void);
349: PETSC_EXTERN PetscErrorCode PetscErrorMessage(int,const char*[],char **);
350: PETSC_EXTERN PetscErrorCode PetscTraceBackErrorHandler(MPI_Comm,int,const char*,const char*,PetscErrorCode,PetscErrorType,const char*,void*);
351: PETSC_EXTERN PetscErrorCode PetscIgnoreErrorHandler(MPI_Comm,int,const char*,const char*,PetscErrorCode,PetscErrorType,const char*,void*);
352: PETSC_EXTERN PetscErrorCode PetscEmacsClientErrorHandler(MPI_Comm,int,const char*,const char*,PetscErrorCode,PetscErrorType,const char*,void*);
353: PETSC_EXTERN PetscErrorCode PetscMPIAbortErrorHandler(MPI_Comm,int,const char*,const char*,PetscErrorCode,PetscErrorType,const char*,void*);
354: PETSC_EXTERN PetscErrorCode PetscAbortErrorHandler(MPI_Comm,int,const char*,const char*,PetscErrorCode,PetscErrorType,const char*,void*);
355: PETSC_EXTERN PetscErrorCode PetscAttachDebuggerErrorHandler(MPI_Comm,int,const char*,const char*,PetscErrorCode,PetscErrorType,const char*,void*);
356: PETSC_EXTERN PetscErrorCode PetscReturnErrorHandler(MPI_Comm,int,const char*,const char*,PetscErrorCode,PetscErrorType,const char*,void*);
357: PETSC_EXTERN PetscErrorCode PetscPushErrorHandler(PetscErrorCode (*handler)(MPI_Comm,int,const char*,const char*,PetscErrorCode,PetscErrorType,const char*,void*),void*);
358: PETSC_EXTERN PetscErrorCode PetscPopErrorHandler(void);
359: PETSC_EXTERN PetscErrorCode PetscSignalHandlerDefault(int,void*);
360: PETSC_EXTERN PetscErrorCode PetscPushSignalHandler(PetscErrorCode (*)(int,void *),void*);
361: PETSC_EXTERN PetscErrorCode PetscPopSignalHandler(void);

364: /*MC
365:     PetscErrorPrintf - Prints error messages.

367:    Synopsis:
368:     #include <petscsys.h>
369:      PetscErrorCode (*PetscErrorPrintf)(const char format[],...);

371:     Not Collective

373:     Input Parameters:
374: .   format - the usual printf() format string

376:    Options Database Keys:
377: +    -error_output_stdout - cause error messages to be printed to stdout instead of the  (default) stderr
378: -    -error_output_none - to turn off all printing of error messages (does not change the way the error is handled.)

380:    Notes: Use
381: $     PetscErrorPrintf = PetscErrorPrintfNone; to turn off all printing of error messages (does not change the way the
382: $                        error is handled.) and
383: $     PetscErrorPrintf = PetscErrorPrintfDefault; to turn it back on or you can use your own function

385:           Use
386:      PETSC_STDERR = FILE* obtained from a file open etc. to have stderr printed to the file.
387:      PETSC_STDOUT = FILE* obtained from a file open etc. to have stdout printed to the file.

389:           Use
390:       PetscPushErrorHandler() to provide your own error handler that determines what kind of messages to print

392:    Level: developer

394:     Fortran Note:
395:     This routine is not supported in Fortran.

397:     Concepts: error messages^printing
398:     Concepts: printing^error messages

400: .seealso: PetscFPrintf(), PetscSynchronizedPrintf(), PetscHelpPrintf(), PetscPrintf(), PetscErrorHandlerPush(), PetscVFPrintf(), PetscHelpPrintf()
401: M*/
402: PETSC_EXTERN PetscErrorCode (*PetscErrorPrintf)(const char[],...);

404: typedef enum {PETSC_FP_TRAP_OFF=0,PETSC_FP_TRAP_ON=1} PetscFPTrap;
405: PETSC_EXTERN PetscErrorCode PetscSetFPTrap(PetscFPTrap);
406: PETSC_EXTERN PetscErrorCode PetscFPTrapPush(PetscFPTrap);
407: PETSC_EXTERN PetscErrorCode PetscFPTrapPop(void);

409: /*
410:       Allows the code to build a stack frame as it runs
411: */

413: #define PETSCSTACKSIZE 64

415: typedef struct  {
416:   const char      *function[PETSCSTACKSIZE];
417:   const char      *file[PETSCSTACKSIZE];
418:         int       line[PETSCSTACKSIZE];
419:         PetscBool petscroutine[PETSCSTACKSIZE];
420:         int       currentsize;
421:         int       hotdepth;
422: } PetscStack;

424: PETSC_EXTERN PetscStack *petscstack;

426: PetscErrorCode  PetscStackCopy(PetscStack*,PetscStack*);
427: PetscErrorCode  PetscStackPrint(PetscStack *,FILE*);
428: #if defined(PETSC_USE_DEBUG)
429: PETSC_STATIC_INLINE PetscBool PetscStackActive(void)
430: {
431:   return(petscstack ? PETSC_TRUE : PETSC_FALSE);
432: }

434: /* Stack handling is based on the following two "NoCheck" macros.  These should only be called directly by other error
435:  * handling macros.  We record the line of the call, which may or may not be the location of the definition.  But is at
436:  * least more useful than "unknown" because it can distinguish multiple calls from the same function.
437:  */

439: #define PetscStackPushNoCheck(funct,petsc_routine,hot)                        \
440:   do {                                                                        \
441:     PetscStackSAWsTakeAccess();                                                \
442:     if (petscstack && (petscstack->currentsize < PETSCSTACKSIZE)) {         \
443:       petscstack->function[petscstack->currentsize]  = funct;               \
444:       petscstack->file[petscstack->currentsize]      = __FILE__;            \
445:       petscstack->line[petscstack->currentsize]      = __LINE__;            \
446:       petscstack->petscroutine[petscstack->currentsize] = petsc_routine;    \
447:       petscstack->currentsize++;                                             \
448:     }                                                                         \
449:     if (petscstack) {                                                        \
450:       petscstack->hotdepth += (hot || petscstack->hotdepth);                \
451:     }                                                                         \
452:     PetscStackSAWsGrantAccess();                                               \
453:   } while (0)

455: #define PetscStackPopNoCheck                                            \
456:   do {                                                                  \
457:     PetscStackSAWsTakeAccess();                                          \
458:     if (petscstack && petscstack->currentsize > 0) {                  \
459:       petscstack->currentsize--;                                       \
460:       petscstack->function[petscstack->currentsize]  = 0;             \
461:       petscstack->file[petscstack->currentsize]      = 0;             \
462:       petscstack->line[petscstack->currentsize]      = 0;             \
463:       petscstack->petscroutine[petscstack->currentsize] = PETSC_FALSE;\
464:     }                                                                   \
465:     if (petscstack) {                                                  \
466:       petscstack->hotdepth = PetscMax(petscstack->hotdepth-1,0);      \
467:     }                                                                   \
468:     PetscStackSAWsGrantAccess();                                         \
469:   } while (0)

471: /*MC
473:       line of PETSc functions should be return(0);

475:    Synopsis:
476:    #include <petscsys.h>

479:    Not Collective

481:    Usage:
482: .vb
483:      int something;

486: .ve

488:    Notes:

491:      Not available in Fortran

493:    Level: developer


497: .keywords: traceback, error handling
498: M*/
500:     PetscStackPushNoCheck(PETSC_FUNCTION_NAME,PETSC_TRUE,PETSC_FALSE); \
502:     PetscRegister__FUNCT__();                                          \
503:   } while (0)

505: /*MC
507:    performance-critical circumstances.  Use of this function allows for lighter profiling by default.

509:    Synopsis:
510:    #include <petscsys.h>

513:    Not Collective

515:    Usage:
516: .vb
517:      int something;

520: .ve

522:    Notes:
523:      Not available in Fortran

525:    Level: developer


529: .keywords: traceback, error handling
530: M*/
532:     PetscStackPushNoCheck(PETSC_FUNCTION_NAME,PETSC_TRUE,PETSC_TRUE);  \
534:     PetscRegister__FUNCT__();                                          \
535:   } while (0)

537: /*MC

540:    Synopsis:
541:    #include <petscsys.h>

544:    Not Collective

546:    Usage:
547: .vb
548:      int something;

551: .ve

553:    Notes:
554:       Final line of PETSc functions should be return(0) except for main().

556:       Not available in Fortran

558:    Level: intermediate


562: .keywords: traceback, error handling
563: M*/
565:   do {                                                                  \
566:     PetscStackPushNoCheck(PETSC_FUNCTION_NAME,PETSC_FALSE,PETSC_FALSE); \
568:     PetscRegister__FUNCT__();                                           \
569:   } while (0)


572: #if defined(PETSC_SERIALIZE_FUNCTIONS)
573: #include <petsc/private/petscfptimpl.h>
574: /*
575:    Registers the current function into the global function pointer to function name table

577:    Have to fix this to handle errors but cannot return error since used in PETSC_VIEWER_DRAW_() etc
578: */
579: #define PetscRegister__FUNCT__() do { \
580:   static PetscBool __chked = PETSC_FALSE; \
581:   if (!__chked) {\
582:   void *ptr; PetscDLSym(NULL,__FUNCT__,&ptr);\
583:   __chked = PETSC_TRUE;\
584:   }} while (0)
585: #else
586: #define PetscRegister__FUNCT__()
587: #endif

590:     PetscStrcmpNoError(PETSC_FUNCTION_NAME,__FUNCT__,&_sc1);\
591:     PetscStrcmpNoError(__FUNCT__,"User provided function",&_sc2);\
592:     if (!_sc1 && !_sc2) { \
593:       printf("%s:%d: __FUNCT__=\"%s\" does not agree with %s=\"%s\"\n",__FILE__,__LINE__,__FUNCT__,PetscStringize(PETSC_FUNCTION_NAME),PETSC_FUNCTION_NAME); \
594:     }                                                                   \
595:   } while (0)

597: #define PetscStackPush(n) \
598:   do {                                                                  \
599:     PetscStackPushNoCheck(n,PETSC_FALSE,PETSC_FALSE);                   \
600:     CHKMEMQ;                                                            \
601:   } while (0)

603: #define PetscStackPop                           \
604:     do {                                        \
605:       CHKMEMQ;                                  \
606:       PetscStackPopNoCheck;                     \
607:     } while (0)

609: /*MC
610:    PetscFunctionReturn - Last executable line of each PETSc function
611:         used for error handling. Replaces return()

613:    Synopsis:
614:    #include <petscsys.h>
615:    void return(0);

617:    Not Collective

619:    Usage:
620: .vb
621:     ....
622:      return(0);
623:    }
624: .ve

626:    Notes:
627:      Not available in Fortran

629:    Level: developer


633: .keywords: traceback, error handling
634: M*/
635: #define PetscFunctionReturn(a) \
636:   do {                                                                \
637:     PetscStackPopNoCheck;                                             \
638:     return(a);} while (0)

640: #define PetscFunctionReturnVoid() \
641:   do {                                                                \
642:     PetscStackPopNoCheck;                                             \
643:     return;} while (0)

645: #else

647: PETSC_STATIC_INLINE PetscBool PetscStackActive(void) {return PETSC_FALSE;}
648: #define PetscStackPushNoCheck(funct,petsc_routine,hot) do {} while (0)
649: #define PetscStackPopNoCheck                           do {} while (0)
653: #define PetscFunctionReturn(a)    return(a)
654: #define PetscFunctionReturnVoid() return
655: #define PetscStackPop             CHKMEMQ
656: #define PetscStackPush(f)         CHKMEMQ

658: #endif

660: /*
661:     PetscStackCall - Calls an external library routine or user function after pushing the name of the routine on the stack.

663:    Input Parameters:
664: +   name - string that gives the name of the function being called
665: -   routine - actual call to the routine, including and 

667:    Note: Often one should use PetscStackCallStandard() instead. This routine is intended for external library routines that DO NOT return error codes

669:    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.



673: */
674: #define PetscStackCall(name,routine) do { PetscStackPush(name);routine;PetscStackPop; } while(0)

676: /*
677:     PetscStackCallStandard - Calls an external library routine after pushing the name of the routine on the stack.

679:    Input Parameters:
680: +   func-  name of the routine
681: -   args - arguments to the routine surrounded by ()

683:    Notes: This is intended for external package routines that return error codes. Use PetscStackCall() for those that do not.

685:    Developer Note: this is so that when an external packge routine results in a crash or corrupts memory, they get blamed instead of PETSc.

687: */
688: #define PetscStackCallStandard(func,args) do {                        \
689:     PetscStackPush(#func);func args;PetscStackPop; if (ierr) SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_LIB,"Error in %s()",#func); \
690:   } while (0)

692: PETSC_EXTERN PetscErrorCode PetscStackCreate(void);
693: PETSC_EXTERN PetscErrorCode PetscStackView(FILE*);
694: PETSC_EXTERN PetscErrorCode PetscStackDestroy(void);

696: #endif