v0.9.0
Functions
ErrorHandler.cpp File Reference

Go to the source code of this file.

Functions

static PetscErrorCode mofem_error_printf (const char format[],...)
 
static void error_printf_highlight (void)
 
static void error_printf_normal (void)
 
static PetscErrorCode mofem_error_handler (MPI_Comm comm, int line, const char *fun, const char *file, PetscErrorCode n, PetscErrorType p, const char *mess, void *ctx)
 

Function Documentation

◆ error_printf_highlight()

static void error_printf_highlight ( void  )
static

Definition at line 60 of file ErrorHandler.cpp.

60  {
61 #if defined(PETSC_HAVE_UNISTD_H) && defined(PETSC_USE_ISATTY)
62  if (isatty(fileno(PETSC_STDERR)))
63  fprintf(PETSC_STDERR, "\033[1;32m");
64 #endif
65 }

◆ error_printf_normal()

static void error_printf_normal ( void  )
static

Definition at line 67 of file ErrorHandler.cpp.

67  {
68 #if defined(PETSC_HAVE_UNISTD_H) && defined(PETSC_USE_ISATTY)
69  if (isatty(fileno(PETSC_STDERR)))
70  fprintf(PETSC_STDERR, "\033[0;39m\033[0;49m");
71 #endif
72 }

◆ mofem_error_handler()

static PetscErrorCode mofem_error_handler ( MPI_Comm  comm,
int  line,
const char *  fun,
const char *  file,
PetscErrorCode  n,
PetscErrorType  p,
const char *  mess,
void *  ctx 
)
static

Definition at line 74 of file ErrorHandler.cpp.

77  {
78 
79  static int cnt = 1;
81 
82  int rank = 0;
83  if (comm != PETSC_COMM_SELF)
84  MPI_Comm_rank(comm, &rank);
85 
86  if (!rank) {
87 
88 
89  if (p == PETSC_ERROR_INITIAL) {
90 
91  char petsc_version[255];
92  PetscGetVersion(petsc_version, 255);
93 
95  mofem_error_printf("--------------------- MoFEM Error Message ---------------------------------------------------\n");
96  mofem_error_printf("MoFEM version %d.%d.%d (%s %s)\n",
97  MoFEM_VERSION_MAJOR, MoFEM_VERSION_MINOR,
98  MoFEM_VERSION_BUILD, MOAB_VERSION_STRING, petsc_version);
99  mofem_error_printf("MoFEM git commit id %s\n", GIT_SHA1_NAME);
100  mofem_error_printf("See "
101  "http://mofem.eng.gla.ac.uk/mofem/html/"
102  "guidelines_bug_reporting.html for bug reporting.\n");
104  "Write to https://groups.google.com/forum/#!forum/mofem-group to "
105  "seek help.\n");
107  }
108 
109  if (n >= MOFEM_DATA_INCONSISTENCY) {
110  if (p == PETSC_ERROR_INITIAL) {
111  if (mess)
112  mofem_error_printf("%s\n", mess);
113  }
114  mofem_error_printf("#%d %s() line %d in %s\n", cnt++, fun, line, file);
115  } else {
116  PetscTraceBackErrorHandler(PETSC_COMM_SELF, line, fun, file, n, p, mess,
117  ctx);
118  }
119 
120  PetscBool ismain, isunknown;
121  PetscStrncmp(fun, "main", 4, &ismain);
122  PetscStrncmp(fun, "unknown", 7, &isunknown);
123  if (ismain || isunknown) {
124 
125  if (n >= MOFEM_DATA_INCONSISTENCY) {
126 #if PETSC_VERSION_GE(3, 7, 0)
127  PetscOptionsView(NULL, PETSC_VIEWER_STDERR_SELF);
128 #else
129  PetscOptionsView(PETSC_VIEWER_STDERR_SELF);
130 #endif
131  }
132 
134  mofem_error_printf("-- MoFEM End of Error Message -- send entire error "
135  "message to mofem-group@googlegroups.com --\n");
137  }
138 
139  } else {
140 
141  /* do not print error messages since process 0 will print them, sleep before
142  * aborting so will not accidentally kill process 0*/
143  PetscSleep(10.0);
144  abort();
145  }
146 
147 
149 }
static void error_printf_highlight(void)
#define MoFEMFunctionBeginHot
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
Definition: definitions.h:501
static void error_printf_normal(void)
#define MoFEMFunctionReturnHot(a)
Last executable line of each PETSc function used for error handling. Replaces return()
Definition: definitions.h:508
static PetscErrorCode mofem_error_printf(const char format[],...)

◆ mofem_error_printf()

static PetscErrorCode mofem_error_printf ( const char  format[],
  ... 
)
static

Definition at line 19 of file ErrorHandler.cpp.

19  {
20  va_list Argp;
21  static PetscBool PetscErrorPrintfCalled = PETSC_FALSE;
22 
23  /*
24  This function does not call PetscFunctionBegin and PetscFunctionReturn()
25  because it may be called by PetscStackView().
26 
27  This function does not do error checking because it is called by the error
28  handlers.
29  */
30 
31  if (!PetscErrorPrintfCalled) {
32  PetscErrorPrintfCalled = PETSC_TRUE;
33 
34  /*
35  On the SGI machines and Cray T3E, if errors are generated
36  "simultaneously" by different processors, the messages are printed all
37  jumbled up; to try to prevent this we have each processor wait based on
38  their rank
39  */
40 #if defined(PETSC_CAN_SLEEP_AFTER_ERROR)
41  {
42  PetscMPIInt rank;
43  if (PetscGlobalRank > 8)
44  rank = 8;
45  else
46  rank = PetscGlobalRank;
47  PetscSleep((PetscReal)rank);
48  }
49 #endif
50  }
51 
52  PetscFPrintf(PETSC_COMM_SELF, PETSC_STDERR,
53  "[%d]MoFEM ERROR: ", PetscGlobalRank);
54  va_start(Argp, format);
55  (*PetscVFPrintf)(PETSC_STDERR, format, Argp);
56  va_end(Argp);
57  return 0;
58 }