Merge pull request #421 from akohlmey/memory-output

improve memory usage reporting in info and output class
This commit is contained in:
sjplimp 2017-03-17 11:18:08 -06:00 committed by GitHub
commit fcc3b3bd36
4 changed files with 71 additions and 37 deletions

View File

@ -12,7 +12,7 @@ info command :h3
info args :pre info args :pre
args = one or more of the following keywords: {out}, {all}, {system}, {communication}, {computes}, {dumps}, {fixes}, {groups}, {regions}, {variables}, {styles}, {time}, or {configuration} args = one or more of the following keywords: {out}, {all}, {system}, {memory}, {communication}, {computes}, {dumps}, {fixes}, {groups}, {regions}, {variables}, {styles}, {time}, or {configuration}
{out} values = {screen}, {log}, {append} filename, {overwrite} filename {out} values = {screen}, {log}, {append} filename, {overwrite} filename
{styles} values = {all}, {angle}, {atom}, {bond}, {compute}, {command}, {dump}, {dihedral}, {fix}, {improper}, {integrate}, {kspace}, {minimize}, {pair}, {region} :ul {styles} values = {all}, {angle}, {atom}, {bond}, {compute}, {command}, {dump}, {dihedral}, {fix}, {improper}, {integrate}, {kspace}, {minimize}, {pair}, {region} :ul
@ -40,6 +40,17 @@ to that file, which is either appended to or overwritten, respectively.
The {all} flag activates printing all categories listed below. The {all} flag activates printing all categories listed below.
The {configuration} category prints some information about the
LAMMPS version as well as architecture and OS it is run on.
The {memory} category prints some information about the current
memory allocation of MPI rank 0 (this the amount of dynamically
allocated memory reported by LAMMPS classes). Where supported,
also some OS specific information about the size of the reserved
memory pool size (this is where malloc() and the new operator
request memory from) and the maximum resident set size is reported
(this is the maximum amount of physical memory occupied so far).
The {system} category prints a general system overview listing. This The {system} category prints a general system overview listing. This
includes the unit style, atom style, number of atoms, bonds, angles, includes the unit style, atom style, number of atoms, bonds, angles,
dihedrals, and impropers and the number of the respective types, box dihedrals, and impropers and the number of the respective types, box
@ -93,11 +104,6 @@ region :ul
The {time} category prints the accumulated CPU and wall time for the The {time} category prints the accumulated CPU and wall time for the
process that writes output (usually MPI rank 0). process that writes output (usually MPI rank 0).
The {configuration} command prints some information about the LAMMPS
version and architecture and OS it is run on. Where supported, also
information about the memory consumption provided by the OS is
reported.
[Restrictions:] none [Restrictions:] none
[Related commands:] [Related commands:]

2
src/.gitignore vendored
View File

@ -655,6 +655,8 @@
/pair_hbond_dreiding_lj.h /pair_hbond_dreiding_lj.h
/pair_hbond_dreiding_morse.cpp /pair_hbond_dreiding_morse.cpp
/pair_hbond_dreiding_morse.h /pair_hbond_dreiding_morse.h
/pair_kolmogorov_crespi_z.cpp
/pair_kolmogorov_crespi_z.h
/pair_lcbop.cpp /pair_lcbop.cpp
/pair_lcbop.h /pair_lcbop.h
/pair_line_lj.cpp /pair_line_lj.cpp

View File

@ -72,32 +72,33 @@ enum {COMPUTES=1<<0,
REGIONS=1<<4, REGIONS=1<<4,
CONFIG=1<<5, CONFIG=1<<5,
TIME=1<<6, TIME=1<<6,
VARIABLES=1<<7, MEMORY=1<<7,
SYSTEM=1<<8, VARIABLES=1<<8,
COMM=1<<9, SYSTEM=1<<9,
ATOM_STYLES=1<<10, COMM=1<<10,
INTEGRATE_STYLES=1<<11, ATOM_STYLES=1<<11,
MINIMIZE_STYLES=1<<12, INTEGRATE_STYLES=1<<12,
PAIR_STYLES=1<<13, MINIMIZE_STYLES=1<<13,
BOND_STYLES=1<<14, PAIR_STYLES=1<<14,
ANGLE_STYLES=1<<15, BOND_STYLES=1<<15,
DIHEDRAL_STYLES=1<<16, ANGLE_STYLES=1<<16,
IMPROPER_STYLES=1<<17, DIHEDRAL_STYLES=1<<17,
KSPACE_STYLES=1<<18, IMPROPER_STYLES=1<<18,
FIX_STYLES=1<<19, KSPACE_STYLES=1<<19,
COMPUTE_STYLES=1<<20, FIX_STYLES=1<<20,
REGION_STYLES=1<<21, COMPUTE_STYLES=1<<21,
DUMP_STYLES=1<<22, REGION_STYLES=1<<22,
COMMAND_STYLES=1<<23, DUMP_STYLES=1<<23,
COMMAND_STYLES=1<<24,
ALL=~0}; ALL=~0};
static const int STYLES = ATOM_STYLES | INTEGRATE_STYLES | MINIMIZE_STYLES | PAIR_STYLES | BOND_STYLES | \ static const int STYLES = ATOM_STYLES | INTEGRATE_STYLES | MINIMIZE_STYLES
ANGLE_STYLES | DIHEDRAL_STYLES | IMPROPER_STYLES | KSPACE_STYLES | FIX_STYLES | \ | PAIR_STYLES | BOND_STYLES | ANGLE_STYLES
COMPUTE_STYLES | REGION_STYLES | DUMP_STYLES | COMMAND_STYLES; | DIHEDRAL_STYLES | IMPROPER_STYLES | KSPACE_STYLES
| FIX_STYLES | COMPUTE_STYLES | REGION_STYLES
| DUMP_STYLES | COMMAND_STYLES;
} }
static const char *varstyles[] = { static const char *varstyles[] = {
"index", "loop", "world", "universe", "uloop", "string", "getenv", "index", "loop", "world", "universe", "uloop", "string", "getenv",
"file", "atomfile", "format", "equal", "atom", "python", "(unknown)"}; "file", "atomfile", "format", "equal", "atom", "python", "(unknown)"};
@ -174,6 +175,9 @@ void Info::command(int narg, char **arg)
} else if (strncmp(arg[idx],"time",3) == 0) { } else if (strncmp(arg[idx],"time",3) == 0) {
flags |= TIME; flags |= TIME;
++idx; ++idx;
} else if (strncmp(arg[idx],"memory",3) == 0) {
flags |= MEMORY;
++idx;
} else if (strncmp(arg[idx],"variables",3) == 0) { } else if (strncmp(arg[idx],"variables",3) == 0) {
flags |= VARIABLES; flags |= VARIABLES;
++idx; ++idx;
@ -293,27 +297,42 @@ void Info::command(int narg, char **arg)
fprintf(out,"\nOS information: %s %s on %s\n", fprintf(out,"\nOS information: %s %s on %s\n",
ut.sysname, ut.release, ut.machine); ut.sysname, ut.release, ut.machine);
#endif #endif
}
if (flags & MEMORY) {
fprintf(out,"\nMemory allocation information (MPI rank 0)\n"); fprintf(out,"\nMemory allocation information (MPI rank 0):\n\n");
bigint bytes = 0;
bytes += atom->memory_usage();
bytes += neighbor->memory_usage();
bytes += comm->memory_usage();
bytes += update->memory_usage();
bytes += force->memory_usage();
bytes += modify->memory_usage();
for (int i = 0; i < output->ndump; i++)
bytes += output->dump[i]->memory_usage();
double mbytes = bytes/1024.0/1024.0;
fprintf(out,"Total dynamically allocated memory: %.4g Mbyte\n",mbytes);
#if defined(_WIN32) #if defined(_WIN32)
HANDLE phandle = GetCurrentProcess(); HANDLE phandle = GetCurrentProcess();
PROCESS_MEMORY_COUNTERS_EX pmc; PROCESS_MEMORY_COUNTERS_EX pmc;
GetProcessMemoryInfo(phandle,(PROCESS_MEMORY_COUNTERS *)&pmc,sizeof(pmc)); GetProcessMemoryInfo(phandle,(PROCESS_MEMORY_COUNTERS *)&pmc,sizeof(pmc));
fprintf(out,"Non-shared memory use: %.3g Mbyte\n", fprintf(out,"Non-shared memory use: %.4g Mbyte\n",
(double)pmc.PrivateUsage/1048576.0); (double)pmc.PrivateUsage/1048576.0);
fprintf(out,"Maximum working set size: %.3g Mbyte\n", fprintf(out,"Maximum working set size: %.4g Mbyte\n",
(double)pmc.PeakWorkingSetSize/1048576.0); (double)pmc.PeakWorkingSetSize/1048576.0);
#else #else
#if defined(__linux) #if defined(__linux)
struct mallinfo mi; struct mallinfo mi;
mi = mallinfo(); mi = mallinfo();
fprintf(out,"Total dynamically allocated memory: %.3g Mbyte\n", fprintf(out,"Current reserved memory pool size: %.4g Mbyte\n",
(double)mi.uordblks/1048576.0); (double)mi.uordblks/1048576.0+(double)mi.hblkhd/1048576.0);
#endif #endif
struct rusage ru; struct rusage ru;
if (getrusage(RUSAGE_SELF, &ru) == 0) { if (getrusage(RUSAGE_SELF, &ru) == 0) {
fprintf(out,"Maximum resident set size: %.3g Mbyte\n", fprintf(out,"Maximum resident set size: %.4g Mbyte\n",
(double)ru.ru_maxrss/1024.0); (double)ru.ru_maxrss/1024.0);
} }
#endif #endif

View File

@ -812,9 +812,9 @@ void Output::create_restart(int narg, char **arg)
sum and print memory usage sum and print memory usage
result is only memory on proc 0, not averaged across procs result is only memory on proc 0, not averaged across procs
------------------------------------------------------------------------- */ ------------------------------------------------------------------------- */
void Output::memory_usage() void Output::memory_usage()
{ {
bigint bytes = 0; bigint bytes = 0;
bytes += atom->memory_usage(); bytes += atom->memory_usage();
bytes += neighbor->memory_usage(); bytes += neighbor->memory_usage();
@ -825,11 +825,18 @@ void Output::memory_usage()
for (int i = 0; i < ndump; i++) bytes += dump[i]->memory_usage(); for (int i = 0; i < ndump; i++) bytes += dump[i]->memory_usage();
double mbytes = bytes/1024.0/1024.0; double mbytes = bytes/1024.0/1024.0;
double mbavg,mbmin,mbmax;
MPI_Reduce(&mbytes,&mbavg,1,MPI_DOUBLE,MPI_SUM,0,world);
MPI_Reduce(&mbytes,&mbmin,1,MPI_DOUBLE,MPI_MIN,0,world);
MPI_Reduce(&mbytes,&mbmax,1,MPI_DOUBLE,MPI_MAX,0,world);
mbavg /= comm->nprocs;
if (comm->me == 0) { if (comm->me == 0) {
if (screen) if (screen)
fprintf(screen,"Memory usage per processor = %g Mbytes\n",mbytes); fprintf(screen,"Per MPI rank memory allocation (min/avg/max) = "
"%.4g | %.4g | %.4g Mbytes\n",mbmin,mbavg,mbmax);
if (logfile) if (logfile)
fprintf(logfile,"Memory usage per processor = %g Mbytes\n",mbytes); fprintf(logfile,"Per MPI rank memory allocation (min/avg/max) = "
"%.4g | %.4g | %.4g Mbytes\n",mbmin,mbavg,mbmax);
} }
} }