From f34fa95e271d18c8085502786b6daadb7a5ed5ca Mon Sep 17 00:00:00 2001 From: Stefan Eilemann Date: Tue, 6 Mar 2012 16:22:32 +0100 Subject: [PATCH] Fix slurm script --- scripts/gpu-sd.sbatch | 38 +++++++++++++++++++++++++++++++++----- scripts/slurm.py | 30 ------------------------------ 2 files changed, 33 insertions(+), 35 deletions(-) delete mode 100644 scripts/slurm.py diff --git a/scripts/gpu-sd.sbatch b/scripts/gpu-sd.sbatch index 2c53785..aaeaf86 100755 --- a/scripts/gpu-sd.sbatch +++ b/scripts/gpu-sd.sbatch @@ -1,17 +1,45 @@ #!/usr/bin/env python import os -import slurm +import re import sys import threading -nodes = slurm.getNodelist() +def getNodelist(): + nodelist = os.environ['SLURM_JOB_NODELIST'] + + p = re.compile( '[^\[]+' ) + match = p.match( nodelist ) + basename = match.group() + + p = re.compile( '\[[0-9,\-]+\]' ) + match = p.search( nodelist ) + + p = re.compile( '[0-9,\-]+' ) + match = p.search( match.group( )) + list = match.group() + + p = re.compile( '-' ) + nodes = [] + for i in list.split( ',' ): + match = p.search( i ) + if match: + tuple = i.split( '-' ) + for node in range( int( tuple[0] ), int( tuple[1] ) + 1 ): + nodes.append( '%(name)s%(num)02d' % { 'name' : basename, + 'num' : node } ) + else: + nodes.append( basename + i ) + return nodes + +def launch( command ): + os.popen( command ) + + +nodes = getNodelist() arguments = sys.argv arguments[0] = 'gpu_sd' command = ' '.join( arguments ) -def launch( command ): - os.exec( command ) - threads = [] for node in nodes: launchCmd = 'ssh ' + node + ' ' + command diff --git a/scripts/slurm.py b/scripts/slurm.py deleted file mode 100644 index 593293f..0000000 --- a/scripts/slurm.py +++ /dev/null @@ -1,30 +0,0 @@ -# slurm helper functions -import os -import re - -def getNodelist(): - nodelist = os.environ['SLURM_JOB_NODELIST'] - - p = re.compile( '[^\[]+' ) - match = p.match( nodelist ) - basename = match.group() - - p = re.compile( '\[[0-9,\-]+\]' ) - match = p.search( nodelist ) - - p = re.compile( '[0-9,\-]+' ) - match = p.search( match.group( )) - list = match.group() - - p = re.compile( '-' ) - nodes = [] - for i in list.split( ',' ): - match = p.search( i ) - if match: - tuple = i.split( '-' ) - for node in range( int( tuple[0] ), int( tuple[1] ) + 1 ): - nodes.append( '%(name)s%(num)02d' % { 'name' : basename, - 'num' : node } ) - else: - nodes.append( basename + i ) - return nodes