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