qmcpack/nexus/library/memory.py

65 lines
2.2 KiB
Python
Raw Normal View History

##################################################################
## (c) Copyright 2015- by Jaron T. Krogel ##
##################################################################
#====================================================================#
# memory.py #
# Calculate memory used by the Nexus host process. #
# #
# Content summary: #
# memory #
# Return memory usage of the current process. #
# #
# resident #
# Return resident memory usage. #
# #
# stacksize #
# Return stack size. #
Major updates to Nexus: see full text of message Changes made to render core of Nexus more robust, a couple of bug fixes, several additions to functionality, and several files relegated to "legacy". ================= new functionality ================= -added support for templated input for qmcpack generation is no longer required should also work for all supported codes now also allows driving of generic simulation codes lacking detailed nexus interface -added basic interfaces to drive CRYSTAL and properties -added support to convert to CASINO pseudopotential format for semilocal PPs can convert from GAMESS/CRYSTAL to QMCPACK/CASINO also convert between QMCPACK and CASINO -improved handling of gamma point calculations for pwscf better autodetection of gamma point explicit user override to forbid "KPOINTS gamma" -added support for head node/local job submission useful for lightweight serial tools or scripts in workflows -added "execute" function to Simulation will later enable use generation/running of simulations directly within user script will allow for dynamic workflows, rather than dynamic execution of static workflows -added enum class to developer.py -added general formatted read to TextFile class in fileio.py ========= bug fixes ========= -dependents of failed simulations now guaranteed not to run following interruption and restart of user script -run directory creation now guaranteed to occur prior to simulation dependency processing ================ added robustness ================ -restructured global base class (obj) in generic.py remove dependence on abilities.py classes streamline and expand base class functions move to "new-style" Python classes (inherit from object) -added nexuscore "namespace" and NexusCore base class better control of core vs. noncore information propagation less chance of downstream breakage (e.g. for derived Simulation classes) classes inheriting from NexusCore: Settings ProjectManager Machine Job Simulation SimulationImage SimulationInput SimulationAnalyzer -added separate SimulationImage class for save/load of Simulation state ensures only central information is saved/loaded prevents interaction with derived Simulation classes -improved organization for Settings class -removed debug log cruft from ProjectManager -improved definition of SimulationTemplateInput now uses string.Template rather than custom code -replaced dynamic type detection functionality from types module with inspect -simplified UnitConverter class -made periodic_table process symbols consistently ============ housekeeping ============ -removed unused files converters.py auxilliary.py -relegated several superseded/less used files to new legacy directory abilities.py differences.py qmcpack_pp_validation.py cascade.py eos_fit.py qmcpack_variations.py density_analyzer.py generator.py qmc.py dft.py qmcpack_calculations.py -consolidated orbital converters for qmcpack into qmcpack_converters.py replaces convert4qmc.py, pw2qmcpack.py, wfconvert.py -consolidated numerical functionality into numerics.py extended_numpy.py is removed along with ill-advised "from numpy import *" -consolidated files associated with QmcpackAnalyzer plotter.py qaobject.py spacegrid.py -renamed project.py as nexus.py, removing vacuous nexus.py also renamed project_base.py as nexus_base.py -separated processing of basis sets to basissets.py -removed outdated BundledQmcpack class git-svn-id: https://subversion.assembla.com/svn/qmcdev/trunk@6616 e5b18d87-469d-4833-9cc0-8cdfa06e9491
2015-11-12 03:39:04 +08:00
# #
#====================================================================#
import os
_proc_status = '/proc/%d/status' % os.getpid()
_scale = {'kB': 1024.0, 'mB': 1024.0*1024.0,
'KB': 1024.0, 'MB': 1024.0*1024.0}
def _VmB(VmKey):
'''Private.
'''
global _proc_status, _scale
# get pseudo file /proc/<pid>/status
try:
t = open(_proc_status)
v = t.read()
t.close()
except:
return 0.0 # non-Linux?
# get VmKey line e.g. 'VmRSS: 9999 kB\n ...'
i = v.index(VmKey)
v = v[i:].split(None, 3) # whitespace
if len(v) < 3:
return 0.0 # invalid format?
# convert Vm value to bytes
return float(v[1]) * _scale[v[2]]
def memory(since=0.0):
'''Return memory usage in bytes.
'''
return _VmB('VmSize:') - since
def resident(since=0.0):
'''Return resident memory usage in bytes.
'''
return _VmB('VmRSS:') - since
def stacksize(since=0.0):
'''Return stack size in bytes.
'''
return _VmB('VmStk:') - since