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