SCRIPTS SLURM batch_slurmΒΆ

# -*-Python-*-
# Created by grierson at 09 Jun 2018  18:08

"""
This script submits a SLURM job
"""

if SERVER(root['SETTINGS']['REMOTE_SETUP']['serverPicker']) == 'iris':
    partition = 'preemptable'
elif SERVER(root['SETTINGS']['REMOTE_SETUP']['serverPicker']) == 'portal':
    partition = 'sque'
else:
    printe('SLURM partition not defined for chosen server')
    OMFITx.End()

# The SLURM batch submission script
slurm_script = '''#!/bin/bash
#SBATCH -J ex
#SBATCH -o batch.out
#SBATCH -e batch.err
#SBATCH -t 0:01:00
#SBATCH -n 1
#SBATCH --mem=10M
#SBATCH -p {}

sleep 3

chmod +x ex.sh

./ex.sh

exit 0

'''.format(
    partition
)

# The code to run.
ex = '''
#!/bin/bash

echo 'hello world std_out'
>&2 echo 'hello world std_err'

sleep 20

pwd > pwd.txt

exit 0

'''

# Make the code we want to run an executable script in a file
ex_sh = OMFITascii('ex.sh', fromString=ex)

OMFITx.executable(
    root,
    inputs=[ex_sh],
    outputs=['pwd.txt'],
    std_out='batch.out',
    std_err='batch.err',
    script=(slurm_script, 'slurm_script.sh'),
    executable='sbatch %s',
    queued=True,
)

root['OUTPUTS'].setdefault('SLURM', OMFITtree())

# Load the output of the job into OMFIT
root['OUTPUTS']['SLURM']['pwd'] = OMFITascii('./pwd.txt')