Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to select memory unit for SGE #46

Merged
merged 1 commit into from
Apr 4, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion jip/cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,7 @@ def __init__(self):
self.threads_pe = sge_cfg.get('threads_pe', None)
self.mem_limit = sge_cfg.get('mem_limit', 'virtual_free')
self.time_limit = sge_cfg.get('time_limit', 's_rt')
self.mem_unit = sge_cfg.get('mem_unit','M').upper()

def resolve_log(self, job, path):
if path is None:
Expand Down Expand Up @@ -444,7 +445,7 @@ def submit(self, job):
if job.working_directory:
cmd.extend(["-wd", job.working_directory])
if job.max_memory > 0:
cmd.extend(["-l", '%s=%sM' % (self.mem_limit, str(job.max_memory))])
cmd.extend(["-l", '%s=%s' % (self.mem_limit, self._sge_mem(job.max_memory))])
if job.account:
cmd.extend(["-A", str(job.account)])
if job.extra is not None:
Expand Down Expand Up @@ -489,6 +490,13 @@ def submit(self, job):
match = re.search(expr, out)
job.job_id = match.group('job_id')

def _sge_mem(self, mem):
if self.mem_unit == 'G':
mem = mem / 1024
if self.mem_unit == 'K':
mem = mem * 1024
return "%s%s" % (mem, self.mem_unit)


class PBS(Cluster):
"""PBS/Torque extension of the Cluster implementation.
Expand Down
25 changes: 25 additions & 0 deletions test/test_cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,28 @@ def test_sge_threads_pe_loading():
}
sge = cl.SGE()
assert sge.threads_pe == 'threads'

@pytest.mark.parametrize("unit,op", [
('G','/ 1024'),
('g','/ 1024'),
('K','* 1024'),
('k','* 1024'),
('M',''),
('m','')
])

def test_sge_mem_unit_loading(unit,op):
mem = 32768
jip.config.config['sge'] = {
"mem_unit": unit
}
sge = cl.SGE()
assert sge.mem_unit == unit.upper()
assert sge._sge_mem(mem) == ('%s%s' % (eval("%s%s" % (mem,op)), unit.upper()))

def test_sge_mem_unit_default():
mem = 32768
sge = cl.SGE()
assert sge.mem_unit == 'M'
assert sge._sge_mem(mem) == '32768M'