PageRenderTime 25ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 0ms

/include/petscerror.h

https://bitbucket.org/petsc/petsc
C Header | 910 lines | 211 code | 60 blank | 639 comment | 27 complexity | ed7538d315b52b8a5232f25c6424cbfe MD5 | raw file
Possible License(s): BSD-3-Clause, LGPL-2.1
  1. /*
  2. Contains all error handling interfaces for PETSc.
  3. */
  4. #if !defined(PETSCERROR_H)
  5. #define PETSCERROR_H
  6. /*
  7. These are the generic error codes. These error codes are used
  8. many different places in the PETSc source code. The string versions are
  9. at src/sys/error/err.c any changes here must also be made there
  10. These are also define in include/petsc/finclude/petscerror.h any CHANGES here
  11. must be also made there.
  12. */
  13. #define PETSC_ERR_MIN_VALUE 54 /* should always be one less then the smallest value */
  14. #define PETSC_ERR_MEM 55 /* unable to allocate requested memory */
  15. #define PETSC_ERR_SUP 56 /* no support for requested operation */
  16. #define PETSC_ERR_SUP_SYS 57 /* no support for requested operation on this computer system */
  17. #define PETSC_ERR_ORDER 58 /* operation done in wrong order */
  18. #define PETSC_ERR_SIG 59 /* signal received */
  19. #define PETSC_ERR_FP 72 /* floating point exception */
  20. #define PETSC_ERR_COR 74 /* corrupted PETSc object */
  21. #define PETSC_ERR_LIB 76 /* error in library called by PETSc */
  22. #define PETSC_ERR_PLIB 77 /* PETSc library generated inconsistent data */
  23. #define PETSC_ERR_MEMC 78 /* memory corruption */
  24. #define PETSC_ERR_CONV_FAILED 82 /* iterative method (KSP or SNES) failed */
  25. #define PETSC_ERR_USER 83 /* user has not provided needed function */
  26. #define PETSC_ERR_SYS 88 /* error in system call */
  27. #define PETSC_ERR_POINTER 70 /* pointer does not point to valid address */
  28. #define PETSC_ERR_MPI_LIB_INCOMP 87 /* MPI library at runtime is not compatible with MPI user compiled with */
  29. #define PETSC_ERR_ARG_SIZ 60 /* nonconforming object sizes used in operation */
  30. #define PETSC_ERR_ARG_IDN 61 /* two arguments not allowed to be the same */
  31. #define PETSC_ERR_ARG_WRONG 62 /* wrong argument (but object probably ok) */
  32. #define PETSC_ERR_ARG_CORRUPT 64 /* null or corrupted PETSc object as argument */
  33. #define PETSC_ERR_ARG_OUTOFRANGE 63 /* input argument, out of range */
  34. #define PETSC_ERR_ARG_BADPTR 68 /* invalid pointer argument */
  35. #define PETSC_ERR_ARG_NOTSAMETYPE 69 /* two args must be same object type */
  36. #define PETSC_ERR_ARG_NOTSAMECOMM 80 /* two args must be same communicators */
  37. #define PETSC_ERR_ARG_WRONGSTATE 73 /* object in argument is in wrong state, e.g. unassembled mat */
  38. #define PETSC_ERR_ARG_TYPENOTSET 89 /* the type of the object has not yet been set */
  39. #define PETSC_ERR_ARG_INCOMP 75 /* two arguments are incompatible */
  40. #define PETSC_ERR_ARG_NULL 85 /* argument is null that should not be */
  41. #define PETSC_ERR_ARG_UNKNOWN_TYPE 86 /* type name doesn't match any registered type */
  42. #define PETSC_ERR_FILE_OPEN 65 /* unable to open file */
  43. #define PETSC_ERR_FILE_READ 66 /* unable to read from file */
  44. #define PETSC_ERR_FILE_WRITE 67 /* unable to write to file */
  45. #define PETSC_ERR_FILE_UNEXPECTED 79 /* unexpected data in file */
  46. #define PETSC_ERR_MAT_LU_ZRPVT 71 /* detected a zero pivot during LU factorization */
  47. #define PETSC_ERR_MAT_CH_ZRPVT 81 /* detected a zero pivot during Cholesky factorization */
  48. #define PETSC_ERR_INT_OVERFLOW 84
  49. #define PETSC_ERR_FLOP_COUNT 90
  50. #define PETSC_ERR_NOT_CONVERGED 91 /* solver did not converge */
  51. #define PETSC_ERR_MISSING_FACTOR 92 /* MatGetFactor() failed */
  52. #define PETSC_ERR_OPT_OVERWRITE 93 /* attempted to over wrote options which should not be changed */
  53. #define PETSC_ERR_MAX_VALUE 94 /* this is always the one more than the largest error code */
  54. #define PetscStringizeArg(a) #a
  55. #define PetscStringize(a) PetscStringizeArg(a)
  56. /*MC
  57. SETERRQ - Macro to be called when an error has been detected,
  58. Synopsis:
  59. #include <petscsys.h>
  60. PetscErrorCode SETERRQ(MPI_Comm comm,PetscErrorCode ierr,char *message)
  61. Collective
  62. Input Parameters:
  63. + comm - A communicator, use PETSC_COMM_SELF unless you know all ranks of another communicator will detect the error
  64. . ierr - nonzero error code, see the list of standard error codes in include/petscerror.h
  65. - message - error message
  66. Level: beginner
  67. Notes:
  68. Once the error handler is called the calling function is then returned from with the given error code.
  69. See SETERRQ1(), SETERRQ2(), SETERRQ3() for versions that take arguments
  70. Experienced users can set the error handler with PetscPushErrorHandler().
  71. .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), CHKERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2(), SETERRQ3()
  72. M*/
  73. #define SETERRQ(comm,ierr,s) return PetscError(comm,__LINE__,PETSC_FUNCTION_NAME,__FILE__,ierr,PETSC_ERROR_INITIAL,s)
  74. /*MC
  75. SETERRMPI - Macro to be called when an error has been detected within an MPI callback function
  76. Synopsis:
  77. #include <petscsys.h>
  78. PetscErrorCode SETERRMPI(MPI_Comm comm,PetscErrorCode ierr,char *message)
  79. 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
  84. Level: developer
  85. Notes:
  86. 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
  87. which is registered with MPI_Add_error_code() when PETSc is initialized.
  88. .seealso: SETERRQ(), CHKERRQ(), CHKERRMPI(), PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), CHKERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2(), SETERRQ3()
  89. M*/
  90. #define SETERRMPI(comm,ierr,s) return (PetscError(comm,__LINE__,PETSC_FUNCTION_NAME,__FILE__,ierr,PETSC_ERROR_INITIAL,s),PETSC_MPI_ERROR_CODE)
  91. /*MC
  92. SETERRQ1 - Macro that is called when an error has been detected,
  93. Synopsis:
  94. #include <petscsys.h>
  95. PetscErrorCode SETERRQ1(MPI_Comm comm,PetscErrorCode ierr,char *formatmessage,arg)
  96. Collective
  97. Input Parameters:
  98. + comm - A communicator, so that the error can be collective
  99. . ierr - nonzero error code, see the list of standard error codes in include/petscerror.h
  100. . message - error message in the printf format
  101. - arg - argument (for example an integer, string or double)
  102. Level: beginner
  103. Notes:
  104. Once the error handler is called the calling function is then returned from with the given error code.
  105. Experienced users can set the error handler with PetscPushErrorHandler().
  106. .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), CHKERRQ(), CHKMEMQ, SETERRQ(), SETERRQ2(), SETERRQ3()
  107. M*/
  108. #define SETERRQ1(comm,ierr,s,a1) return PetscError(comm,__LINE__,PETSC_FUNCTION_NAME,__FILE__,ierr,PETSC_ERROR_INITIAL,s,a1)
  109. /*MC
  110. SETERRQ2 - Macro that is called when an error has been detected,
  111. Synopsis:
  112. #include <petscsys.h>
  113. PetscErrorCode SETERRQ2(MPI_Comm comm,PetscErrorCode ierr,char *formatmessage,arg1,arg2)
  114. Collective
  115. Input Parameters:
  116. + comm - A communicator, so that the error can be collective
  117. . ierr - nonzero error code, see the list of standard error codes in include/petscerror.h
  118. . message - error message in the printf format
  119. . arg1 - argument (for example an integer, string or double)
  120. - arg2 - argument (for example an integer, string or double)
  121. Level: beginner
  122. Notes:
  123. Once the error handler is called the calling function is then returned from with the given error code.
  124. Experienced users can set the error handler with PetscPushErrorHandler().
  125. .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), CHKERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ3()
  126. M*/
  127. #define SETERRQ2(comm,ierr,s,a1,a2) return PetscError(comm,__LINE__,PETSC_FUNCTION_NAME,__FILE__,ierr,PETSC_ERROR_INITIAL,s,a1,a2)
  128. /*MC
  129. SETERRQ3 - Macro that is called when an error has been detected,
  130. Synopsis:
  131. #include <petscsys.h>
  132. PetscErrorCode SETERRQ3(MPI_Comm comm,PetscErrorCode ierr,char *formatmessage,arg1,arg2,arg3)
  133. Collective
  134. Input Parameters:
  135. + comm - A communicator, so that the error can be collective
  136. . ierr - nonzero error code, see the list of standard error codes in include/petscerror.h
  137. . message - error message in the printf format
  138. . arg1 - argument (for example an integer, string or double)
  139. . arg2 - argument (for example an integer, string or double)
  140. - arg3 - argument (for example an integer, string or double)
  141. Level: beginner
  142. Notes:
  143. Once the error handler is called the calling function is then returned from with the given error code.
  144. There are also versions for 4, 5, 6 and 7 arguments.
  145. Experienced users can set the error handler with PetscPushErrorHandler().
  146. .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), CHKERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2()
  147. M*/
  148. #define SETERRQ3(comm,ierr,s,a1,a2,a3) return PetscError(comm,__LINE__,PETSC_FUNCTION_NAME,__FILE__,ierr,PETSC_ERROR_INITIAL,s,a1,a2,a3)
  149. /*MC
  150. SETERRQ4 - Macro that is called when an error has been detected,
  151. Synopsis:
  152. #include <petscsys.h>
  153. PetscErrorCode SETERRQ4(MPI_Comm comm,PetscErrorCode ierr,char *formatmessage,arg1,arg2,arg3)
  154. Collective
  155. Input Parameters:
  156. + comm - A communicator, so that the error can be collective
  157. . ierr - nonzero error code, see the list of standard error codes in include/petscerror.h
  158. . message - error message in the printf format
  159. . arg1 - argument (for example an integer, string or double)
  160. . arg2 - argument (for example an integer, string or double)
  161. . arg3 - argument (for example an integer, string or double)
  162. - arg4 - argument (for example an integer, string or double)
  163. Level: beginner
  164. Notes:
  165. Once the error handler is called the calling function is then returned from with the given error code.
  166. There are also versions for 4, 5, 6 and 7 arguments.
  167. Experienced users can set the error handler with PetscPushErrorHandler().
  168. .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), CHKERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2()
  169. M*/
  170. #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)
  171. /*MC
  172. SETERRQ5 - Macro that is called when an error has been detected,
  173. Synopsis:
  174. #include <petscsys.h>
  175. PetscErrorCode SETERRQ5(MPI_Comm comm,PetscErrorCode ierr,char *formatmessage,arg1,arg2,arg3)
  176. Collective
  177. Input Parameters:
  178. + comm - A communicator, so that the error can be collective
  179. . ierr - nonzero error code, see the list of standard error codes in include/petscerror.h
  180. . message - error message in the printf format
  181. . arg1 - argument (for example an integer, string or double)
  182. . arg2 - argument (for example an integer, string or double)
  183. . arg3 - argument (for example an integer, string or double)
  184. . arg4 - argument (for example an integer, string or double)
  185. - arg5 - argument (for example an integer, string or double)
  186. Level: beginner
  187. Notes:
  188. Once the error handler is called the calling function is then returned from with the given error code.
  189. There are also versions for 4, 5, 6 and 7 arguments.
  190. Experienced users can set the error handler with PetscPushErrorHandler().
  191. .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), CHKERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2()
  192. M*/
  193. #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)
  194. /*MC
  195. SETERRQ6 - Macro that is called when an error has been detected,
  196. Synopsis:
  197. #include <petscsys.h>
  198. PetscErrorCode SETERRQ6(MPI_Comm comm,PetscErrorCode ierr,char *formatmessage,arg1,arg2,arg3)
  199. Collective
  200. Input Parameters:
  201. + comm - A communicator, so that the error can be collective
  202. . ierr - nonzero error code, see the list of standard error codes in include/petscerror.h
  203. . message - error message in the printf format
  204. . arg1 - argument (for example an integer, string or double)
  205. . arg2 - argument (for example an integer, string or double)
  206. . arg3 - argument (for example an integer, string or double)
  207. . arg4 - argument (for example an integer, string or double)
  208. . arg5 - argument (for example an integer, string or double)
  209. - arg6 - argument (for example an integer, string or double)
  210. Level: beginner
  211. Notes:
  212. 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.
  214. Experienced users can set the error handler with PetscPushErrorHandler().
  215. .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), CHKERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2()
  216. M*/
  217. #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)
  218. /*MC
  219. SETERRQ7 - Macro that is called when an error has been detected,
  220. Synopsis:
  221. #include <petscsys.h>
  222. PetscErrorCode SETERRQ7(MPI_Comm comm,PetscErrorCode ierr,char *formatmessage,arg1,arg2,arg3)
  223. Collective
  224. Input Parameters:
  225. + comm - A communicator, so that the error can be collective
  226. . ierr - nonzero error code, see the list of standard error codes in include/petscerror.h
  227. . message - error message in the printf format
  228. . arg1 - argument (for example an integer, string or double)
  229. . arg2 - argument (for example an integer, string or double)
  230. . arg3 - argument (for example an integer, string or double)
  231. . arg4 - argument (for example an integer, string or double)
  232. . arg5 - argument (for example an integer, string or double)
  233. . arg6 - argument (for example an integer, string or double)
  234. - arg7 - argument (for example an integer, string or double)
  235. Level: beginner
  236. Notes:
  237. Once the error handler is called the calling function is then returned from with the given error code.
  238. There are also versions for 4, 5, 6 and 7 arguments.
  239. Experienced users can set the error handler with PetscPushErrorHandler().
  240. .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), CHKERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2()
  241. M*/
  242. #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)
  243. /*MC
  244. SETERRQ8 - Macro that is called when an error has been detected,
  245. Synopsis:
  246. #include <petscsys.h>
  247. PetscErrorCode SETERRQ8(MPI_Comm comm,PetscErrorCode ierr,char *formatmessage,arg1,arg2,arg3)
  248. 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)
  258. . arg6 - argument (for example an integer, string or double)
  259. . arg7 - argument (for example an integer, string or double)
  260. - arg8 - argument (for example an integer, string or double)
  261. Level: beginner
  262. Notes:
  263. 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.
  265. Experienced users can set the error handler with PetscPushErrorHandler().
  266. .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), CHKERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2()
  267. M*/
  268. #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)
  269. /*MC
  270. SETERRQ9 - Macro that is called when an error has been detected,
  271. Synopsis:
  272. #include <petscsys.h>
  273. PetscErrorCode SETERRQ9(MPI_Comm comm,PetscErrorCode ierr,char *formatmessage,arg1,arg2,arg3)
  274. Collective
  275. Input Parameters:
  276. + comm - A communicator, so that the error can be collective
  277. . ierr - nonzero error code, see the list of standard error codes in include/petscerror.h
  278. . message - error message in the printf format
  279. . arg1 - argument (for example an integer, string or double)
  280. . arg2 - argument (for example an integer, string or double)
  281. . arg3 - argument (for example an integer, string or double)
  282. . arg4 - argument (for example an integer, string or double)
  283. . arg5 - argument (for example an integer, string or double)
  284. . arg6 - argument (for example an integer, string or double)
  285. . arg7 - argument (for example an integer, string or double)
  286. . arg8 - argument (for example an integer, string or double)
  287. - arg9 - argument (for example an integer, string or double)
  288. Level: beginner
  289. Notes:
  290. Once the error handler is called the calling function is then returned from with the given error code.
  291. There are also versions for 0 to 9 arguments.
  292. Experienced users can set the error handler with PetscPushErrorHandler().
  293. .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), CHKERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2()
  294. M*/
  295. #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)
  296. /*MC
  297. SETERRABORT - Macro that can be called when an error has been detected,
  298. Synopsis:
  299. #include <petscsys.h>
  300. PetscErrorCode SETERRABORT(MPI_Comm comm,PetscErrorCode ierr,char *message)
  301. Collective
  302. Input Parameters:
  303. + comm - A communicator, so that the error can be collective
  304. . ierr - nonzero error code, see the list of standard error codes in include/petscerror.h
  305. - message - error message in the printf format
  306. Level: beginner
  307. Notes:
  308. This function just calls MPI_Abort().
  309. .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), CHKERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2()
  310. M*/
  311. #define SETERRABORT(comm,ierr,s) do {PetscError(comm,__LINE__,PETSC_FUNCTION_NAME,__FILE__,ierr,PETSC_ERROR_INITIAL,s);MPI_Abort(comm,ierr);} while (0)
  312. /*MC
  313. CHKERRQ - Checks error code, if non-zero it calls the error handler and then returns
  314. Synopsis:
  315. #include <petscsys.h>
  316. PetscErrorCode CHKERRQ(PetscErrorCode ierr)
  317. Not Collective
  318. Input Parameters:
  319. . ierr - nonzero error code, see the list of standard error codes in include/petscerror.h
  320. Level: beginner
  321. Notes:
  322. Once the error handler is called the calling function is then returned from with the given error code.
  323. Experienced users can set the error handler with PetscPushErrorHandler().
  324. CHKERRQ(ierr) is fundamentally a macro replacement for
  325. if (ierr) return(PetscError(...,ierr,...));
  326. Although typical usage resembles "void CHKERRQ(PetscErrorCode)" as described above, for certain uses it is
  327. highly inappropriate to use it in this manner as it invokes return(PetscErrorCode). In particular,
  328. it cannot be used in functions which return(void) or any other datatype. In these types of functions,
  329. you can use CHKERRV() which returns without an error code (bad idea since the error is ignored or
  330. if (ierr) {PetscError(....); return(YourReturnType);}
  331. where you may pass back a NULL to indicate an error. You can also call CHKERRABORT(comm,n) to have
  332. MPI_Abort() returned immediately.
  333. .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), SETERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2(), SETERRQ2()
  334. M*/
  335. #define CHKERRQ(ierr) do {if (PetscUnlikely(ierr)) return PetscError(PETSC_COMM_SELF,__LINE__,PETSC_FUNCTION_NAME,__FILE__,ierr,PETSC_ERROR_REPEAT," ");} while (0)
  336. #define CHKERRV(ierr) do {if (PetscUnlikely(ierr)) {ierr = PetscError(PETSC_COMM_SELF,__LINE__,PETSC_FUNCTION_NAME,__FILE__,ierr,PETSC_ERROR_REPEAT," ");return;}} while(0)
  337. #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)
  338. #define CHKERRCONTINUE(ierr) do {if (PetscUnlikely(ierr)) {PetscError(PETSC_COMM_SELF,__LINE__,PETSC_FUNCTION_NAME,__FILE__,ierr,PETSC_ERROR_REPEAT," ");}} while (0)
  339. /*MC
  340. CHKERRMPI - Checks error code, if non-zero it calls the error handler and then returns
  341. Synopsis:
  342. #include <petscsys.h>
  343. PetscErrorCode CHKERRMPI(PetscErrorCode ierr)
  344. Not Collective
  345. Input Parameters:
  346. . ierr - nonzero error code, see the list of standard error codes in include/petscerror.h
  347. Level: developer
  348. Notes:
  349. 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
  350. which is registered with MPI_Add_error_code() when PETSc is initialized.
  351. .seealso: CHKERRQ(), PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), SETERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2(), SETERRQ2()
  352. M*/
  353. #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)
  354. #ifdef PETSC_CLANGUAGE_CXX
  355. /*MC
  356. CHKERRXX - Checks error code, if non-zero it calls the C++ error handler which throws an exception
  357. Synopsis:
  358. #include <petscsys.h>
  359. void CHKERRXX(PetscErrorCode ierr)
  360. Not Collective
  361. Input Parameters:
  362. . ierr - nonzero error code, see the list of standard error codes in include/petscerror.h
  363. Level: beginner
  364. Notes:
  365. Once the error handler throws a ??? exception.
  366. You can use CHKERRV() which returns without an error code (bad idea since the error is ignored)
  367. or CHKERRABORT(comm,n) to have MPI_Abort() returned immediately.
  368. .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), SETERRQ(), CHKERRQ(), CHKMEMQ
  369. M*/
  370. #define CHKERRXX(ierr) do {if (PetscUnlikely(ierr)) {PetscError(PETSC_COMM_SELF,__LINE__,PETSC_FUNCTION_NAME,__FILE__,ierr,PETSC_ERROR_IN_CXX,0);}} while(0)
  371. #endif
  372. #if defined(PETSC_HAVE_CUDA)
  373. #define CHKERRCUDA(err) do {if (PetscUnlikely(err)) SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_LIB,"CUDA error %d",err);} while(0)
  374. #define CHKERRCUBLAS(err) do {if (PetscUnlikely(err)) SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_LIB,"CUBLAS error %d",err);} while(0)
  375. #define CHKERRCUSOLVER(err) do {if (PetscUnlikely(err)) SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_LIB,"CUSOLVER error %d",err);} while(0)
  376. #endif
  377. /*MC
  378. CHKMEMQ - Checks the memory for corruption, calls error handler if any is detected
  379. Synopsis:
  380. #include <petscsys.h>
  381. CHKMEMQ;
  382. Not Collective
  383. Level: beginner
  384. Notes:
  385. We highly recommend using valgrind https://www.mcs.anl.gov/petsc/documentation/faq.html#valgrind for finding memory problems. This is useful
  386. on systems that do not have valgrind, but much much less useful.
  387. Must run with the option -malloc_debug (-malloc_test in debug mode; or if PetscMallocSetDebug() called) to enable this option
  388. Once the error handler is called the calling function is then returned from with the given error code.
  389. By defaults prints location where memory that is corrupted was allocated.
  390. Use CHKMEMA for functions that return void
  391. .seealso: PetscTraceBackErrorHandler(), PetscPushErrorHandler(), PetscError(), SETERRQ(), CHKMEMQ, SETERRQ1(), SETERRQ2(), SETERRQ3(),
  392. PetscMallocValidate()
  393. M*/
  394. #define CHKMEMQ do {PetscErrorCode _7_ierr = PetscMallocValidate(__LINE__,PETSC_FUNCTION_NAME,__FILE__);CHKERRQ(_7_ierr);} while(0)
  395. #define CHKMEMA PetscMallocValidate(__LINE__,PETSC_FUNCTION_NAME,__FILE__)
  396. /*E
  397. PetscErrorType - passed to the PETSc error handling routines indicating if this is the first or a later call to the error handlers
  398. Level: advanced
  399. PETSC_ERROR_IN_CXX indicates the error was detected in C++ and an exception should be generated
  400. Developer Notes:
  401. This is currently used to decide when to print the detailed information about the run in PetscTraceBackErrorHandler()
  402. .seealso: PetscError(), SETERRXX()
  403. E*/
  404. typedef enum {PETSC_ERROR_INITIAL=0,PETSC_ERROR_REPEAT=1,PETSC_ERROR_IN_CXX = 2} PetscErrorType;
  405. #if defined(__clang_analyzer__)
  406. __attribute__((analyzer_noreturn))
  407. #endif
  408. PETSC_EXTERN PetscErrorCode PetscError(MPI_Comm,int,const char*,const char*,PetscErrorCode,PetscErrorType,const char*,...);
  409. PETSC_EXTERN PetscErrorCode PetscErrorPrintfInitialize(void);
  410. PETSC_EXTERN PetscErrorCode PetscErrorMessage(int,const char*[],char **);
  411. PETSC_EXTERN PetscErrorCode PetscTraceBackErrorHandler(MPI_Comm,int,const char*,const char*,PetscErrorCode,PetscErrorType,const char*,void*);
  412. PETSC_EXTERN PetscErrorCode PetscIgnoreErrorHandler(MPI_Comm,int,const char*,const char*,PetscErrorCode,PetscErrorType,const char*,void*);
  413. PETSC_EXTERN PetscErrorCode PetscEmacsClientErrorHandler(MPI_Comm,int,const char*,const char*,PetscErrorCode,PetscErrorType,const char*,void*);
  414. PETSC_EXTERN PetscErrorCode PetscMPIAbortErrorHandler(MPI_Comm,int,const char*,const char*,PetscErrorCode,PetscErrorType,const char*,void*);
  415. PETSC_EXTERN PetscErrorCode PetscAbortErrorHandler(MPI_Comm,int,const char*,const char*,PetscErrorCode,PetscErrorType,const char*,void*);
  416. PETSC_EXTERN PetscErrorCode PetscAttachDebuggerErrorHandler(MPI_Comm,int,const char*,const char*,PetscErrorCode,PetscErrorType,const char*,void*);
  417. PETSC_EXTERN PetscErrorCode PetscReturnErrorHandler(MPI_Comm,int,const char*,const char*,PetscErrorCode,PetscErrorType,const char*,void*);
  418. PETSC_EXTERN PetscErrorCode PetscPushErrorHandler(PetscErrorCode (*handler)(MPI_Comm,int,const char*,const char*,PetscErrorCode,PetscErrorType,const char*,void*),void*);
  419. PETSC_EXTERN PetscErrorCode PetscPopErrorHandler(void);
  420. PETSC_EXTERN PetscErrorCode PetscSignalHandlerDefault(int,void*);
  421. PETSC_EXTERN PetscErrorCode PetscPushSignalHandler(PetscErrorCode (*)(int,void *),void*);
  422. PETSC_EXTERN PetscErrorCode PetscPopSignalHandler(void);
  423. PETSC_EXTERN PetscErrorCode PetscCheckPointerSetIntensity(PetscInt);
  424. PETSC_EXTERN void PetscSignalSegvCheckPointer(void);
  425. /*MC
  426. PetscErrorPrintf - Prints error messages.
  427. Synopsis:
  428. #include <petscsys.h>
  429. PetscErrorCode (*PetscErrorPrintf)(const char format[],...);
  430. Not Collective
  431. Input Parameters:
  432. . format - the usual printf() format string
  433. Options Database Keys:
  434. + -error_output_stdout - cause error messages to be printed to stdout instead of the (default) stderr
  435. - -error_output_none - to turn off all printing of error messages (does not change the way the error is handled.)
  436. Notes:
  437. Use
  438. $ PetscErrorPrintf = PetscErrorPrintfNone; to turn off all printing of error messages (does not change the way the
  439. $ error is handled.) and
  440. $ PetscErrorPrintf = PetscErrorPrintfDefault; to turn it back on or you can use your own function
  441. Use
  442. PETSC_STDERR = FILE* obtained from a file open etc. to have stderr printed to the file.
  443. PETSC_STDOUT = FILE* obtained from a file open etc. to have stdout printed to the file.
  444. Use
  445. PetscPushErrorHandler() to provide your own error handler that determines what kind of messages to print
  446. Level: developer
  447. Fortran Note:
  448. This routine is not supported in Fortran.
  449. .seealso: PetscFPrintf(), PetscSynchronizedPrintf(), PetscHelpPrintf(), PetscPrintf(), PetscPushErrorHandler(), PetscVFPrintf(), PetscHelpPrintf()
  450. M*/
  451. PETSC_EXTERN PetscErrorCode (*PetscErrorPrintf)(const char[],...);
  452. typedef enum {PETSC_FP_TRAP_OFF=0,PETSC_FP_TRAP_ON=1} PetscFPTrap;
  453. PETSC_EXTERN PetscErrorCode PetscSetFPTrap(PetscFPTrap);
  454. PETSC_EXTERN PetscErrorCode PetscFPTrapPush(PetscFPTrap);
  455. PETSC_EXTERN PetscErrorCode PetscFPTrapPop(void);
  456. /*
  457. Allows the code to build a stack frame as it runs
  458. */
  459. #define PETSCSTACKSIZE 64
  460. typedef struct {
  461. const char *function[PETSCSTACKSIZE];
  462. const char *file[PETSCSTACKSIZE];
  463. int line[PETSCSTACKSIZE];
  464. PetscBool petscroutine[PETSCSTACKSIZE];
  465. int currentsize;
  466. int hotdepth;
  467. } PetscStack;
  468. PETSC_EXTERN PetscStack *petscstack;
  469. PetscErrorCode PetscStackCopy(PetscStack*,PetscStack*);
  470. PetscErrorCode PetscStackPrint(PetscStack *,FILE*);
  471. #if defined(PETSC_SERIALIZE_FUNCTIONS)
  472. #include <petsc/private/petscfptimpl.h>
  473. /*
  474. Registers the current function into the global function pointer to function name table
  475. Have to fix this to handle errors but cannot return error since used in PETSC_VIEWER_DRAW_() etc
  476. */
  477. #define PetscRegister__FUNCT__() do { \
  478. static PetscBool __chked = PETSC_FALSE; \
  479. if (!__chked) {\
  480. void *ptr; PetscDLSym(NULL,PETSC_FUNCTION_NAME,&ptr);\
  481. __chked = PETSC_TRUE;\
  482. }} while (0)
  483. #else
  484. #define PetscRegister__FUNCT__()
  485. #endif
  486. #if defined(PETSC_USE_DEBUG)
  487. PETSC_STATIC_INLINE PetscBool PetscStackActive(void)
  488. {
  489. return(petscstack ? PETSC_TRUE : PETSC_FALSE);
  490. }
  491. /* Stack handling is based on the following two "NoCheck" macros. These should only be called directly by other error
  492. * handling macros. We record the line of the call, which may or may not be the location of the definition. But is at
  493. * least more useful than "unknown" because it can distinguish multiple calls from the same function.
  494. */
  495. #define PetscStackPushNoCheck(funct,petsc_routine,hot) \
  496. do { \
  497. PetscStackSAWsTakeAccess(); \
  498. if (petscstack && (petscstack->currentsize < PETSCSTACKSIZE)) { \
  499. petscstack->function[petscstack->currentsize] = funct; \
  500. petscstack->file[petscstack->currentsize] = __FILE__; \
  501. petscstack->line[petscstack->currentsize] = __LINE__; \
  502. petscstack->petscroutine[petscstack->currentsize] = petsc_routine; \
  503. petscstack->currentsize++; \
  504. } \
  505. if (petscstack) { \
  506. petscstack->hotdepth += (hot || petscstack->hotdepth); \
  507. } \
  508. PetscStackSAWsGrantAccess(); \
  509. } while (0)
  510. #define PetscStackPopNoCheck \
  511. do { \
  512. PetscStackSAWsTakeAccess(); \
  513. if (petscstack && petscstack->currentsize > 0) { \
  514. petscstack->currentsize--; \
  515. petscstack->function[petscstack->currentsize] = 0; \
  516. petscstack->file[petscstack->currentsize] = 0; \
  517. petscstack->line[petscstack->currentsize] = 0; \
  518. petscstack->petscroutine[petscstack->currentsize] = PETSC_FALSE;\
  519. } \
  520. if (petscstack) { \
  521. petscstack->hotdepth = PetscMax(petscstack->hotdepth-1,0); \
  522. } \
  523. PetscStackSAWsGrantAccess(); \
  524. } while (0)
  525. /*MC
  526. PetscFunctionBegin - First executable line of each PETSc function, used for error handling. Final
  527. line of PETSc functions should be PetscFunctionReturn(0);
  528. Synopsis:
  529. #include <petscsys.h>
  530. void PetscFunctionBegin;
  531. Not Collective
  532. Usage:
  533. .vb
  534. int something;
  535. PetscFunctionBegin;
  536. .ve
  537. Notes:
  538. Use PetscFunctionBeginUser for application codes.
  539. Not available in Fortran
  540. Level: developer
  541. .seealso: PetscFunctionReturn(), PetscFunctionBeginHot(), PetscFunctionBeginUser()
  542. M*/
  543. #define PetscFunctionBegin do { \
  544. PetscStackPushNoCheck(PETSC_FUNCTION_NAME,PETSC_TRUE,PETSC_FALSE); \
  545. PetscRegister__FUNCT__(); \
  546. } while (0)
  547. /*MC
  548. PetscFunctionBeginHot - Substitute for PetscFunctionBegin to be used in functions that are called in
  549. performance-critical circumstances. Use of this function allows for lighter profiling by default.
  550. Synopsis:
  551. #include <petscsys.h>
  552. void PetscFunctionBeginHot;
  553. Not Collective
  554. Usage:
  555. .vb
  556. int something;
  557. PetscFunctionBeginHot;
  558. .ve
  559. Notes:
  560. Not available in Fortran
  561. Level: developer
  562. .seealso: PetscFunctionBegin, PetscFunctionReturn()
  563. M*/
  564. #define PetscFunctionBeginHot do { \
  565. PetscStackPushNoCheck(PETSC_FUNCTION_NAME,PETSC_TRUE,PETSC_TRUE); \
  566. PetscRegister__FUNCT__(); \
  567. } while (0)
  568. /*MC
  569. PetscFunctionBeginUser - First executable line of user provided PETSc routine
  570. Synopsis:
  571. #include <petscsys.h>
  572. void PetscFunctionBeginUser;
  573. Not Collective
  574. Usage:
  575. .vb
  576. int something;
  577. PetscFunctionBeginUser;
  578. .ve
  579. Notes:
  580. Final line of PETSc functions should be PetscFunctionReturn(0) except for main().
  581. Not available in Fortran
  582. This is identical to PetscFunctionBegin except it labels the routine as a user
  583. routine instead of as a PETSc library routine.
  584. Level: intermediate
  585. .seealso: PetscFunctionReturn(), PetscFunctionBegin, PetscFunctionBeginHot
  586. M*/
  587. #define PetscFunctionBeginUser \
  588. do { \
  589. PetscStackPushNoCheck(PETSC_FUNCTION_NAME,PETSC_FALSE,PETSC_FALSE); \
  590. PetscRegister__FUNCT__(); \
  591. } while (0)
  592. #define PetscStackPush(n) \
  593. do { \
  594. PetscStackPushNoCheck(n,PETSC_FALSE,PETSC_FALSE); \
  595. CHKMEMQ; \
  596. } while (0)
  597. #define PetscStackPop \
  598. do { \
  599. CHKMEMQ; \
  600. PetscStackPopNoCheck; \
  601. } while (0)
  602. /*MC
  603. PetscFunctionReturn - Last executable line of each PETSc function
  604. used for error handling. Replaces return()
  605. Synopsis:
  606. #include <petscsys.h>
  607. void PetscFunctionReturn(0);
  608. Not Collective
  609. Usage:
  610. .vb
  611. ....
  612. PetscFunctionReturn(0);
  613. }
  614. .ve
  615. Notes:
  616. Not available in Fortran
  617. Level: developer
  618. .seealso: PetscFunctionBegin()
  619. M*/
  620. #define PetscFunctionReturn(a) \
  621. do { \
  622. PetscStackPopNoCheck; \
  623. return(a);} while (0)
  624. #define PetscFunctionReturnVoid() \
  625. do { \
  626. PetscStackPopNoCheck; \
  627. return;} while (0)
  628. #else
  629. PETSC_STATIC_INLINE PetscBool PetscStackActive(void) {return PETSC_FALSE;}
  630. #define PetscStackPushNoCheck(funct,petsc_routine,hot) do {} while (0)
  631. #define PetscStackPopNoCheck do {} while (0)
  632. #define PetscFunctionBegin
  633. #define PetscFunctionBeginUser
  634. #define PetscFunctionBeginHot
  635. #define PetscFunctionReturn(a) return(a)
  636. #define PetscFunctionReturnVoid() return
  637. #define PetscStackPop CHKMEMQ
  638. #define PetscStackPush(f) CHKMEMQ
  639. #endif
  640. /*
  641. PetscStackCall - Calls an external library routine or user function after pushing the name of the routine on the stack.
  642. Input Parameters:
  643. + name - string that gives the name of the function being called
  644. - routine - actual call to the routine, including ierr = and CHKERRQ(ierr);
  645. Note: Often one should use PetscStackCallStandard() instead. This routine is intended for external library routines that DO NOT return error codes
  646. 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.
  647. */
  648. #define PetscStackCall(name,routine) do { PetscStackPush(name);routine;PetscStackPop; } while(0)
  649. /*
  650. PetscStackCallStandard - Calls an external library routine after pushing the name of the routine on the stack.
  651. Input Parameters:
  652. + func- name of the routine
  653. - args - arguments to the routine surrounded by ()
  654. Notes:
  655. This is intended for external package routines that return error codes. Use PetscStackCall() for those that do not.
  656. Developer Note: this is so that when an external packge routine results in a crash or corrupts memory, they get blamed instead of PETSc.
  657. */
  658. #define PetscStackCallStandard(func,args) do { \
  659. PetscErrorCode __ierr; \
  660. PetscStackPush(#func); \
  661. __ierr = func args; \
  662. PetscStackPop; \
  663. if (__ierr) SETERRQ2(PETSC_COMM_SELF,PETSC_ERR_LIB,"Error in %s(): error code %d",#func,(int)__ierr); \
  664. } while (0)
  665. PETSC_EXTERN PetscErrorCode PetscStackCreate(void);
  666. PETSC_EXTERN PetscErrorCode PetscStackView(FILE*);
  667. PETSC_EXTERN PetscErrorCode PetscStackDestroy(void);
  668. #endif