Actual source code: petscerror.h

petsc-3.9.4 2018-09-11
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)
 99: #define SETERRMPI(comm,ierr,s) return (PetscError(comm,__LINE__,PETSC_FUNCTION_NAME,__FILE__,ierr,PETSC_ERROR_INITIAL,s),PETSC_MPI_ERROR_CODE)

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

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

108:    Collective on MPI_Comm

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

116:   Level: beginner

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

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

123:    Concepts: error^setting condition

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

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

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

136:    Collective on MPI_Comm

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

145:   Level: beginner

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

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

152:    Concepts: error^setting condition

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

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

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

165:    Collective on MPI_Comm

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

175:   Level: beginner

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

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

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

184:    Concepts: error^setting condition

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

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

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

197:    Collective on MPI_Comm

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

208:   Level: beginner

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

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

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

217:    Concepts: error^setting condition

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

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

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

230:    Collective on MPI_COmm

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

242:   Level: beginner

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

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

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

251:    Concepts: error^setting condition

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

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

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

264:    Collective on MPI_Comm

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

277:   Level: beginner

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

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

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

286:    Concepts: error^setting condition

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

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

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

299:    Collective on MPI_Comm

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

313:   Level: beginner

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

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

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

322:    Concepts: error^setting condition

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

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

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

335:    Collective on MPI_Comm

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

350:   Level: beginner

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

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

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

359:    Concepts: error^setting condition

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

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

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

372:    Collective on MPI_Comm

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

379:   Level: beginner

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

384:    Concepts: error^setting condition

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

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

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

397:    Not Collective

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

402:   Level: beginner

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

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

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

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

420:     In Fortran MPI_Abort() is always called

422:    Concepts: error^setting condition

424: .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), SETERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2(), SETERRQ2()
425: M*/
426: #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)
430: #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)

432: #ifdef PETSC_CLANGUAGE_CXX

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

437:    Synopsis:
438:    #include <petscsys.h>
439:    void CHKERRXX(PetscErrorCode ierr)

441:    Not Collective

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

446:   Level: beginner

448:    Notes:
449:     Once the error handler throws a ??? exception.

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

454:    Concepts: error^setting condition

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

460: #endif

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

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

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

472:    Not Collective

474:   Level: beginner

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

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

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

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

486:     Use CHKMEMA for functions that return void

488:    Concepts: memory corruption

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

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

497: #else /* PETSC_USE_ERRORCHECKING */

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

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

515: #define CHKERRQ(ierr)     ;
516: #define CHKERRV(ierr)     ;
517: #define CHKERRABORT(comm,n) ;
518: #define CHKERRCONTINUE(ierr) ;
519: #define CHKERRMPI(ierr) ;
520: #define CHKMEMQ        ;
521: #define CHKERRCUDA(err) ;
522: #define CHKERRCUBLAS(err) ;

524: #ifdef PETSC_CLANGUAGE_CXX
525: #define CHKERRXX(ierr) ;
526: #endif

528: #endif /* PETSC_USE_ERRORCHECKING */

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

533:   Level: advanced

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

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

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

543: #if defined(__clang_analyzer__)
544: __attribute__((analyzer_noreturn))
545: #endif
546: PETSC_EXTERN PetscErrorCode PetscError(MPI_Comm,int,const char*,const char*,PetscErrorCode,PetscErrorType,const char*,...);

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

564: /*MC
565:     PetscErrorPrintf - Prints error messages.

567:    Synopsis:
568:     #include <petscsys.h>
569:      PetscErrorCode (*PetscErrorPrintf)(const char format[],...);

571:     Not Collective

573:     Input Parameters:
574: .   format - the usual printf() format string

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

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

585:           Use
586:      PETSC_STDERR = FILE* obtained from a file open etc. to have stderr printed to the file.
587:      PETSC_STDOUT = FILE* obtained from a file open etc. to have stdout printed to the file.

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

592:    Level: developer

594:     Fortran Note:
595:     This routine is not supported in Fortran.

597:     Concepts: error messages^printing
598:     Concepts: printing^error messages

600: .seealso: PetscFPrintf(), PetscSynchronizedPrintf(), PetscHelpPrintf(), PetscPrintf(), PetscErrorHandlerPush(), PetscVFPrintf(), PetscHelpPrintf()
601: M*/
602: PETSC_EXTERN PetscErrorCode (*PetscErrorPrintf)(const char[],...);

604: typedef enum {PETSC_FP_TRAP_OFF=0,PETSC_FP_TRAP_ON=1} PetscFPTrap;
605: PETSC_EXTERN PetscErrorCode PetscSetFPTrap(PetscFPTrap);
606: PETSC_EXTERN PetscErrorCode PetscFPTrapPush(PetscFPTrap);
607: PETSC_EXTERN PetscErrorCode PetscFPTrapPop(void);

609: /*
610:       Allows the code to build a stack frame as it runs
611: */

613: #define PETSCSTACKSIZE 64

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

624: PETSC_EXTERN PetscStack *petscstack;

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

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

645: #if defined(PETSC_USE_DEBUG)
646: PETSC_STATIC_INLINE PetscBool PetscStackActive(void)
647: {
648:   return(petscstack ? PETSC_TRUE : PETSC_FALSE);
649: }

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

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

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

688: /*MC
690:       line of PETSc functions should be return(0);

692:    Synopsis:
693:    #include <petscsys.h>

696:    Not Collective

698:    Usage:
699: .vb
700:      int something;

703: .ve

705:    Notes:

708:      Not available in Fortran

710:    Level: developer


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

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

725:    Synopsis:
726:    #include <petscsys.h>

729:    Not Collective

731:    Usage:
732: .vb
733:      int something;

736: .ve

738:    Notes:
739:      Not available in Fortran

741:    Level: developer


745: .keywords: traceback, error handling
746: M*/
748:     PetscStackPushNoCheck(PETSC_FUNCTION_NAME,PETSC_TRUE,PETSC_TRUE);  \
749:     PetscRegister__FUNCT__();                                          \
750:   } while (0)

752: /*MC

755:    Synopsis:
756:    #include <petscsys.h>

759:    Not Collective

761:    Usage:
762: .vb
763:      int something;

766: .ve

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

771:       Not available in Fortran

774:       routine instead of as a PETSc library routine.

776:    Level: intermediate


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


789: #define PetscStackPush(n) \
790:   do {                                                                  \
791:     PetscStackPushNoCheck(n,PETSC_FALSE,PETSC_FALSE);                   \
792:     CHKMEMQ;                                                            \
793:   } while (0)

795: #define PetscStackPop                           \
796:     do {                                        \
797:       CHKMEMQ;                                  \
798:       PetscStackPopNoCheck;                     \
799:     } while (0)

801: /*MC
802:    PetscFunctionReturn - Last executable line of each PETSc function
803:         used for error handling. Replaces return()

805:    Synopsis:
806:    #include <petscsys.h>
807:    void return(0);

809:    Not Collective

811:    Usage:
812: .vb
813:     ....
814:      return(0);
815:    }
816: .ve

818:    Notes:
819:      Not available in Fortran

821:    Level: developer


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

832: #define PetscFunctionReturnVoid() \
833:   do {                                                                \
834:     PetscStackPopNoCheck;                                             \
835:     return;} while (0)

837: #else

839: PETSC_STATIC_INLINE PetscBool PetscStackActive(void) {return PETSC_FALSE;}
840: #define PetscStackPushNoCheck(funct,petsc_routine,hot) do {} while (0)
841: #define PetscStackPopNoCheck                           do {} while (0)
845: #define PetscFunctionReturn(a)    return(a)
846: #define PetscFunctionReturnVoid() return
847: #define PetscStackPop             CHKMEMQ
848: #define PetscStackPush(f)         CHKMEMQ

850: #endif

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

855:    Input Parameters:
856: +   name - string that gives the name of the function being called
857: -   routine - actual call to the routine, including and 

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

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



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

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

871:    Input Parameters:
872: +   func-  name of the routine
873: -   args - arguments to the routine surrounded by ()

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

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

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

884: PETSC_EXTERN PetscErrorCode PetscStackCreate(void);
885: PETSC_EXTERN PetscErrorCode PetscStackView(FILE*);
886: PETSC_EXTERN PetscErrorCode PetscStackDestroy(void);

888: #endif