Skip to content

Commit

Permalink
added method to check memory avaiable
Browse files Browse the repository at this point in the history
  • Loading branch information
kwhitehall committed Feb 25, 2016
1 parent ef1e7c0 commit c8af0e8
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
5 changes: 5 additions & 0 deletions code/iomethods.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,11 @@ def read_data(varName, latName, lonName, userVariables, filelist=None):
global LAT
global LON

mem = utils.sufficient_mem(userVariables.DIRS, userVariables.filelist, 2)
if not mem:
print 'There is not enough memory on this system to complete this task'
sys.exit()

timeName = 'time'

filelistInstructions = userVariables.DIRS['CEoriDirName']+'/*'
Expand Down
28 changes: 28 additions & 0 deletions code/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,34 @@
import numpy.ma as ma
from netCDF4 import Dataset
from scipy.ndimage import map_coordinates
from psutil import virtual_memory

def sufficient_mem(fileNamesDict, filelist, numProc):
'''
Purpose:: To check for the avialable memory on a system and compare with
the memory needed to complete the work
Input:: filesDict - dictionary with paths to inputFiles
filelist - list of core (MERG)files to be used
num of processes
Output:: boolean indicating if there is sufficient mem or not
'''
sysMem = virtual_memory()
maxMemList = []
maxMemList.append(max(os.path.getsize(i) for i in filelist))

for directory in fileNamesDict:
if not 'CEoriDirName' in directory or not 'mainDirStr' in directory:
maxMemList.append(max(os.path.getsize(i) for i in glob.glob(fileNamesDict[directory]+'/*')))

#min mem required = 2 * fileSizes * numProc
minMemReq = sum((2 * i * numProc) for i in maxMemList)

This comment has been minimized.

Copy link
@kwhitehall

kwhitehall Feb 25, 2016

Author Owner

raw heuristic calculation for min mem required


if minMemReq > maxMemList:
return False
else:
return True


def do_regrid(inputGrid, lat, lon, lat2, lon2, order=1, mdi=-999999999):
Expand Down

0 comments on commit c8af0e8

Please sign in to comment.