xref: /petsc/src/sys/error/errstop.c (revision b43aa488f900e1fa15f896f863d5deacb647a378)
1 
2 #include <petscsys.h> /*I "petscsys.h" I*/
3 
4 /*@C
5   PetscMPIAbortErrorHandler - Calls PETSCABORT and exits.
6 
7   Not Collective
8 
9   Input Parameters:
10 + comm - communicator over which error occurred
11 . line - the line number of the error (indicated by __LINE__)
12 . file - the file in which the error was detected (indicated by __FILE__)
13 . mess - an error text string, usually just printed to the screen
14 . n    - the generic error number
15 . p    - `PETSC_ERROR_INITIAL` if error just detected, otherwise `PETSC_ERROR_REPEAT`
16 - ctx  - error handler context
17 
18   Level: developer
19 
20   Note:
21   Users do not directly call this routine
22 
23   Use `PetscPushErrorHandler()` to set the desired error handler.  The
24   currently available PETSc error handlers include `PetscTraceBackErrorHandler()`,
25   `PetscMPIAbortErrorHandler()`, `PetscAttachDebuggerErrorHandler()`, and `PetscAbortErrorHandler()`.
26 
27 .seealso: `PetscError()`, `PetscPushErrorHandler()`, `PetscPopErrorHandler()`, `PetscAttachDebuggerErrorHandler()`,
28           `PetscAbortErrorHandler()`, `PetscMPIAbortErrorHandler()`, `PetscTraceBackErrorHandler()`, `PetscEmacsClientErrorHandler()`, `PetscReturnErrorHandler()`
29  @*/
30 PetscErrorCode PetscMPIAbortErrorHandler(MPI_Comm comm, int line, const char *fun, const char *file, PetscErrorCode n, PetscErrorType p, const char *mess, void *ctx)
31 {
32   PetscErrorCode ierr;
33   PetscBool      flg1 = PETSC_FALSE, flg2 = PETSC_FALSE, flg3 = PETSC_FALSE;
34   PetscLogDouble mem, rss;
35 
36   PetscFunctionBegin;
37   if (!mess) mess = " ";
38 
39   if (n == PETSC_ERR_MEM) {
40     ierr = (*PetscErrorPrintf)("%s() at %s:%d\n", fun, file, line);
41     ierr = (*PetscErrorPrintf)("Out of memory. This could be due to allocating\n");
42     ierr = (*PetscErrorPrintf)("too large an object or bleeding by not properly\n");
43     ierr = (*PetscErrorPrintf)("destroying unneeded objects.\n");
44     ierr = PetscMallocGetCurrentUsage(&mem);
45     ierr = PetscMemoryGetCurrentUsage(&rss);
46     ierr = PetscOptionsGetBool(NULL, NULL, "-malloc_dump", &flg1, NULL);
47     ierr = PetscOptionsGetBool(NULL, NULL, "-malloc_view", &flg2, NULL);
48     ierr = PetscOptionsHasName(NULL, NULL, "-malloc_view_threshold", &flg3);
49     if (flg2 || flg3) ierr = PetscMallocView(stdout);
50     else {
51       ierr = (*PetscErrorPrintf)("Memory allocated %.0f Memory used by process %.0f\n", mem, rss);
52       if (flg1) ierr = PetscMallocDump(stdout);
53       else ierr = (*PetscErrorPrintf)("Try running with -malloc_dump or -malloc_view for info.\n");
54     }
55   } else if (n == PETSC_ERR_SUP) {
56     ierr = (*PetscErrorPrintf)("%s() at %s:%d\n", fun, file, line);
57     ierr = (*PetscErrorPrintf)("No support for this operation for this object type!\n");
58     ierr = (*PetscErrorPrintf)("%s\n", mess);
59   } else if (n == PETSC_ERR_SIG) ierr = (*PetscErrorPrintf)("%s() at %s:%d %s\n", fun, file, line, mess);
60   else ierr = (*PetscErrorPrintf)("%s() at %s:%d\n    %s\n", fun, file, line, mess);
61 
62   (void)ierr;
63   PETSCABORT(PETSC_COMM_WORLD, n);
64   PetscFunctionReturn(PETSC_SUCCESS);
65 }
66