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