xref: /petsc/src/sys/error/errstop.c (revision d71ae5a4db6382e7f06317b8d368875286fe9008)
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
15811af0c4SBarry 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 
20811af0c4SBarry Smith    Note:
21811af0c4SBarry Smith    Users do not directly call this routine
22e5c89e4eSSatish Balay 
23811af0c4SBarry Smith    Use `PetscPushErrorHandler()` to set the desired error handler.  The
24811af0c4SBarry Smith    currently available PETSc error handlers include `PetscTraceBackErrorHandler()`,
25811af0c4SBarry Smith    `PetscMPIAbortErrorHandler()`, `PetscAttachDebuggerErrorHandler()`, and `PetscAbortErrorHandler()`.
26e5c89e4eSSatish Balay 
27db781477SPatrick Sanan .seealso: `PetscError()`, `PetscPushErrorHandler()`, `PetscPopErrorHandler()`, `PetscAttachDebuggerErrorHandler()`,
28db781477SPatrick Sanan           `PetscAbortErrorHandler()`, `PetscMPIAbortErrorHandler()`, `PetscTraceBackErrorHandler()`, `PetscEmacsClientErrorHandler()`, `PetscReturnErrorHandler()`
29e5c89e4eSSatish Balay  @*/
30*d71ae5a4SJacob Faibussowitsch PetscErrorCode PetscMPIAbortErrorHandler(MPI_Comm comm, int line, const char *fun, const char *file, PetscErrorCode n, PetscErrorType p, const char *mess, void *ctx)
31*d71ae5a4SJacob Faibussowitsch {
32574034a9SJed Brown   PetscBool      flg1 = PETSC_FALSE, flg2 = PETSC_FALSE, flg3 = PETSC_FALSE;
33e5c89e4eSSatish Balay   PetscLogDouble mem, rss;
34e5c89e4eSSatish Balay 
35e5c89e4eSSatish Balay   PetscFunctionBegin;
36e5c89e4eSSatish Balay   if (!mess) mess = " ";
37e5c89e4eSSatish Balay 
38e5c89e4eSSatish Balay   if (n == PETSC_ERR_MEM) {
392f307e7aSJunchao Zhang     (*PetscErrorPrintf)("%s() at %s:%d\n", fun, file, line);
40e5c89e4eSSatish Balay     (*PetscErrorPrintf)("Out of memory. This could be due to allocating\n");
41e5c89e4eSSatish Balay     (*PetscErrorPrintf)("too large an object or bleeding by not properly\n");
42e5c89e4eSSatish Balay     (*PetscErrorPrintf)("destroying unneeded objects.\n");
439371c9d4SSatish Balay     PetscMallocGetCurrentUsage(&mem);
449371c9d4SSatish Balay     PetscMemoryGetCurrentUsage(&rss);
45c5929fdfSBarry Smith     PetscOptionsGetBool(NULL, NULL, "-malloc_dump", &flg1, NULL);
4692f119d6SBarry Smith     PetscOptionsGetBool(NULL, NULL, "-malloc_view", &flg2, NULL);
4792f119d6SBarry Smith     PetscOptionsHasName(NULL, NULL, "-malloc_view_threshold", &flg3);
4892f119d6SBarry Smith     if (flg2 || flg3) PetscMallocView(stdout);
49a297a907SKarl Rupp     else {
50b85f3346SJed Brown       (*PetscErrorPrintf)("Memory allocated %.0f Memory used by process %.0f\n", mem, rss);
51a297a907SKarl Rupp       if (flg1) PetscMallocDump(stdout);
5279dccf82SBarry Smith       else (*PetscErrorPrintf)("Try running with -malloc_dump or -malloc_view for info.\n");
53e5c89e4eSSatish Balay     }
54e5c89e4eSSatish Balay   } else if (n == PETSC_ERR_SUP) {
552f307e7aSJunchao Zhang     (*PetscErrorPrintf)("%s() at %s:%d\n", fun, file, line);
56e5c89e4eSSatish Balay     (*PetscErrorPrintf)("No support for this operation for this object type!\n");
57e5c89e4eSSatish Balay     (*PetscErrorPrintf)("%s\n", mess);
582f307e7aSJunchao Zhang   } else if (n == PETSC_ERR_SIG) (*PetscErrorPrintf)("%s() at %s:%d %s\n", fun, file, line, mess);
592f307e7aSJunchao Zhang   else (*PetscErrorPrintf)("%s() at %s:%d\n    %s\n", fun, file, line, mess);
60a297a907SKarl Rupp 
6141e02c4dSJunchao Zhang   PETSCABORT(PETSC_COMM_WORLD, n);
62e5c89e4eSSatish Balay   PetscFunctionReturn(0);
63e5c89e4eSSatish Balay }
64