1*9beb8f72SToby Isaac #ifndef PETSC_SYS_ERROR_ERR_H 2*9beb8f72SToby Isaac #define PETSC_SYS_ERROR_ERR_H 3*9beb8f72SToby Isaac 4*9beb8f72SToby Isaac #include <petscsys.h> 5*9beb8f72SToby Isaac 6*9beb8f72SToby Isaac static inline PetscErrorCode PetscErrorMemoryMessage(PetscErrorCode n) 7*9beb8f72SToby Isaac { 8*9beb8f72SToby Isaac PetscLogDouble mem, rss; 9*9beb8f72SToby Isaac PetscErrorCode ierr; 10*9beb8f72SToby Isaac PetscBool flg1 = PETSC_FALSE, flg2 = PETSC_FALSE, flg3 = PETSC_FALSE; 11*9beb8f72SToby Isaac 12*9beb8f72SToby Isaac if (n == PETSC_ERR_MEM) { 13*9beb8f72SToby Isaac ierr = (*PetscErrorPrintf)("Out of memory. This could be due to allocating\n"); 14*9beb8f72SToby Isaac ierr = (*PetscErrorPrintf)("too large an object or bleeding by not properly\n"); 15*9beb8f72SToby Isaac ierr = (*PetscErrorPrintf)("destroying unneeded objects.\n"); 16*9beb8f72SToby Isaac } else { 17*9beb8f72SToby Isaac ierr = (*PetscErrorPrintf)("Memory leaked due to not properly destroying\n"); 18*9beb8f72SToby Isaac ierr = (*PetscErrorPrintf)("unneeded objects.\n"); 19*9beb8f72SToby Isaac } 20*9beb8f72SToby Isaac ierr = PetscMallocGetCurrentUsage(&mem); 21*9beb8f72SToby Isaac ierr = PetscMemoryGetCurrentUsage(&rss); 22*9beb8f72SToby Isaac ierr = PetscOptionsGetBool(NULL, NULL, "-on_error_malloc_dump", &flg1, NULL); 23*9beb8f72SToby Isaac ierr = PetscOptionsGetBool(NULL, NULL, "-malloc_view", &flg2, NULL); 24*9beb8f72SToby Isaac ierr = PetscOptionsHasName(NULL, NULL, "-malloc_view_threshold", &flg3); 25*9beb8f72SToby Isaac if (flg2 || flg3) ierr = PetscMallocView(stdout); 26*9beb8f72SToby Isaac else { 27*9beb8f72SToby Isaac ierr = (*PetscErrorPrintf)("Memory allocated %.0f Memory used by process %.0f\n", mem, rss); 28*9beb8f72SToby Isaac if (flg1) ierr = PetscMallocDump(stdout); 29*9beb8f72SToby Isaac else ierr = (*PetscErrorPrintf)("Try running with -on_error_malloc_dump or -malloc_view for info.\n"); 30*9beb8f72SToby Isaac } 31*9beb8f72SToby Isaac return ierr; 32*9beb8f72SToby Isaac } 33*9beb8f72SToby Isaac 34*9beb8f72SToby Isaac #endif // #define PETSC_SYS_ERROR_ERR_H 35