Actual source code: petscerror.h

petsc-master 2019-10-19
Report Typos and Errors
  1: /*
  2:     Contains all error handling interfaces for PETSc.
  3: */
  4: #if !defined(PETSCERROR_H)
  5: #define PETSCERROR_H

  7: /*
  8:      These are the generic error codes. These error codes are used
  9:      many different places in the PETSc source code. The string versions are
 10:      at src/sys/error/err.c any changes here must also be made there
 11:      These are also define in include/petsc/finclude/petscerror.h any CHANGES here
 12:      must be also made there.

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

 17: #define PETSC_ERR_MEM              55   /* unable to allocate requested memory */
 18: #define PETSC_ERR_SUP              56   /* no support for requested operation */
 19: #define PETSC_ERR_SUP_SYS          57   /* no support for requested operation on this computer system */
 20: #define PETSC_ERR_ORDER            58   /* operation done in wrong order */
 21: #define PETSC_ERR_SIG              59   /* signal received */
 22: #define PETSC_ERR_FP               72   /* floating point exception */
 23: #define PETSC_ERR_COR              74   /* corrupted PETSc object */
 24: #define PETSC_ERR_LIB              76   /* error in library called by PETSc */
 25: #define PETSC_ERR_PLIB             77   /* PETSc library generated inconsistent data */
 26: #define PETSC_ERR_MEMC             78   /* memory corruption */
 27: #define PETSC_ERR_CONV_FAILED      82   /* iterative method (KSP or SNES) failed */
 28: #define PETSC_ERR_USER             83   /* user has not provided needed function */
 29: #define PETSC_ERR_SYS              88   /* error in system call */
 30: #define PETSC_ERR_POINTER          70   /* pointer does not point to valid address */
 31: #define PETSC_ERR_MPI_LIB_INCOMP   87   /* MPI library at runtime is not compatible with MPI user compiled with */

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

 47: #define PETSC_ERR_FILE_OPEN        65   /* unable to open file */
 48: #define PETSC_ERR_FILE_READ        66   /* unable to read from file */
 49: #define PETSC_ERR_FILE_WRITE       67   /* unable to write to file */
 50: #define PETSC_ERR_FILE_UNEXPECTED  79   /* unexpected data in file */

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

 55: #define PETSC_ERR_INT_OVERFLOW     84

 57: #define PETSC_ERR_FLOP_COUNT       90
 58: #define PETSC_ERR_NOT_CONVERGED    91  /* solver did not converge */
 59: #define PETSC_ERR_MISSING_FACTOR   92  /* MatGetFactor() failed */
 60: #define PETSC_ERR_OPT_OVERWRITE    93  /* attempted to over write options which should not be changed */
 61: #define PETSC_ERR_WRONG_MPI_SIZE   94  /* example/application run with number of MPI ranks it does not support */
 62: #define PETSC_ERR_USER_INPUT       95  /* missing or incorrect user input */
 63: #define PETSC_ERR_MAX_VALUE        96  /* this is always the one more than the largest error code */

 65: #define PetscStringizeArg(a) #a
 66: #define PetscStringize(a) PetscStringizeArg(a)


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

 72:    Synopsis:
 73:    #include <petscsys.h>
 74:    PetscErrorCode SETERRQ(MPI_Comm comm,PetscErrorCode ierr,char *message)

 76:    Collective

 78:    Input Parameters:
 79: +  comm - A communicator, use PETSC_COMM_SELF unless you know all ranks of another communicator will detect the error
 80: .  ierr - nonzero error code, see the list of standard error codes in include/petscerror.h
 81: -  message - error message

 83:   Level: beginner

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

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

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

 92: .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), CHKERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2(), SETERRQ3()
 93: M*/
 94: #define SETERRQ(comm,ierr,s) return PetscError(comm,__LINE__,PETSC_FUNCTION_NAME,__FILE__,ierr,PETSC_ERROR_INITIAL,s)

 96: /*MC
 97:    SETERRMPI - Macro to be called when an error has been detected within an MPI callback function

 99:    Synopsis:
100:    #include <petscsys.h>
101:    PetscErrorCode SETERRMPI(MPI_Comm comm,PetscErrorCode ierr,char *message)

103:    Collective

105:    Input Parameters:
106: +  comm - A communicator, use PETSC_COMM_SELF unless you know all ranks of another communicator will detect the error
107: .  ierr - nonzero error code, see the list of standard error codes in include/petscerror.h
108: -  message - error message

110:   Level: developer

112:    Notes:
113:     This macro is FOR USE IN MPI CALLBACK FUNCTIONS ONLY, such as those passed to MPI_Comm_create_keyval(). It always returns the error code PETSC_MPI_ERROR_CODE
114:     which is registered with MPI_Add_error_code() when PETSc is initialized.

116: .seealso: SETERRQ(), CHKERRQ(), CHKERRMPI(), PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), CHKERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2(), SETERRQ3()
117: M*/
118: #define SETERRMPI(comm,ierr,s) return (PetscError(comm,__LINE__,PETSC_FUNCTION_NAME,__FILE__,ierr,PETSC_ERROR_INITIAL,s),PETSC_MPI_ERROR_CODE)

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

123:    Synopsis:
124:    #include <petscsys.h>
125:    PetscErrorCode SETERRQ1(MPI_Comm comm,PetscErrorCode ierr,char *formatmessage,arg)

127:    Collective

129:    Input Parameters:
130: +  comm - A communicator, so that the error can be collective
131: .  ierr - nonzero error code, see the list of standard error codes in include/petscerror.h
132: .  message - error message in the printf format
133: -  arg - argument (for example an integer, string or double)

135:   Level: beginner

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

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

142: .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), CHKERRQ(), CHKMEMQ, SETERRQ(), SETERRQ2(), SETERRQ3()
143: M*/
144: #define SETERRQ1(comm,ierr,s,a1) return PetscError(comm,__LINE__,PETSC_FUNCTION_NAME,__FILE__,ierr,PETSC_ERROR_INITIAL,s,a1)

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

149:    Synopsis:
150:    #include <petscsys.h>
151:    PetscErrorCode SETERRQ2(MPI_Comm comm,PetscErrorCode ierr,char *formatmessage,arg1,arg2)

153:    Collective

155:    Input Parameters:
156: +  comm - A communicator, so that the error can be collective
157: .  ierr - nonzero error code, see the list of standard error codes in include/petscerror.h
158: .  message - error message in the printf format
159: .  arg1 - argument (for example an integer, string or double)
160: -  arg2 - argument (for example an integer, string or double)

162:   Level: beginner

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

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

169: .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), CHKERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ3()
170: M*/
171: #define SETERRQ2(comm,ierr,s,a1,a2) return PetscError(comm,__LINE__,PETSC_FUNCTION_NAME,__FILE__,ierr,PETSC_ERROR_INITIAL,s,a1,a2)

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

176:    Synopsis:
177:    #include <petscsys.h>
178:    PetscErrorCode SETERRQ3(MPI_Comm comm,PetscErrorCode ierr,char *formatmessage,arg1,arg2,arg3)

180:    Collective

182:    Input Parameters:
183: +  comm - A communicator, so that the error can be collective
184: .  ierr - nonzero error code, see the list of standard error codes in include/petscerror.h
185: .  message - error message in the printf format
186: .  arg1 - argument (for example an integer, string or double)
187: .  arg2 - argument (for example an integer, string or double)
188: -  arg3 - argument (for example an integer, string or double)

190:   Level: beginner

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

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

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

199: .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), CHKERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2()
200: M*/
201: #define SETERRQ3(comm,ierr,s,a1,a2,a3) return PetscError(comm,__LINE__,PETSC_FUNCTION_NAME,__FILE__,ierr,PETSC_ERROR_INITIAL,s,a1,a2,a3)

203: /*MC
204:    SETERRQ4 - Macro that is called when an error has been detected,

206:    Synopsis:
207:    #include <petscsys.h>
208:    PetscErrorCode SETERRQ4(MPI_Comm comm,PetscErrorCode ierr,char *formatmessage,arg1,arg2,arg3)

210:    Collective

212:    Input Parameters:
213: +  comm - A communicator, so that the error can be collective
214: .  ierr - nonzero error code, see the list of standard error codes in include/petscerror.h
215: .  message - error message in the printf format
216: .  arg1 - argument (for example an integer, string or double)
217: .  arg2 - argument (for example an integer, string or double)
218: .  arg3 - argument (for example an integer, string or double)
219: -  arg4 - argument (for example an integer, string or double)

221:   Level: beginner

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

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

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

230: .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), CHKERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2()
231: M*/
232: #define SETERRQ4(comm,ierr,s,a1,a2,a3,a4) return PetscError(comm,__LINE__,PETSC_FUNCTION_NAME,__FILE__,ierr,PETSC_ERROR_INITIAL,s,a1,a2,a3,a4)

234: /*MC
235:    SETERRQ5 - Macro that is called when an error has been detected,

237:    Synopsis:
238:    #include <petscsys.h>
239:    PetscErrorCode SETERRQ5(MPI_Comm comm,PetscErrorCode ierr,char *formatmessage,arg1,arg2,arg3)

241:    Collective

243:    Input Parameters:
244: +  comm - A communicator, so that the error can be collective
245: .  ierr - nonzero error code, see the list of standard error codes in include/petscerror.h
246: .  message - error message in the printf format
247: .  arg1 - argument (for example an integer, string or double)
248: .  arg2 - argument (for example an integer, string or double)
249: .  arg3 - argument (for example an integer, string or double)
250: .  arg4 - argument (for example an integer, string or double)
251: -  arg5 - argument (for example an integer, string or double)

253:   Level: beginner

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

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

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

262: .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), CHKERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2()
263: M*/
264: #define SETERRQ5(comm,ierr,s,a1,a2,a3,a4,a5) return PetscError(comm,__LINE__,PETSC_FUNCTION_NAME,__FILE__,ierr,PETSC_ERROR_INITIAL,s,a1,a2,a3,a4,a5)

266: /*MC
267:    SETERRQ6 - Macro that is called when an error has been detected,

269:    Synopsis:
270:    #include <petscsys.h>
271:    PetscErrorCode SETERRQ6(MPI_Comm comm,PetscErrorCode ierr,char *formatmessage,arg1,arg2,arg3)

273:    Collective

275:    Input Parameters:
276: +  comm - A communicator, so that the error can be collective
277: .  ierr - nonzero error code, see the list of standard error codes in include/petscerror.h
278: .  message - error message in the printf format
279: .  arg1 - argument (for example an integer, string or double)
280: .  arg2 - argument (for example an integer, string or double)
281: .  arg3 - argument (for example an integer, string or double)
282: .  arg4 - argument (for example an integer, string or double)
283: .  arg5 - argument (for example an integer, string or double)
284: -  arg6 - argument (for example an integer, string or double)

286:   Level: beginner

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

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

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

295: .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), CHKERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2()
296: M*/
297: #define SETERRQ6(comm,ierr,s,a1,a2,a3,a4,a5,a6) return PetscError(comm,__LINE__,PETSC_FUNCTION_NAME,__FILE__,ierr,PETSC_ERROR_INITIAL,s,a1,a2,a3,a4,a5,a6)

299: /*MC
300:    SETERRQ7 - Macro that is called when an error has been detected,

302:    Synopsis:
303:    #include <petscsys.h>
304:    PetscErrorCode SETERRQ7(MPI_Comm comm,PetscErrorCode ierr,char *formatmessage,arg1,arg2,arg3)

306:    Collective

308:    Input Parameters:
309: +  comm - A communicator, so that the error can be collective
310: .  ierr - nonzero error code, see the list of standard error codes in include/petscerror.h
311: .  message - error message in the printf format
312: .  arg1 - argument (for example an integer, string or double)
313: .  arg2 - argument (for example an integer, string or double)
314: .  arg3 - argument (for example an integer, string or double)
315: .  arg4 - argument (for example an integer, string or double)
316: .  arg5 - argument (for example an integer, string or double)
317: .  arg6 - argument (for example an integer, string or double)
318: -  arg7 - argument (for example an integer, string or double)

320:   Level: beginner

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

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

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

329: .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), CHKERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2()
330: M*/
331: #define SETERRQ7(comm,ierr,s,a1,a2,a3,a4,a5,a6,a7) return PetscError(comm,__LINE__,PETSC_FUNCTION_NAME,__FILE__,ierr,PETSC_ERROR_INITIAL,s,a1,a2,a3,a4,a5,a6,a7)

333: /*MC
334:    SETERRQ8 - Macro that is called when an error has been detected,

336:    Synopsis:
337:    #include <petscsys.h>
338:    PetscErrorCode SETERRQ8(MPI_Comm comm,PetscErrorCode ierr,char *formatmessage,arg1,arg2,arg3)

340:    Collective

342:    Input Parameters:
343: +  comm - A communicator, so that the error can be collective
344: .  ierr - nonzero error code, see the list of standard error codes in include/petscerror.h
345: .  message - error message in the printf format
346: .  arg1 - argument (for example an integer, string or double)
347: .  arg2 - argument (for example an integer, string or double)
348: .  arg3 - argument (for example an integer, string or double)
349: .  arg4 - argument (for example an integer, string or double)
350: .  arg5 - argument (for example an integer, string or double)
351: .  arg6 - argument (for example an integer, string or double)
352: .  arg7 - argument (for example an integer, string or double)
353: -  arg8 - argument (for example an integer, string or double)

355:   Level: beginner

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

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

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

364: .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), CHKERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2()
365: M*/
366: #define SETERRQ8(comm,ierr,s,a1,a2,a3,a4,a5,a6,a7,a8) return PetscError(comm,__LINE__,PETSC_FUNCTION_NAME,__FILE__,ierr,PETSC_ERROR_INITIAL,s,a1,a2,a3,a4,a5,a6,a7,a8)

368: /*MC
369:    SETERRQ9 - Macro that is called when an error has been detected,

371:    Synopsis:
372:    #include <petscsys.h>
373:    PetscErrorCode SETERRQ9(MPI_Comm comm,PetscErrorCode ierr,char *formatmessage,arg1,arg2,arg3)

375:    Collective

377:    Input Parameters:
378: +  comm - A communicator, so that the error can be collective
379: .  ierr - nonzero error code, see the list of standard error codes in include/petscerror.h
380: .  message - error message in the printf format
381: .  arg1 - argument (for example an integer, string or double)
382: .  arg2 - argument (for example an integer, string or double)
383: .  arg3 - argument (for example an integer, string or double)
384: .  arg4 - argument (for example an integer, string or double)
385: .  arg5 - argument (for example an integer, string or double)
386: .  arg6 - argument (for example an integer, string or double)
387: .  arg7 - argument (for example an integer, string or double)
388: .  arg8 - argument (for example an integer, string or double)
389: -  arg9 - argument (for example an integer, string or double)

391:   Level: beginner

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

396:     There are also versions for 0 to 9 arguments.

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

400: .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), CHKERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2()
401: M*/
402: #define SETERRQ9(comm,ierr,s,a1,a2,a3,a4,a5,a6,a7,a8,a9) return PetscError(comm,__LINE__,PETSC_FUNCTION_NAME,__FILE__,ierr,PETSC_ERROR_INITIAL,s,a1,a2,a3,a4,a5,a6,a7,a8,a9)

404: /*MC
405:    SETERRABORT - Macro that can be called when an error has been detected,

407:    Synopsis:
408:    #include <petscsys.h>
409:    PetscErrorCode SETERRABORT(MPI_Comm comm,PetscErrorCode ierr,char *message)

411:    Collective

413:    Input Parameters:
414: +  comm - A communicator, so that the error can be collective
415: .  ierr - nonzero error code, see the list of standard error codes in include/petscerror.h
416: -  message - error message in the printf format

418:   Level: beginner

420:    Notes:
421:     This function just calls MPI_Abort().

423: .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), CHKERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2()
424: M*/
425: #define SETERRABORT(comm,ierr,s) do {PetscError(comm,__LINE__,PETSC_FUNCTION_NAME,__FILE__,ierr,PETSC_ERROR_INITIAL,s);MPI_Abort(comm,ierr);} while (0)

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

430:    Synopsis:
431:    #include <petscsys.h>
432:    PetscErrorCode CHKERRQ(PetscErrorCode ierr)

434:    Not Collective

436:    Input Parameters:
437: .  ierr - nonzero error code, see the list of standard error codes in include/petscerror.h

439:   Level: beginner

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

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

446:     CHKERRQ(ierr) is fundamentally a macro replacement for
447:          if (ierr) return(PetscError(...,ierr,...));

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

457: .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), SETERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2(), SETERRQ2()
458: M*/
459: #define CHKERRQ(ierr)          do {if (PetscUnlikely(ierr)) return PetscError(PETSC_COMM_SELF,__LINE__,PETSC_FUNCTION_NAME,__FILE__,ierr,PETSC_ERROR_REPEAT," ");} while (0)
460: #define CHKERRV(ierr)          do {if (PetscUnlikely(ierr)) {PetscError(PETSC_COMM_SELF,__LINE__,PETSC_FUNCTION_NAME,__FILE__,ierr,PETSC_ERROR_REPEAT," ");return;}} while(0)
461: #define CHKERRABORT(comm,ierr) do {if (PetscUnlikely(ierr)) {PetscError(PETSC_COMM_SELF,__LINE__,PETSC_FUNCTION_NAME,__FILE__,ierr,PETSC_ERROR_REPEAT," ");MPI_Abort(comm,ierr);}} while (0)
462: #define CHKERRCONTINUE(ierr)   do {if (PetscUnlikely(ierr)) {PetscError(PETSC_COMM_SELF,__LINE__,PETSC_FUNCTION_NAME,__FILE__,ierr,PETSC_ERROR_REPEAT," ");}} while (0)

464: PETSC_EXTERN PetscErrorCode PetscAbortFindSourceFile_Private(const char*,PetscInt*);

466: /*MC
467:    PETSCABORT - Call MPI_Abort with an informative error code

469:    Synopsis:
470:    #include <petscsys.h>
471:    PETSCABORT(MPI_Comm comm, PetscErrorCode ierr)

473:    Collective

475:    Input Parameters:
476: +  comm - A communicator, so that the error can be collective
477: -  ierr - nonzero error code, see the list of standard error codes in include/petscerror.h

479:    Level: beginner

481:    Notes: We pass MPI_Abort() an error code of format XX_YYYY_ZZZ, where XX, YYYY are an index and line number of the file
482:    where PETSCABORT is called, respectively. ZZZ is the PETSc error code.

484:    If XX is zero, this means that the call was made in the routine main().
485:    If XX is one, that means 1) the file is not in PETSc (it may be in users code); OR 2) the file is in PETSc but PetscAbortSourceFiles[]
486:      is out of date. PETSc developers have to update it.
487:    Otherwise, look up the value of XX in the table PetscAbortSourceFiles[] in src/sys/error/err.c to map XX back to the source file where the PETSCABORT() was called.

489: M*/
490: #define PETSCABORT(comm,ierr)  \
491:    do {                                                               \
492:       PetscInt       idx = 0;                                         \
493:       PetscMPIInt    errcode;                                         \
494:       PetscAbortFindSourceFile_Private(__FILE__,&idx);                \
495:       errcode = (PetscMPIInt)(idx*10000000 + __LINE__*1000 + ierr);   \
496:       MPI_Abort(comm,errcode);                                        \
497:    } while (0)

499: /*MC
500:    CHKERRMPI - Checks error code, if non-zero it calls the error handler and then returns

502:    Synopsis:
503:    #include <petscsys.h>
504:    PetscErrorCode CHKERRMPI(PetscErrorCode ierr)

506:    Not Collective

508:    Input Parameters:
509: .  ierr - nonzero error code, see the list of standard error codes in include/petscerror.h

511:   Level: developer

513:    Notes:
514:     This macro is FOR USE IN MPI CALLBACK FUNCTIONS ONLY, such as those passed to MPI_Comm_create_keyval(). It always returns the error code PETSC_MPI_ERROR_CODE
515:     which is registered with MPI_Add_error_code() when PETSc is initialized.

517: .seealso: CHKERRQ(), PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), SETERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2(), SETERRQ2()
518: M*/
519: #define CHKERRMPI(ierr)        do {if (PetscUnlikely(ierr)) return (PetscError(PETSC_COMM_SELF,__LINE__,PETSC_FUNCTION_NAME,__FILE__,ierr,PETSC_ERROR_REPEAT," "),PETSC_MPI_ERROR_CODE);} while (0)

521: #ifdef PETSC_CLANGUAGE_CXX

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

526:    Synopsis:
527:    #include <petscsys.h>
528:    void CHKERRXX(PetscErrorCode ierr)

530:    Not Collective

532:    Input Parameters:
533: .  ierr - nonzero error code, see the list of standard error codes in include/petscerror.h

535:   Level: beginner

537:    Notes:
538:     Once the error handler throws a ??? exception.

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

543: .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), SETERRQ(), CHKERRQ(), CHKMEMQ
544: M*/
545: #define CHKERRXX(ierr)  do {if (PetscUnlikely(ierr)) {PetscError(PETSC_COMM_SELF,__LINE__,PETSC_FUNCTION_NAME,__FILE__,ierr,PETSC_ERROR_IN_CXX,0);}} while(0)

547: #endif

549: #define CHKERRCUDA(err)   do {if (PetscUnlikely(err)) SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_LIB,"CUDA error %d",err);} while(0)
550: #define CHKERRCUBLAS(err) do {if (PetscUnlikely(err)) SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_LIB,"CUBLAS error %d",err);} while(0)

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

555:    Synopsis:
556:    #include <petscsys.h>
557:    CHKMEMQ;

559:    Not Collective

561:   Level: beginner

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

567:     Must run with the option -malloc_debug (-malloc_test in debug mode; or if PetscMallocSetDebug() called) to enable this option

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

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

573:     Use CHKMEMA for functions that return void

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

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

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

585:   Level: advanced

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

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

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

596: #if defined(__clang_analyzer__)
597: __attribute__((analyzer_noreturn))
598: #endif
599: PETSC_EXTERN PetscErrorCode PetscError(MPI_Comm,int,const char*,const char*,PetscErrorCode,PetscErrorType,const char*,...);

601: PETSC_EXTERN PetscErrorCode PetscErrorPrintfInitialize(void);
602: PETSC_EXTERN PetscErrorCode PetscErrorMessage(int,const char*[],char **);
603: PETSC_EXTERN PetscErrorCode PetscTraceBackErrorHandler(MPI_Comm,int,const char*,const char*,PetscErrorCode,PetscErrorType,const char*,void*);
604: PETSC_EXTERN PetscErrorCode PetscIgnoreErrorHandler(MPI_Comm,int,const char*,const char*,PetscErrorCode,PetscErrorType,const char*,void*);
605: PETSC_EXTERN PetscErrorCode PetscEmacsClientErrorHandler(MPI_Comm,int,const char*,const char*,PetscErrorCode,PetscErrorType,const char*,void*);
606: PETSC_EXTERN PetscErrorCode PetscMPIAbortErrorHandler(MPI_Comm,int,const char*,const char*,PetscErrorCode,PetscErrorType,const char*,void*);
607: PETSC_EXTERN PetscErrorCode PetscAbortErrorHandler(MPI_Comm,int,const char*,const char*,PetscErrorCode,PetscErrorType,const char*,void*);
608: PETSC_EXTERN PetscErrorCode PetscAttachDebuggerErrorHandler(MPI_Comm,int,const char*,const char*,PetscErrorCode,PetscErrorType,const char*,void*);
609: PETSC_EXTERN PetscErrorCode PetscReturnErrorHandler(MPI_Comm,int,const char*,const char*,PetscErrorCode,PetscErrorType,const char*,void*);
610: PETSC_EXTERN PetscErrorCode PetscPushErrorHandler(PetscErrorCode (*handler)(MPI_Comm,int,const char*,const char*,PetscErrorCode,PetscErrorType,const char*,void*),void*);
611: PETSC_EXTERN PetscErrorCode PetscPopErrorHandler(void);
612: PETSC_EXTERN PetscErrorCode PetscSignalHandlerDefault(int,void*);
613: PETSC_EXTERN PetscErrorCode PetscPushSignalHandler(PetscErrorCode (*)(int,void *),void*);
614: PETSC_EXTERN PetscErrorCode PetscPopSignalHandler(void);
616: PETSC_EXTERN void PetscSignalSegvCheckPointer(void);

618: /*MC
619:     PetscErrorPrintf - Prints error messages.

621:    Synopsis:
622:     #include <petscsys.h>
623:      PetscErrorCode (*PetscErrorPrintf)(const char format[],...);

625:     Not Collective

627:     Input Parameters:
628: .   format - the usual printf() format string

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

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

640:           Use
641:      PETSC_STDERR = FILE* obtained from a file open etc. to have stderr printed to the file.
642:      PETSC_STDOUT = FILE* obtained from a file open etc. to have stdout printed to the file.

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

647:    Level: developer

649:     Fortran Note:
650:     This routine is not supported in Fortran.


653: .seealso: PetscFPrintf(), PetscSynchronizedPrintf(), PetscHelpPrintf(), PetscPrintf(), PetscPushErrorHandler(), PetscVFPrintf(), PetscHelpPrintf()
654: M*/
655: PETSC_EXTERN PetscErrorCode (*PetscErrorPrintf)(const char[],...);

657: typedef enum {PETSC_FP_TRAP_OFF=0,PETSC_FP_TRAP_ON=1} PetscFPTrap;
658: PETSC_EXTERN PetscErrorCode PetscSetFPTrap(PetscFPTrap);
659: PETSC_EXTERN PetscErrorCode PetscFPTrapPush(PetscFPTrap);
660: PETSC_EXTERN PetscErrorCode PetscFPTrapPop(void);

662: /*
663:       Allows the code to build a stack frame as it runs
664: */

666: #define PETSCSTACKSIZE 64

668: typedef struct  {
669:   const char      *function[PETSCSTACKSIZE];
670:   const char      *file[PETSCSTACKSIZE];
671:         int       line[PETSCSTACKSIZE];
672:         PetscBool petscroutine[PETSCSTACKSIZE];
673:         int       currentsize;
674:         int       hotdepth;
675: } PetscStack;

677: PETSC_EXTERN PetscStack *petscstack;

679: PetscErrorCode  PetscStackCopy(PetscStack*,PetscStack*);
680: PetscErrorCode  PetscStackPrint(PetscStack *,FILE*);
681: #if defined(PETSC_SERIALIZE_FUNCTIONS)
682:  #include <petsc/private/petscfptimpl.h>
683: /*
684:    Registers the current function into the global function pointer to function name table

686:    Have to fix this to handle errors but cannot return error since used in PETSC_VIEWER_DRAW_() etc
687: */
688: #define PetscRegister__FUNCT__() do { \
689:   static PetscBool __chked = PETSC_FALSE; \
690:   if (!__chked) {\
691:   void *ptr; PetscDLSym(NULL,PETSC_FUNCTION_NAME,&ptr);\
692:   __chked = PETSC_TRUE;\
693:   }} while (0)
694: #else
695: #define PetscRegister__FUNCT__()
696: #endif

698: #if defined(PETSC_USE_DEBUG)
699: PETSC_STATIC_INLINE PetscBool PetscStackActive(void)
700: {
701:   return(petscstack ? PETSC_TRUE : PETSC_FALSE);
702: }

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

709: #define PetscStackPushNoCheck(funct,petsc_routine,hot)                        \
710:   do {                                                                        \
711:     PetscStackSAWsTakeAccess();                                                \
712:     if (petscstack && (petscstack->currentsize < PETSCSTACKSIZE)) {         \
713:       petscstack->function[petscstack->currentsize]  = funct;               \
714:       petscstack->file[petscstack->currentsize]      = __FILE__;            \
715:       petscstack->line[petscstack->currentsize]      = __LINE__;            \
716:       petscstack->petscroutine[petscstack->currentsize] = petsc_routine;    \
717:       petscstack->currentsize++;                                             \
718:     }                                                                         \
719:     if (petscstack) {                                                        \
720:       petscstack->hotdepth += (hot || petscstack->hotdepth);                \
721:     }                                                                         \
722:     PetscStackSAWsGrantAccess();                                               \
723:   } while (0)

725: #define PetscStackPopNoCheck                                            \
726:   do {                                                                  \
727:     PetscStackSAWsTakeAccess();                                          \
728:     if (petscstack && petscstack->currentsize > 0) {                  \
729:       petscstack->currentsize--;                                       \
730:       petscstack->function[petscstack->currentsize]  = 0;             \
731:       petscstack->file[petscstack->currentsize]      = 0;             \
732:       petscstack->line[petscstack->currentsize]      = 0;             \
733:       petscstack->petscroutine[petscstack->currentsize] = PETSC_FALSE;\
734:     }                                                                   \
735:     if (petscstack) {                                                  \
736:       petscstack->hotdepth = PetscMax(petscstack->hotdepth-1,0);      \
737:     }                                                                   \
738:     PetscStackSAWsGrantAccess();                                         \
739:   } while (0)

741: /*MC
743:       line of PETSc functions should be return(0);

745:    Synopsis:
746:    #include <petscsys.h>

749:    Not Collective

751:    Usage:
752: .vb
753:      int something;

756: .ve

758:    Notes:

761:      Not available in Fortran

763:    Level: developer


767: M*/
769:     PetscStackPushNoCheck(PETSC_FUNCTION_NAME,PETSC_TRUE,PETSC_FALSE); \
770:     PetscRegister__FUNCT__();                                          \
771:   } while (0)

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

777:    Synopsis:
778:    #include <petscsys.h>

781:    Not Collective

783:    Usage:
784: .vb
785:      int something;

788: .ve

790:    Notes:
791:      Not available in Fortran

793:    Level: developer


797: M*/
799:     PetscStackPushNoCheck(PETSC_FUNCTION_NAME,PETSC_TRUE,PETSC_TRUE);  \
800:     PetscRegister__FUNCT__();                                          \
801:   } while (0)

803: /*MC

806:    Synopsis:
807:    #include <petscsys.h>

810:    Not Collective

812:    Usage:
813: .vb
814:      int something;

817: .ve

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

822:       Not available in Fortran

825:       routine instead of as a PETSc library routine.

827:    Level: intermediate


831: M*/
833:   do {                                                                  \
834:     PetscStackPushNoCheck(PETSC_FUNCTION_NAME,PETSC_FALSE,PETSC_FALSE); \
835:     PetscRegister__FUNCT__();                                           \
836:   } while (0)


839: #define PetscStackPush(n) \
840:   do {                                                                  \
841:     PetscStackPushNoCheck(n,PETSC_FALSE,PETSC_FALSE);                   \
842:     CHKMEMQ;                                                            \
843:   } while (0)

845: #define PetscStackPop                           \
846:     do {                                        \
847:       CHKMEMQ;                                  \
848:       PetscStackPopNoCheck;                     \
849:     } while (0)

851: /*MC
852:    PetscFunctionReturn - Last executable line of each PETSc function
853:         used for error handling. Replaces return()

855:    Synopsis:
856:    #include <petscsys.h>
857:    void return(0);

859:    Not Collective

861:    Usage:
862: .vb
863:     ....
864:      return(0);
865:    }
866: .ve

868:    Notes:
869:      Not available in Fortran

871:    Level: developer


875: M*/
876: #define PetscFunctionReturn(a) \
877:   do {                                                                \
878:     PetscStackPopNoCheck;                                             \
879:     return(a);} while (0)

881: #define PetscFunctionReturnVoid() \
882:   do {                                                                \
883:     PetscStackPopNoCheck;                                             \
884:     return;} while (0)

886: #else

888: PETSC_STATIC_INLINE PetscBool PetscStackActive(void) {return PETSC_FALSE;}
889: #define PetscStackPushNoCheck(funct,petsc_routine,hot) do {} while (0)
890: #define PetscStackPopNoCheck                           do {} while (0)
894: #define PetscFunctionReturn(a)    return(a)
895: #define PetscFunctionReturnVoid() return
896: #define PetscStackPop             CHKMEMQ
897: #define PetscStackPush(f)         CHKMEMQ

899: #endif

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

904:    Input Parameters:
905: +   name - string that gives the name of the function being called
906: -   routine - actual call to the routine, including and 

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

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



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

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

920:    Input Parameters:
921: +   func-  name of the routine
922: -   args - arguments to the routine surrounded by ()

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

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

929: */
930: #define PetscStackCallStandard(func,args) do {                                                            \
931:     PetscErrorCode __ierr;                                                                                \
932:     PetscStackPush(#func);                                                                                \
933:     __func args;                                                                                   \
934:     PetscStackPop;                                                                                        \
935:     if (__ierr) SETERRQ2(PETSC_COMM_SELF,PETSC_ERR_LIB,"Error in %s(): error code %d",#func,(int)__ierr); \
936:   } while (0)

938: PETSC_EXTERN PetscErrorCode PetscStackCreate(void);
939: PETSC_EXTERN PetscErrorCode PetscStackView(FILE*);
940: PETSC_EXTERN PetscErrorCode PetscStackDestroy(void);

942: #endif