1*a4963045SJacob Faibussowitsch #pragma once
29beb8f72SToby Isaac
39beb8f72SToby Isaac #include <petscsys.h>
49beb8f72SToby Isaac
PetscErrorMemoryMessage(PetscErrorCode n)59beb8f72SToby Isaac static inline PetscErrorCode PetscErrorMemoryMessage(PetscErrorCode n)
69beb8f72SToby Isaac {
79beb8f72SToby Isaac PetscLogDouble mem, rss;
89beb8f72SToby Isaac PetscErrorCode ierr;
99beb8f72SToby Isaac PetscBool flg1 = PETSC_FALSE, flg2 = PETSC_FALSE, flg3 = PETSC_FALSE;
109beb8f72SToby Isaac
119beb8f72SToby Isaac if (n == PETSC_ERR_MEM) {
129beb8f72SToby Isaac ierr = (*PetscErrorPrintf)("Out of memory. This could be due to allocating\n");
139beb8f72SToby Isaac ierr = (*PetscErrorPrintf)("too large an object or bleeding by not properly\n");
149beb8f72SToby Isaac ierr = (*PetscErrorPrintf)("destroying unneeded objects.\n");
159beb8f72SToby Isaac } else {
169beb8f72SToby Isaac ierr = (*PetscErrorPrintf)("Memory leaked due to not properly destroying\n");
179beb8f72SToby Isaac ierr = (*PetscErrorPrintf)("unneeded objects.\n");
189beb8f72SToby Isaac }
199beb8f72SToby Isaac ierr = PetscMallocGetCurrentUsage(&mem);
209beb8f72SToby Isaac ierr = PetscMemoryGetCurrentUsage(&rss);
219beb8f72SToby Isaac ierr = PetscOptionsGetBool(NULL, NULL, "-on_error_malloc_dump", &flg1, NULL);
229beb8f72SToby Isaac ierr = PetscOptionsGetBool(NULL, NULL, "-malloc_view", &flg2, NULL);
239beb8f72SToby Isaac ierr = PetscOptionsHasName(NULL, NULL, "-malloc_view_threshold", &flg3);
249beb8f72SToby Isaac if (flg2 || flg3) ierr = PetscMallocView(stdout);
259beb8f72SToby Isaac else {
269beb8f72SToby Isaac ierr = (*PetscErrorPrintf)("Memory allocated %.0f Memory used by process %.0f\n", mem, rss);
279beb8f72SToby Isaac if (flg1) ierr = PetscMallocDump(stdout);
289beb8f72SToby Isaac else ierr = (*PetscErrorPrintf)("Try running with -on_error_malloc_dump or -malloc_view for info.\n");
299beb8f72SToby Isaac }
309beb8f72SToby Isaac return ierr;
319beb8f72SToby Isaac }
32