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