Up: Contents
Next: Machine-Specific Optimizations
Previous: Tips for Efficient Use of Linear Solvers
PETSc provides a number of tools to aid in detection of problems
with memory allocation, including leaks and use of uninitialized space.
We briefly describe these below.
- The PETSc memory allocation (which collects statistics and performs
error checking), is employed by default for codes compiled in a
debug mode ( BOPT=g, BOPT=g_c++, BOPT=g_complex).
PETSc memory allocation can be activated for other other cases, such
as BOPT=O, with the option -trmalloc, while
-trmalloc_off forces the use of conventional memory allocation for the
BOPT=g, BOPT=g_c++, and BOPT=g_complex versions.
When running timing tests, one should use
the BOPT=O version of the libraries.
- When the PETSc memory allocation routines are used, the option
-trdump will print a list of unfreed memory at the conclusion of a
program. If all memory has been freed, only a message stating
the maximum allocated space will be printed. However, if some memory
remains unfreed, this information will be printed. Note that the
option -trdump merely activates a call to PetscTrDump() during
PetscFinalize(); the user can also call PetscTrDump() elsewhere
in a program.
- Another useful option for use with PETSc memory allocation
routines is -trmalloc_log, which activates logging of all calls
to malloc and reports memory usage, including all Fortran arrays.
This option provides a more complete picture than -trdump for
codes that employ Fortran with hardwired arrays. Note that the option
-trmalloc_log activates calls to PetscTrLog(),
PetscTrLogDump(), and PetscGetResidentSetSize() during
PetscFinalize(); the user can also call these routines elsewhere in a
program.
- The option -trmalloc_nan is useful for tracking down the
allocated memory that is used before it has been initialized. This
option calls PetscInitializeNans() which marks an array as being
uninitialized, so that if values are used for computation without
first having been set, a floating point exception is generated. This
option also calls PetscInitializeLargeInts(); see the manual pages for
details. Note that so far these work only on the certain systems.
- The utility ${}PETSC_DIR/bin/petscview can illustrate graphically
what PETSc objects have never been properly destroyed during a run.
First, one should check that the source has been compiled with the
-DPETSC_LOG flag (which is the default for all versions).
Then one can run the program with the -log option, and view the resulting
log file with petscview, which uses colors to illustrate different
levels of object activity. When PETSc objects have been destroyed,
they change color (gray, by default). Any objects that have not
been properly destroyed (so that their memory remains allocated)
should not turn gray.
Up: Contents
Next: Machine-Specific Optimizations
Previous: Tips for Efficient Use of Linear Solvers