Actual source code: petscerror.h

petsc-master 2020-10-26
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 src/sys/f90-mod/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_GPU_RESOURCE     96  /* unable to load a GPU resource, for example cuBLAS */
 64: #define PETSC_ERR_GPU              97  /* An error from a GPU call, this may be due to lack of resources on the GPU or a true error in the call */
 65: #define PETSC_ERR_MAX_VALUE        98  /* this is always the one more than the largest error code */

 67: #define PetscStringizeArg(a) #a
 68: #define PetscStringize(a) PetscStringizeArg(a)


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

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

 78:    Collective

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

 85:   Level: beginner

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

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

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

 94:    Fortran Notes:
 95:       SETERRQ() may be called from Fortran subroutines but SETERRA() must be called from the
 96:       Fortran main program.

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

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

105:    Synopsis:
106: #include <petscsys.h>
107:    PetscErrorCode SETERRMPI(MPI_Comm comm,PetscErrorCode ierr,char *message)

109:    Collective

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

116:   Level: developer

118:    Notes:
119:     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
120:     which is registered with MPI_Add_error_code() when PETSc is initialized.

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

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

129:    Synopsis:
130: #include <petscsys.h>
131:    PetscErrorCode SETERRQ1(MPI_Comm comm,PetscErrorCode ierr,char *formatmessage,arg)

133:    Collective

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

141:   Level: beginner

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

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

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

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

155:    Synopsis:
156: #include <petscsys.h>
157:    PetscErrorCode SETERRQ2(MPI_Comm comm,PetscErrorCode ierr,char *formatmessage,arg1,arg2)

159:    Collective

161:    Input Parameters:
162: +  comm - A communicator, so that the error can be collective
163: .  ierr - nonzero error code, see the list of standard error codes in include/petscerror.h
164: .  message - error message in the printf format
165: .  arg1 - argument (for example an integer, string or double)
166: -  arg2 - argument (for example an integer, string or double)

168:   Level: beginner

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

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

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

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

182:    Synopsis:
183: #include <petscsys.h>
184:    PetscErrorCode SETERRQ3(MPI_Comm comm,PetscErrorCode ierr,char *formatmessage,arg1,arg2,arg3)

186:    Collective

188:    Input Parameters:
189: +  comm - A communicator, so that the error can be collective
190: .  ierr - nonzero error code, see the list of standard error codes in include/petscerror.h
191: .  message - error message in the printf format
192: .  arg1 - argument (for example an integer, string or double)
193: .  arg2 - argument (for example an integer, string or double)
194: -  arg3 - argument (for example an integer, string or double)

196:   Level: beginner

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

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

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

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

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

212:    Synopsis:
213: #include <petscsys.h>
214:    PetscErrorCode SETERRQ4(MPI_Comm comm,PetscErrorCode ierr,char *formatmessage,arg1,arg2,arg3,arg4)

216:    Collective

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

227:   Level: beginner

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

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

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

236: .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), CHKERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2()
237: M*/
238: #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)

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

243:    Synopsis:
244: #include <petscsys.h>
245:    PetscErrorCode SETERRQ5(MPI_Comm comm,PetscErrorCode ierr,char *formatmessage,arg1,arg2,arg3,arg4,arg5)

247:    Collective

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

259:   Level: beginner

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

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

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

268: .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), CHKERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2()
269: M*/
270: #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)

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

275:    Synopsis:
276: #include <petscsys.h>
277:    PetscErrorCode SETERRQ6(MPI_Comm comm,PetscErrorCode ierr,char *formatmessage,arg1,arg2,arg3,arg4,arg5,arg6)

279:    Collective

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

292:   Level: beginner

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

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

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

301: .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), CHKERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2()
302: M*/
303: #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)

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

308:    Synopsis:
309: #include <petscsys.h>
310:    PetscErrorCode SETERRQ7(MPI_Comm comm,PetscErrorCode ierr,char *formatmessage,arg1,arg2,arg3,arg4,arg5,arg6,arg7)

312:    Collective

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

326:   Level: beginner

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

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

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

335: .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), CHKERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2()
336: M*/
337: #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)

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

342:    Synopsis:
343: #include <petscsys.h>
344:    PetscErrorCode SETERRQ8(MPI_Comm comm,PetscErrorCode ierr,char *formatmessage,arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8)

346:    Collective

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

361:   Level: beginner

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

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

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

370: .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), CHKERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2()
371: M*/
372: #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)

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

377:    Synopsis:
378: #include <petscsys.h>
379:    PetscErrorCode SETERRQ9(MPI_Comm comm,PetscErrorCode ierr,char *formatmessage,arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9)

381:    Collective

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

397:   Level: beginner

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

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

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

406: .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), CHKERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2()
407: M*/
408: #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)

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

413:    Synopsis:
414: #include <petscsys.h>
415:    PetscErrorCode SETERRABORT(MPI_Comm comm,PetscErrorCode ierr,char *message)

417:    Collective

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

424:   Level: beginner

426:    Notes:
427:     This function just calls MPI_Abort().

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

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

436:    Synopsis:
437: #include <petscsys.h>
438:    PetscErrorCode CHKERRQ(PetscErrorCode ierr)

440:    Not Collective

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

445:   Level: beginner

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

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

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

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

463: .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), SETERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2(), SETERRQ2()
464: M*/
465: #define CHKERRQ(ierr)          do {PetscErrorCode ierr__ = (ierr); if (PetscUnlikely(ierr__)) return PetscError(PETSC_COMM_SELF,__LINE__,PETSC_FUNCTION_NAME,__FILE__,ierr__,PETSC_ERROR_REPEAT," ");} while (0)
466: #define CHKERRV(ierr)          do {PetscErrorCode ierr__ = (ierr); if (PetscUnlikely(ierr__)) {PetscError(PETSC_COMM_SELF,__LINE__,PETSC_FUNCTION_NAME,__FILE__,ierr__,PETSC_ERROR_REPEAT," ");return;}} while (0)
467: #define CHKERRABORT(comm,ierr) do {PetscErrorCode ierr__ = (ierr); if (PetscUnlikely(ierr__)) {PetscError(PETSC_COMM_SELF,__LINE__,PETSC_FUNCTION_NAME,__FILE__,ierr__,PETSC_ERROR_REPEAT," ");MPI_Abort(comm,ierr);}} while (0)
468: #define CHKERRCONTINUE(ierr)   do {PetscErrorCode ierr__ = (ierr); if (PetscUnlikely(ierr__)) {PetscError(PETSC_COMM_SELF,__LINE__,PETSC_FUNCTION_NAME,__FILE__,ierr__,PETSC_ERROR_REPEAT," ");}} while (0)

470: PETSC_EXTERN PetscErrorCode PetscAbortFindSourceFile_Private(const char*,PetscInt*);
471: PETSC_EXTERN PetscBool petscwaitonerror,petscindebugger;

473: /*MC
474:    PETSCABORT - Call MPI_Abort with an informative error code

476:    Synopsis:
477: #include <petscsys.h>
478:    PETSCABORT(MPI_Comm comm, PetscErrorCode ierr)

480:    Collective

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

486:    Level: advanced

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

492:    If XX is zero, this means that the call was made in the routine main().
493:    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[]
494:      is out of date. PETSc developers have to update it.
495:    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.

497:    If the option -start_in_debugger was used then this calls abort() to stop the program in the debugger.

499: M*/
500: #define PETSCABORT(comm,ierr)  \
501:    do {                                                               \
502:       PetscInt       idx = 0;                                         \
503:       PetscMPIInt    errcode;                                         \
504:       PetscAbortFindSourceFile_Private(__FILE__,&idx);                \
505:       errcode = (PetscMPIInt)(idx*10000000 + __LINE__*1000 + ierr);   \
506:       if (petscwaitonerror) PetscSleep(1000);                         \
507:       if (petscindebugger) abort();                                   \
508:       else MPI_Abort(comm,errcode);                                   \
509:    } while (0)

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

514:    Synopsis:
515: #include <petscsys.h>
516:    PetscErrorCode CHKERRMPI(PetscErrorCode ierr)

518:    Not Collective

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

523:   Level: developer

525:    Notes:
526:     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
527:     which is registered with MPI_Add_error_code() when PETSc is initialized.

529: .seealso: CHKERRQ(), PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), SETERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2(), SETERRQ2()
530: M*/
531: #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)

533: #ifdef PETSC_CLANGUAGE_CXX

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

538:    Synopsis:
539: #include <petscsys.h>
540:    void CHKERRXX(PetscErrorCode ierr)

542:    Not Collective

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

547:   Level: beginner

549:    Notes:
550:     Once the error handler throws a ??? exception.

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

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

559: #endif

561: #if defined(PETSC_HAVE_CUDA)
562: #define CHKERRCUSOLVER(err) do {if (PetscUnlikely(err)) SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_LIB,"CUSOLVER error %d",err);} while (0)
563: #endif
564: /*MC
565:    CHKMEMQ - Checks the memory for corruption, calls error handler if any is detected

567:    Synopsis:
568: #include <petscsys.h>
569:    CHKMEMQ;

571:    Not Collective

573:   Level: beginner

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

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

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

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

585:     Use CHKMEMA for functions that return void

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

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

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

597:   Level: advanced

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

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

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

608: #if defined(__clang_analyzer__)
609: __attribute__((analyzer_noreturn))
610: #endif
611: PETSC_EXTERN PetscErrorCode PetscError(MPI_Comm,int,const char*,const char*,PetscErrorCode,PetscErrorType,const char*,...);

613: PETSC_EXTERN PetscErrorCode PetscErrorPrintfInitialize(void);
614: PETSC_EXTERN PetscErrorCode PetscErrorMessage(int,const char*[],char **);
615: PETSC_EXTERN PetscErrorCode PetscTraceBackErrorHandler(MPI_Comm,int,const char*,const char*,PetscErrorCode,PetscErrorType,const char*,void*);
616: PETSC_EXTERN PetscErrorCode PetscIgnoreErrorHandler(MPI_Comm,int,const char*,const char*,PetscErrorCode,PetscErrorType,const char*,void*);
617: PETSC_EXTERN PetscErrorCode PetscEmacsClientErrorHandler(MPI_Comm,int,const char*,const char*,PetscErrorCode,PetscErrorType,const char*,void*);
618: PETSC_EXTERN PetscErrorCode PetscMPIAbortErrorHandler(MPI_Comm,int,const char*,const char*,PetscErrorCode,PetscErrorType,const char*,void*);
619: PETSC_EXTERN PetscErrorCode PetscAbortErrorHandler(MPI_Comm,int,const char*,const char*,PetscErrorCode,PetscErrorType,const char*,void*);
620: PETSC_EXTERN PetscErrorCode PetscAttachDebuggerErrorHandler(MPI_Comm,int,const char*,const char*,PetscErrorCode,PetscErrorType,const char*,void*);
621: PETSC_EXTERN PetscErrorCode PetscReturnErrorHandler(MPI_Comm,int,const char*,const char*,PetscErrorCode,PetscErrorType,const char*,void*);
622: PETSC_EXTERN PetscErrorCode PetscPushErrorHandler(PetscErrorCode (*handler)(MPI_Comm,int,const char*,const char*,PetscErrorCode,PetscErrorType,const char*,void*),void*);
623: PETSC_EXTERN PetscErrorCode PetscPopErrorHandler(void);
624: PETSC_EXTERN PetscErrorCode PetscSignalHandlerDefault(int,void*);
625: PETSC_EXTERN PetscErrorCode PetscPushSignalHandler(PetscErrorCode (*)(int,void *),void*);
626: PETSC_EXTERN PetscErrorCode PetscPopSignalHandler(void);
628: PETSC_EXTERN void PetscSignalSegvCheckPointerOrMpi(void);
629: PETSC_DEPRECATED_FUNCTION("Use PetscSignalSegvCheckPointerOrMpi() (since version 3.13)") PETSC_STATIC_INLINE void PetscSignalSegvCheckPointer(void) {PetscSignalSegvCheckPointerOrMpi();}

631: /*MC
632:     PetscErrorPrintf - Prints error messages.

634:    Synopsis:
635: #include <petscsys.h>
636:      PetscErrorCode (*PetscErrorPrintf)(const char format[],...);

638:     Not Collective

640:     Input Parameters:
641: .   format - the usual printf() format string

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

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

653:           Use
654:      PETSC_STDERR = FILE* obtained from a file open etc. to have stderr printed to the file.
655:      PETSC_STDOUT = FILE* obtained from a file open etc. to have stdout printed to the file.

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

660:    Level: developer

662:     Fortran Note:
663:     This routine is not supported in Fortran.


666: .seealso: PetscFPrintf(), PetscSynchronizedPrintf(), PetscHelpPrintf(), PetscPrintf(), PetscPushErrorHandler(), PetscVFPrintf(), PetscHelpPrintf()
667: M*/
668: PETSC_EXTERN PetscErrorCode (*PetscErrorPrintf)(const char[],...);

670: typedef enum {PETSC_FP_TRAP_OFF=0,PETSC_FP_TRAP_ON=1} PetscFPTrap;
671: PETSC_EXTERN PetscErrorCode PetscSetFPTrap(PetscFPTrap);
672: PETSC_EXTERN PetscErrorCode PetscFPTrapPush(PetscFPTrap);
673: PETSC_EXTERN PetscErrorCode PetscFPTrapPop(void);
674: PETSC_EXTERN PetscErrorCode PetscDetermineInitialFPTrap(void);

676: /*
677:       Allows the code to build a stack frame as it runs
678: */

680: #define PETSCSTACKSIZE 64

682: typedef struct  {
683:   const char      *function[PETSCSTACKSIZE];
684:   const char      *file[PETSCSTACKSIZE];
685:         int       line[PETSCSTACKSIZE];
686:         PetscBool petscroutine[PETSCSTACKSIZE];
687:         int       currentsize;
688:         int       hotdepth;
689: } PetscStack;

691: PETSC_EXTERN PetscStack *petscstack;

693: PetscErrorCode  PetscStackCopy(PetscStack*,PetscStack*);
694: PetscErrorCode  PetscStackPrint(PetscStack *,FILE*);
695: #if defined(PETSC_SERIALIZE_FUNCTIONS)
696: #include <petsc/private/petscfptimpl.h>
697: /*
698:    Registers the current function into the global function pointer to function name table

700:    Have to fix this to handle errors but cannot return error since used in PETSC_VIEWER_DRAW_() etc
701: */
702: #define PetscRegister__FUNCT__() do { \
703:   static PetscBool __chked = PETSC_FALSE; \
704:   if (!__chked) {\
705:   void *ptr; PetscDLSym(NULL,PETSC_FUNCTION_NAME,&ptr);\
706:   __chked = PETSC_TRUE;\
707:   }} while (0)
708: #else
709: #define PetscRegister__FUNCT__()
710: #endif

712: #if defined(PETSC_USE_DEBUG)
713: PETSC_STATIC_INLINE PetscBool PetscStackActive(void)
714: {
715:   return(petscstack ? PETSC_TRUE : PETSC_FALSE);
716: }

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

723: #define PetscStackPushNoCheck(funct,petsc_routine,hot)                        \
724:   do {                                                                        \
725:     PetscStackSAWsTakeAccess();                                                \
726:     if (petscstack && (petscstack->currentsize < PETSCSTACKSIZE)) {         \
727:       petscstack->function[petscstack->currentsize]  = funct;               \
728:       petscstack->file[petscstack->currentsize]      = __FILE__;            \
729:       petscstack->line[petscstack->currentsize]      = __LINE__;            \
730:       petscstack->petscroutine[petscstack->currentsize] = petsc_routine;    \
731:       petscstack->currentsize++;                                             \
732:     }                                                                         \
733:     if (petscstack) {                                                        \
734:       petscstack->hotdepth += (hot || petscstack->hotdepth);                \
735:     }                                                                         \
736:     PetscStackSAWsGrantAccess();                                               \
737:   } while (0)

739: #define PetscStackPopNoCheck                                            \
740:   do {                                                                  \
741:     PetscStackSAWsTakeAccess();                                          \
742:     if (petscstack && petscstack->currentsize > 0) {                  \
743:       petscstack->currentsize--;                                       \
744:       petscstack->function[petscstack->currentsize]  = NULL;             \
745:       petscstack->file[petscstack->currentsize]      = NULL;             \
746:       petscstack->line[petscstack->currentsize]      = 0;             \
747:       petscstack->petscroutine[petscstack->currentsize] = PETSC_FALSE;\
748:     }                                                                   \
749:     if (petscstack) {                                                  \
750:       petscstack->hotdepth = PetscMax(petscstack->hotdepth-1,0);      \
751:     }                                                                   \
752:     PetscStackSAWsGrantAccess();                                         \
753:   } while (0)

755: /*MC
757:       line of PETSc functions should be return(0);

759:    Synopsis:
760: #include <petscsys.h>

763:    Not Collective

765:    Usage:
766: .vb
767:      int something;

770: .ve

772:    Notes:

775:      Not available in Fortran

777:    Level: developer


781: M*/
783:     PetscStackPushNoCheck(PETSC_FUNCTION_NAME,PETSC_TRUE,PETSC_FALSE); \
784:     PetscRegister__FUNCT__();                                          \
785:   } while (0)

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

791:    Synopsis:
792: #include <petscsys.h>

795:    Not Collective

797:    Usage:
798: .vb
799:      int something;

802: .ve

804:    Notes:
805:      Not available in Fortran

807:    Level: developer


811: M*/
813:     PetscStackPushNoCheck(PETSC_FUNCTION_NAME,PETSC_TRUE,PETSC_TRUE);  \
814:     PetscRegister__FUNCT__();                                          \
815:   } while (0)

817: /*MC

820:    Synopsis:
821: #include <petscsys.h>

824:    Not Collective

826:    Usage:
827: .vb
828:      int something;

831: .ve

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

836:       Not available in Fortran

839:       routine instead of as a PETSc library routine.

841:    Level: intermediate


845: M*/
847:   do {                                                                  \
848:     PetscStackPushNoCheck(PETSC_FUNCTION_NAME,PETSC_FALSE,PETSC_FALSE); \
849:     PetscRegister__FUNCT__();                                           \
850:   } while (0)


853: #define PetscStackPush(n) \
854:   do {                                                                  \
855:     PetscStackPushNoCheck(n,PETSC_FALSE,PETSC_FALSE);                   \
856:     CHKMEMQ;                                                            \
857:   } while (0)

859: #define PetscStackPop                           \
860:     do {                                        \
861:       CHKMEMQ;                                  \
862:       PetscStackPopNoCheck;                     \
863:     } while (0)

865: /*MC
866:    PetscFunctionReturn - Last executable line of each PETSc function
867:         used for error handling. Replaces return()

869:    Synopsis:
870: #include <petscsys.h>
871:    void return(0);

873:    Not Collective

875:    Usage:
876: .vb
877:     ....
878:      return(0);
879:    }
880: .ve

882:    Notes:
883:      Not available in Fortran

885:    Level: developer


889: M*/
890: #define PetscFunctionReturn(a) \
891:   do {                                                                \
892:     PetscStackPopNoCheck;                                             \
893:     return(a);} while (0)

895: #define PetscFunctionReturnVoid() \
896:   do {                                                                \
897:     PetscStackPopNoCheck;                                             \
898:     return;} while (0)

900: #else

902: PETSC_STATIC_INLINE PetscBool PetscStackActive(void) {return PETSC_FALSE;}
903: #define PetscStackPushNoCheck(funct,petsc_routine,hot) do {} while (0)
904: #define PetscStackPopNoCheck                           do {} while (0)
908: #define PetscFunctionReturn(a)    return(a)
909: #define PetscFunctionReturnVoid() return
910: #define PetscStackPop             CHKMEMQ
911: #define PetscStackPush(f)         CHKMEMQ

913: #endif

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

918:    Input Parameters:
919: +   name - string that gives the name of the function being called
920: -   routine - actual call to the routine, including and 

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

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



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

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

934:    Input Parameters:
935: +   func-  name of the routine
936: -   args - arguments to the routine surrounded by ()

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

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

943: */
944: #define PetscStackCallStandard(func,args) do {                                                            \
945:     PetscErrorCode __ierr;                                                                                \
946:     PetscStackPush(#func);                                                                                \
947:     __func args;                                                                                   \
948:     PetscStackPop;                                                                                        \
949:     if (__ierr) SETERRQ2(PETSC_COMM_SELF,PETSC_ERR_LIB,"Error in %s(): error code %d",#func,(int)__ierr); \
950:   } while (0)

952: PETSC_EXTERN PetscErrorCode PetscStackCreate(void);
953: PETSC_EXTERN PetscErrorCode PetscStackView(FILE*);
954: PETSC_EXTERN PetscErrorCode PetscStackDestroy(void);

956: #endif