Skip to content

Commit ffc8ce5

Browse files
committed
Bug fixes
1 parent 821ca37 commit ffc8ce5

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

scripts/smart-dispatch

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,12 +148,17 @@ def main():
148148

149149
queue = Queue(args.queueName, CLUSTER_NAME, args.walltime, args.coresPerNode, args.gpusPerNode, args.memPerNode, args.modules)
150150

151-
# Check that requested core number does not exceed node total
151+
# Check that requested per command resources do not exceed node total
152152
if args.coresPerCommand > queue.nb_cores_per_node:
153153
sys.stderr.write("smart-dispatch: error: coresPerCommand exceeds nodes total: asked {req_cores} cores, nodes have {node_cores}\n"
154154
.format(req_cores=args.coresPerCommand, node_cores=queue.nb_cores_per_node))
155155
sys.exit(2)
156156

157+
if args.memPerCommand > queue.mem_per_node:
158+
sys.stderr.write("smart-dispatch: error: memPerCommand exceeds nodes total: asked {req_mem} Gb, nodes have {node_mem} Gb\n"
159+
.format(req_mem=args.memPerCommand, node_mem=queue.mem_per_node))
160+
sys.exit(2)
161+
157162
command_params = {'nb_cores_per_command': args.coresPerCommand,
158163
'nb_gpus_per_command': args.gpusPerCommand,
159164
'mem_per_command': None # args.memPerCommand
@@ -223,7 +228,9 @@ def parse_arguments():
223228
if args.queueName not in AVAILABLE_QUEUES and ((args.coresPerNode is None and args.gpusPerNode is None) or args.walltime is None):
224229
parser.error("Unknown queue, --coresPerNode/--gpusPerNode and --walltime must be set.")
225230
if args.coresPerCommand < 1:
226-
parser.error("coresPerNode must be at least 1")
231+
parser.error("coresPerCommand must be at least 1")
232+
if args.memPerCommand is not None and args.memPerCommand < 0:
233+
parser.error("memPerCommand must be positive")
227234

228235
return args
229236

tests/test_smart_dispatch.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ def setUp(self):
3434
smart_dispatch_command_with_cores = '{} -C 1 -M 1 -c {{cores}} -q test -t 5:00 -x {{0}}'.format(pjoin(scripts_path, 'smart-dispatch'))
3535
self.launch_command_with_cores = smart_dispatch_command_with_cores.format('launch ' + self.folded_commands, cores='{cores}')
3636

37+
smart_dispatch_command_with_memory = '{} -C 1 -M 1 -m {{memory}} -q test -t 5:00 -x {{0}}'.format(pjoin(scripts_path, 'smart-dispatch'))
38+
self.launch_command_with_memory = smart_dispatch_command_with_memory.format('launch ' + self.folded_commands, memory='{memory}')
39+
3740
self._cwd = os.getcwd()
3841
os.chdir(self.testing_dir)
3942

@@ -95,6 +98,18 @@ def test_main_launch_with_cores_command(self):
9598
assert_equal(exit_status_100, 2)
9699
assert_true(os.path.isdir(self.logs_dir))
97100

101+
def test_main_launch_with_memory_command(self):
102+
# Actual test
103+
exit_status_0 = call(self.launch_command_with_memory.format(memory=0), shell=True)
104+
exit_status_05 = call(self.launch_command_with_memory.format(memory=0.5), shell=True)
105+
exit_status_100 = call(self.launch_command_with_memory.format(memory=100), shell=True)
106+
107+
# Test validation
108+
assert_equal(exit_status_0, 2)
109+
assert_equal(exit_status_05, 0)
110+
assert_equal(exit_status_100, 2)
111+
assert_true(os.path.isdir(self.logs_dir))
112+
98113
def test_main_resume(self):
99114
# Setup
100115
call(self.launch_command, shell=True)

0 commit comments

Comments
 (0)