cluster:slurmize
Script python para ejecutar un archivo de ordenes
Tenemos un archivo de ordenes, ejemplo,
[osotolongo@brick03 slurmit]$ cat listado head /nas/data/facehbi/vbmcomps/tempdata_10.dat > /home/osotolongo/slurmit/ht10.dat head /nas/data/facehbi/vbmcomps/tempdata_11.dat > /home/osotolongo/slurmit/ht11.dat head /nas/data/facehbi/vbmcomps/tempdata_12.dat > /home/osotolongo/slurmit/ht12.dat
y queremos que estas ordenes se lancen en el cluster. Lo unico que hay que hacer es leer este archivo y por cada linea escribir y ejecutar un sbatch
ifile = str(sys.argv[1]) wdir = 'slurm' if not os.path.isdir(wdir): os.mkdir(wdir) count = 0 with open(ifile, 'r') as orf: for line in orf: count+=1 ofile = wdir+'/sorder_{:04d}'.format(count)+'.sh' cont = '#!/bin/bash\n' cont += '#SBATCH -J '+ifile+'\n' cont += '#SBATCH -c '+str(cpus)+'\n' cont += '#SBATCH --mem-per-cpu=4G\n' cont += '#SBATCH --time='+time+'\n' cont += '#SBATCH --mail-type=FAIL,TIME_LIMIT,STAGE_OUT\n' cont += '#SBATCH --mail-user='+os.environ.get('USER')+'\n' cont += '#SBATCH -o '+wdir+'/'+ifile+'_end-%j\n' cont += '#SBATCH -p fast\n' cont += line+'\n' exf = open(ofile, 'w') exf.write(cont) exf.close() os.system('sbatch '+ofile)
luego, para escribimos un sbatch que dependa de estos (un singleton es suficiente) y lo ejecutamos todo.
En fin, que es sencillo y queda bonito,
#!/usr/bin/python3 import sys import os #Cambiar aqui las variables time = '3:0:0' cpus = 4 ifile = str(sys.argv[1]) wdir = 'slurm' if not os.path.isdir(wdir): os.mkdir(wdir) count = 0 with open(ifile, 'r') as orf: for line in orf: count+=1 ofile = wdir+'/sorder_{:04d}'.format(count)+'.sh' cont = '#!/bin/bash\n' cont += '#SBATCH -J '+ifile+'\n' cont += '#SBATCH -c '+str(cpus)+'\n' cont += '#SBATCH --mem-per-cpu=4G\n' cont += '#SBATCH --time='+time+'\n' cont += '#SBATCH --mail-type=FAIL,TIME_LIMIT,STAGE_OUT\n' cont += '#SBATCH --mail-user='+os.environ.get('USER')+'\n' cont += '#SBATCH -o '+wdir+'/'+ifile+'_end-%j\n' cont += '#SBATCH -p fast\n' cont += line+'\n' exf = open(ofile, 'w') exf.write(cont) exf.close() os.system('sbatch '+ofile) ofile = wdir+'/'+ifile+'_end.sh' cont = '#!/bin/bash\n' cont += '#SBATCH -J '+ifile+'\n' cont += '#SBATCH --mail-type=END\n' cont += '#SBATCH --mail-user='+os.environ.get('USER')+'\n' cont += '#SBATCH -o '+wdir+'/'+ifile+'_end-%j\n' cont += ':\n' exf = open(ofile, 'w') exf.write(cont) exf.close() os.system('sbatch --dependency=singleton '+ofile)
cluster/slurmize.txt · Last modified: 2020/10/10 14:20 by osotolongo