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