Actual source code: petscerror.h

petsc-3.8.4 2018-03-24
Report Typos and Errors
  1: /*
  2:     Contains all error handling interfaces for PETSc.
  3: */

  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 wrote options which should not be changed */

 62: #define PETSC_ERR_MAX_VALUE        94  /* this is always the one more than the largest error code */

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

 67: #if defined(PETSC_USE_ERRORCHECKING)

 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 on MPI_Comm

 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:     In Fortran MPI_Abort() is always called

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

 94:    Concepts: error^setting condition

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

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

103:    Synopsis:
104:    #include <petscsys.h>
105:    PetscErrorCode SETERRQ1(MPI_Comm comm,PetscErrorCode ierr,char *formatmessage,arg)

107:    Collective on MPI_Comm

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

115:   Level: beginner

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

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

122:    Concepts: error^setting condition

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

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

131:    Synopsis:
132:    #include <petscsys.h>
133:    PetscErrorCode SETERRQ2(MPI_Comm comm,PetscErrorCode ierr,char *formatmessage,arg1,arg2)

135:    Collective on MPI_Comm

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

144:   Level: beginner

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

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

151:    Concepts: error^setting condition

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

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

160:    Synopsis:
161:    #include <petscsys.h>
162:    PetscErrorCode SETERRQ3(MPI_Comm comm,PetscErrorCode ierr,char *formatmessage,arg1,arg2,arg3)

164:    Collective on MPI_Comm

166:    Input Parameters:
167: +  comm - A communicator, so that the error can be collective
168: .  ierr - nonzero error code, see the list of standard error codes in include/petscerror.h
169: .  message - error message in the printf format
170: .  arg1 - argument (for example an integer, string or double)
171: .  arg2 - argument (for example an integer, string or double)
172: -  arg3 - argument (for example an integer, string or double)

174:   Level: beginner

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

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

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

183:    Concepts: error^setting condition

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

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

192:    Synopsis:
193:    #include <petscsys.h>
194:    PetscErrorCode SETERRQ4(MPI_Comm comm,PetscErrorCode ierr,char *formatmessage,arg1,arg2,arg3)

196:    Collective on MPI_Comm

198:    Input Parameters:
199: +  comm - A communicator, so that the error can be collective
200: .  ierr - nonzero error code, see the list of standard error codes in include/petscerror.h
201: .  message - error message in the printf format
202: .  arg1 - argument (for example an integer, string or double)
203: .  arg2 - argument (for example an integer, string or double)
204: .  arg3 - argument (for example an integer, string or double)
205: -  arg4 - argument (for example an integer, string or double)

207:   Level: beginner

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

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

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

216:    Concepts: error^setting condition

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

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

225:    Synopsis:
226:    #include <petscsys.h>
227:    PetscErrorCode SETERRQ5(MPI_Comm comm,PetscErrorCode ierr,char *formatmessage,arg1,arg2,arg3)

229:    Collective on MPI_COmm

231:    Input Parameters:
232: +  comm - A communicator, so that the error can be collective
233: .  ierr - nonzero error code, see the list of standard error codes in include/petscerror.h
234: .  message - error message in the printf format
235: .  arg1 - argument (for example an integer, string or double)
236: .  arg2 - argument (for example an integer, string or double)
237: .  arg3 - argument (for example an integer, string or double)
238: .  arg4 - argument (for example an integer, string or double)
239: -  arg5 - argument (for example an integer, string or double)

241:   Level: beginner

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

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

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

250:    Concepts: error^setting condition

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

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

259:    Synopsis:
260:    #include <petscsys.h>
261:    PetscErrorCode SETERRQ6(MPI_Comm comm,PetscErrorCode ierr,char *formatmessage,arg1,arg2,arg3)

263:    Collective on MPI_Comm

265:    Input Parameters:
266: +  comm - A communicator, so that the error can be collective
267: .  ierr - nonzero error code, see the list of standard error codes in include/petscerror.h
268: .  message - error message in the printf format
269: .  arg1 - argument (for example an integer, string or double)
270: .  arg2 - argument (for example an integer, string or double)
271: .  arg3 - argument (for example an integer, string or double)
272: .  arg4 - argument (for example an integer, string or double)
273: .  arg5 - argument (for example an integer, string or double)
274: -  arg6 - argument (for example an integer, string or double)

276:   Level: beginner

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

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

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

285:    Concepts: error^setting condition

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

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

294:    Synopsis:
295:    #include <petscsys.h>
296:    PetscErrorCode SETERRQ7(MPI_Comm comm,PetscErrorCode ierr,char *formatmessage,arg1,arg2,arg3)

298:    Collective on MPI_Comm

300:    Input Parameters:
301: +  comm - A communicator, so that the error can be collective
302: .  ierr - nonzero error code, see the list of standard error codes in include/petscerror.h
303: .  message - error message in the printf format
304: .  arg1 - argument (for example an integer, string or double)
305: .  arg2 - argument (for example an integer, string or double)
306: .  arg3 - argument (for example an integer, string or double)
307: .  arg4 - argument (for example an integer, string or double)
308: .  arg5 - argument (for example an integer, string or double)
309: .  arg6 - argument (for example an integer, string or double)
310: -  arg7 - argument (for example an integer, string or double)

312:   Level: beginner

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

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

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

321:    Concepts: error^setting condition

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

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

330:    Synopsis:
331:    #include <petscsys.h>
332:    PetscErrorCode SETERRQ8(MPI_Comm comm,PetscErrorCode ierr,char *formatmessage,arg1,arg2,arg3)

334:    Collective on MPI_Comm

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

349:   Level: beginner

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

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

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

358:    Concepts: error^setting condition

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

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

367:    Synopsis:
368:    #include <petscsys.h>
369:    PetscErrorCode SETERRABORT(MPI_Comm comm,PetscErrorCode ierr,char *message)

371:    Collective on MPI_Comm

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

378:   Level: beginner

380:    Notes:
381:     This function just calls MPI_Abort().

383:    Concepts: error^setting condition

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

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

392:    Synopsis:
393:    #include <petscsys.h>
394:    PetscErrorCode CHKERRQ(PetscErrorCode ierr)

396:    Not Collective

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

401:   Level: beginner

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

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

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

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

419:     In Fortran MPI_Abort() is always called

421:    Concepts: error^setting condition

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

427: #define CHKERRV(ierr)          do {if (PetscUnlikely(ierr)) {PetscError(PETSC_COMM_SELF,__LINE__,PETSC_FUNCTION_NAME,__FILE__,ierr,PETSC_ERROR_REPEAT," ");return;}} while(0)
428: #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)
429: #define CHKERRCONTINUE(ierr)   do {if (PetscUnlikely(ierr)) {PetscError(PETSC_COMM_SELF,__LINE__,PETSC_FUNCTION_NAME,__FILE__,ierr,PETSC_ERROR_REPEAT," ");}} while (0)

431: #ifdef PETSC_CLANGUAGE_CXX

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

436:    Synopsis:
437:    #include <petscsys.h>
438:    void CHKERRXX(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 throws a ??? exception.

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

453:    Concepts: error^setting condition

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

459: #endif

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

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

467:    Synopsis:
468:    #include <petscsys.h>
469:    CHKMEMQ;

471:    Not Collective

473:   Level: beginner

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

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

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

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

485:     Use CHKMEMA for functions that return void

487:    Concepts: memory corruption

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

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

496: #else /* PETSC_USE_ERRORCHECKING */

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

502: #define SETERRQ(c,ierr,s)
503: #define SETERRQ1(c,ierr,s,a1)
504: #define SETERRQ2(c,ierr,s,a1,a2)
505: #define SETERRQ3(c,ierr,s,a1,a2,a3)
506: #define SETERRQ4(c,ierr,s,a1,a2,a3,a4)
507: #define SETERRQ5(c,ierr,s,a1,a2,a3,a4,a5)
508: #define SETERRQ6(c,ierr,s,a1,a2,a3,a4,a5,a6)
509: #define SETERRQ7(c,ierr,s,a1,a2,a3,a4,a5,a6,a7)
510: #define SETERRQ8(c,ierr,s,a1,a2,a3,a4,a5,a6,a7,a8)
511: #define SETERRABORT(comm,ierr,s)

513: #define CHKERRQ(ierr)     ;
514: #define CHKERRV(ierr)     ;
515: #define CHKERRABORT(comm,n) ;
516: #define CHKERRCONTINUE(ierr) ;
517: #define CHKMEMQ        ;
518: #define CHKERRCUDA(err) ;
519: #define CHKERRCUBLAS(err) ;

521: #ifdef PETSC_CLANGUAGE_CXX
522: #define CHKERRXX(ierr) ;
523: #endif

525: #endif /* PETSC_USE_ERRORCHECKING */

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

530:   Level: advanced

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

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

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

540: #if defined(__clang_analyzer__)
541: __attribute__((analyzer_noreturn))
542: #endif
543: PETSC_EXTERN PetscErrorCode PetscError(MPI_Comm,int,const char*,const char*,PetscErrorCode,PetscErrorType,const char*,...);

545: PETSC_EXTERN PetscErrorCode PetscErrorPrintfInitialize(void);
546: PETSC_EXTERN PetscErrorCode PetscErrorMessage(int,const char*[],char **);
547: PETSC_EXTERN PetscErrorCode PetscTraceBackErrorHandler(MPI_Comm,int,const char*,const char*,PetscErrorCode,PetscErrorType,const char*,void*);
548: PETSC_EXTERN PetscErrorCode PetscIgnoreErrorHandler(MPI_Comm,int,const char*,const char*,PetscErrorCode,PetscErrorType,const char*,void*);
549: PETSC_EXTERN PetscErrorCode PetscEmacsClientErrorHandler(MPI_Comm,int,const char*,const char*,PetscErrorCode,PetscErrorType,const char*,void*);
550: PETSC_EXTERN PetscErrorCode PetscMPIAbortErrorHandler(MPI_Comm,int,const char*,const char*,PetscErrorCode,PetscErrorType,const char*,void*);
551: PETSC_EXTERN PetscErrorCode PetscAbortErrorHandler(MPI_Comm,int,const char*,const char*,PetscErrorCode,PetscErrorType,const char*,void*);
552: PETSC_EXTERN PetscErrorCode PetscAttachDebuggerErrorHandler(MPI_Comm,int,const char*,const char*,PetscErrorCode,PetscErrorType,const char*,void*);
553: PETSC_EXTERN PetscErrorCode PetscReturnErrorHandler(MPI_Comm,int,const char*,const char*,PetscErrorCode,PetscErrorType,const char*,void*);
554: PETSC_EXTERN PetscErrorCode PetscPushErrorHandler(PetscErrorCode (*handler)(MPI_Comm,int,const char*,const char*,PetscErrorCode,PetscErrorType,const char*,void*),void*);
555: PETSC_EXTERN PetscErrorCode PetscPopErrorHandler(void);
556: PETSC_EXTERN PetscErrorCode PetscSignalHandlerDefault(int,void*);
557: PETSC_EXTERN PetscErrorCode PetscPushSignalHandler(PetscErrorCode (*)(int,void *),void*);
558: PETSC_EXTERN PetscErrorCode PetscPopSignalHandler(void);

561: /*MC
562:     PetscErrorPrintf - Prints error messages.

564:    Synopsis:
565:     #include <petscsys.h>
566:      PetscErrorCode (*PetscErrorPrintf)(const char format[],...);

568:     Not Collective

570:     Input Parameters:
571: .   format - the usual printf() format string

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

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

582:           Use
583:      PETSC_STDERR = FILE* obtained from a file open etc. to have stderr printed to the file.
584:      PETSC_STDOUT = FILE* obtained from a file open etc. to have stdout printed to the file.

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

589:    Level: developer

591:     Fortran Note:
592:     This routine is not supported in Fortran.

594:     Concepts: error messages^printing
595:     Concepts: printing^error messages

597: .seealso: PetscFPrintf(), PetscSynchronizedPrintf(), PetscHelpPrintf(), PetscPrintf(), PetscErrorHandlerPush(), PetscVFPrintf(), PetscHelpPrintf()
598: M*/
599: PETSC_EXTERN PetscErrorCode (*PetscErrorPrintf)(const char[],...);

601: typedef enum {PETSC_FP_TRAP_OFF=0,PETSC_FP_TRAP_ON=1} PetscFPTrap;
602: PETSC_EXTERN PetscErrorCode PetscSetFPTrap(PetscFPTrap);
603: PETSC_EXTERN PetscErrorCode PetscFPTrapPush(PetscFPTrap);
604: PETSC_EXTERN PetscErrorCode PetscFPTrapPop(void);

606: /*
607:       Allows the code to build a stack frame as it runs
608: */

610: #define PETSCSTACKSIZE 64

612: typedef struct  {
613:   const char      *function[PETSCSTACKSIZE];
614:   const char      *file[PETSCSTACKSIZE];
615:         int       line[PETSCSTACKSIZE];
616:         PetscBool petscroutine[PETSCSTACKSIZE];
617:         int       currentsize;
618:         int       hotdepth;
619: } PetscStack;

621: PETSC_EXTERN PetscStack *petscstack;

623: PetscErrorCode  PetscStackCopy(PetscStack*,PetscStack*);
624: PetscErrorCode  PetscStackPrint(PetscStack *,FILE*);
625: #if defined(PETSC_SERIALIZE_FUNCTIONS)
626:  #include <petsc/private/petscfptimpl.h>
627: /*
628:    Registers the current function into the global function pointer to function name table

630:    Have to fix this to handle errors but cannot return error since used in PETSC_VIEWER_DRAW_() etc
631: */
632: #define PetscRegister__FUNCT__() do { \
633:   static PetscBool __chked = PETSC_FALSE; \
634:   if (!__chked) {\
635:   void *ptr; PetscDLSym(NULL,PETSC_FUNCTION_NAME,&ptr);\
636:   __chked = PETSC_TRUE;\
637:   }} while (0)
638: #else
639: #define PetscRegister__FUNCT__()
640: #endif

642: #if defined(PETSC_USE_DEBUG)
643: PETSC_STATIC_INLINE PetscBool PetscStackActive(void)
644: {
645:   return(petscstack ? PETSC_TRUE : PETSC_FALSE);
646: }

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

653: #define PetscStackPushNoCheck(funct,petsc_routine,hot)                        \
654:   do {                                                                        \
655:     PetscStackSAWsTakeAccess();                                                \
656:     if (petscstack && (petscstack->currentsize < PETSCSTACKSIZE)) {         \
657:       petscstack->function[petscstack->currentsize]  = funct;               \
658:       petscstack->file[petscstack->currentsize]      = __FILE__;            \
659:       petscstack->line[petscstack->currentsize]      = __LINE__;            \
660:       petscstack->petscroutine[petscstack->currentsize] = petsc_routine;    \
661:       petscstack->currentsize++;                                             \
662:     }                                                                         \
663:     if (petscstack) {                                                        \
664:       petscstack->hotdepth += (hot || petscstack->hotdepth);                \
665:     }                                                                         \
666:     PetscStackSAWsGrantAccess();                                               \
667:   } while (0)

669: #define PetscStackPopNoCheck                                            \
670:   do {                                                                  \
671:     PetscStackSAWsTakeAccess();                                          \
672:     if (petscstack && petscstack->currentsize > 0) {                  \
673:       petscstack->currentsize--;                                       \
674:       petscstack->function[petscstack->currentsize]  = 0;             \
675:       petscstack->file[petscstack->currentsize]      = 0;             \
676:       petscstack->line[petscstack->currentsize]      = 0;             \
677:       petscstack->petscroutine[petscstack->currentsize] = PETSC_FALSE;\
678:     }                                                                   \
679:     if (petscstack) {                                                  \
680:       petscstack->hotdepth = PetscMax(petscstack->hotdepth-1,0);      \
681:     }                                                                   \
682:     PetscStackSAWsGrantAccess();                                         \
683:   } while (0)

685: /*MC
687:       line of PETSc functions should be return(0);

689:    Synopsis:
690:    #include <petscsys.h>

693:    Not Collective

695:    Usage:
696: .vb
697:      int something;

700: .ve

702:    Notes:

705:      Not available in Fortran

707:    Level: developer


711: .keywords: traceback, error handling
712: M*/
714:     PetscStackPushNoCheck(PETSC_FUNCTION_NAME,PETSC_TRUE,PETSC_FALSE); \
715:     PetscRegister__FUNCT__();                                          \
716:   } while (0)

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

722:    Synopsis:
723:    #include <petscsys.h>

726:    Not Collective

728:    Usage:
729: .vb
730:      int something;

733: .ve

735:    Notes:
736:      Not available in Fortran

738:    Level: developer


742: .keywords: traceback, error handling
743: M*/
745:     PetscStackPushNoCheck(PETSC_FUNCTION_NAME,PETSC_TRUE,PETSC_TRUE);  \
746:     PetscRegister__FUNCT__();                                          \
747:   } while (0)

749: /*MC

752:    Synopsis:
753:    #include <petscsys.h>

756:    Not Collective

758:    Usage:
759: .vb
760:      int something;

763: .ve

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

768:       Not available in Fortran

771:       routine instead of as a PETSc library routine.

773:    Level: intermediate


777: .keywords: traceback, error handling
778: M*/
780:   do {                                                                  \
781:     PetscStackPushNoCheck(PETSC_FUNCTION_NAME,PETSC_FALSE,PETSC_FALSE); \
782:     PetscRegister__FUNCT__();                                           \
783:   } while (0)


786: #define PetscStackPush(n) \
787:   do {                                                                  \
788:     PetscStackPushNoCheck(n,PETSC_FALSE,PETSC_FALSE);                   \
789:     CHKMEMQ;                                                            \
790:   } while (0)

792: #define PetscStackPop                           \
793:     do {                                        \
794:       CHKMEMQ;                                  \
795:       PetscStackPopNoCheck;                     \
796:     } while (0)

798: /*MC
799:    PetscFunctionReturn - Last executable line of each PETSc function
800:         used for error handling. Replaces return()

802:    Synopsis:
803:    #include <petscsys.h>
804:    void return(0);

806:    Not Collective

808:    Usage:
809: .vb
810:     ....
811:      return(0);
812:    }
813: .ve

815:    Notes:
816:      Not available in Fortran

818:    Level: developer


822: .keywords: traceback, error handling
823: M*/
824: #define PetscFunctionReturn(a) \
825:   do {                                                                \
826:     PetscStackPopNoCheck;                                             \
827:     return(a);} while (0)

829: #define PetscFunctionReturnVoid() \
830:   do {                                                                \
831:     PetscStackPopNoCheck;                                             \
832:     return;} while (0)

834: #else

836: PETSC_STATIC_INLINE PetscBool PetscStackActive(void) {return PETSC_FALSE;}
837: #define PetscStackPushNoCheck(funct,petsc_routine,hot) do {} while (0)
838: #define PetscStackPopNoCheck                           do {} while (0)
842: #define PetscFunctionReturn(a)    return(a)
843: #define PetscFunctionReturnVoid() return
844: #define PetscStackPop             CHKMEMQ
845: #define PetscStackPush(f)         CHKMEMQ

847: #endif

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

852:    Input Parameters:
853: +   name - string that gives the name of the function being called
854: -   routine - actual call to the routine, including and 

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

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



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

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

868:    Input Parameters:
869: +   func-  name of the routine
870: -   args - arguments to the routine surrounded by ()

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

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

876: */
877: #define PetscStackCallStandard(func,args) do {                        \
878:     PetscStackPush(#func);func args;PetscStackPop; if (ierr) SETERRQ2(PETSC_COMM_SELF,PETSC_ERR_LIB,"Error in %s(): error code %d",#func,(int)ierr); \
879:   } while (0)

881: PETSC_EXTERN PetscErrorCode PetscStackCreate(void);
882: PETSC_EXTERN PetscErrorCode PetscStackView(FILE*);
883: PETSC_EXTERN PetscErrorCode PetscStackDestroy(void);

885: #endif