xref: /petsc/src/sys/error/errstop.c (revision 9371c9d470a9602b6d10a8bf50c9b2280a79e45a)
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
15668f157eSBarry 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 
20e5c89e4eSSatish Balay    Notes:
21e5c89e4eSSatish Balay    Most users need not directly employ this routine and the other error
22e5c89e4eSSatish Balay    handlers, but can instead use the simplified interface SETERRQ, which has
23e5c89e4eSSatish Balay    the calling sequence
24e32f2f54SBarry Smith $     SETERRQ(comm,n,p,mess)
25e5c89e4eSSatish Balay 
26e5c89e4eSSatish Balay    Notes for experienced users:
27e5c89e4eSSatish Balay    Use PetscPushErrorHandler() to set the desired error handler.  The
28e5c89e4eSSatish Balay    currently available PETSc error handlers include PetscTraceBackErrorHandler(),
29e8fb0fc0SBarry Smith    PetscMPIAbortErrorHandler(), PetscAttachDebuggerErrorHandler(), and PetscAbortErrorHandler().
30e5c89e4eSSatish Balay 
31db781477SPatrick Sanan .seealso: `PetscError()`, `PetscPushErrorHandler()`, `PetscPopErrorHandler()`, `PetscAttachDebuggerErrorHandler()`,
32db781477SPatrick Sanan           `PetscAbortErrorHandler()`, `PetscMPIAbortErrorHandler()`, `PetscTraceBackErrorHandler()`, `PetscEmacsClientErrorHandler()`, `PetscReturnErrorHandler()`
33e5c89e4eSSatish Balay  @*/
34*9371c9d4SSatish Balay PetscErrorCode PetscMPIAbortErrorHandler(MPI_Comm comm, int line, const char *fun, const char *file, PetscErrorCode n, PetscErrorType p, const char *mess, void *ctx) {
35574034a9SJed Brown   PetscBool      flg1 = PETSC_FALSE, flg2 = PETSC_FALSE, flg3 = PETSC_FALSE;
36e5c89e4eSSatish Balay   PetscLogDouble mem, rss;
37e5c89e4eSSatish Balay 
38e5c89e4eSSatish Balay   PetscFunctionBegin;
39e5c89e4eSSatish Balay   if (!mess) mess = " ";
40e5c89e4eSSatish Balay 
41e5c89e4eSSatish Balay   if (n == PETSC_ERR_MEM) {
422f307e7aSJunchao Zhang     (*PetscErrorPrintf)("%s() at %s:%d\n", fun, file, line);
43e5c89e4eSSatish Balay     (*PetscErrorPrintf)("Out of memory. This could be due to allocating\n");
44e5c89e4eSSatish Balay     (*PetscErrorPrintf)("too large an object or bleeding by not properly\n");
45e5c89e4eSSatish Balay     (*PetscErrorPrintf)("destroying unneeded objects.\n");
46*9371c9d4SSatish Balay     PetscMallocGetCurrentUsage(&mem);
47*9371c9d4SSatish Balay     PetscMemoryGetCurrentUsage(&rss);
48c5929fdfSBarry Smith     PetscOptionsGetBool(NULL, NULL, "-malloc_dump", &flg1, NULL);
4992f119d6SBarry Smith     PetscOptionsGetBool(NULL, NULL, "-malloc_view", &flg2, NULL);
5092f119d6SBarry Smith     PetscOptionsHasName(NULL, NULL, "-malloc_view_threshold", &flg3);
5192f119d6SBarry Smith     if (flg2 || flg3) PetscMallocView(stdout);
52a297a907SKarl Rupp     else {
53b85f3346SJed Brown       (*PetscErrorPrintf)("Memory allocated %.0f Memory used by process %.0f\n", mem, rss);
54a297a907SKarl Rupp       if (flg1) PetscMallocDump(stdout);
5579dccf82SBarry Smith       else (*PetscErrorPrintf)("Try running with -malloc_dump or -malloc_view for info.\n");
56e5c89e4eSSatish Balay     }
57e5c89e4eSSatish Balay   } else if (n == PETSC_ERR_SUP) {
582f307e7aSJunchao Zhang     (*PetscErrorPrintf)("%s() at %s:%d\n", fun, file, line);
59e5c89e4eSSatish Balay     (*PetscErrorPrintf)("No support for this operation for this object type!\n");
60e5c89e4eSSatish Balay     (*PetscErrorPrintf)("%s\n", mess);
612f307e7aSJunchao Zhang   } else if (n == PETSC_ERR_SIG) (*PetscErrorPrintf)("%s() at %s:%d %s\n", fun, file, line, mess);
622f307e7aSJunchao Zhang   else (*PetscErrorPrintf)("%s() at %s:%d\n    %s\n", fun, file, line, mess);
63a297a907SKarl Rupp 
6441e02c4dSJunchao Zhang   PETSCABORT(PETSC_COMM_WORLD, n);
65e5c89e4eSSatish Balay   PetscFunctionReturn(0);
66e5c89e4eSSatish Balay }
67