1*1b37a2a7SPierre Jolivet#!/usr/bin/env python3 2296f63deSMatthew G Knepleydef generateBatchScript(num, procs, time, *args): 3296f63deSMatthew G Knepley body = '''\ 4296f63deSMatthew G Knepley#!/bin/bash 5296f63deSMatthew G Knepley#PBS -N ex%d_GPU_test 6296f63deSMatthew G Knepley#PBS -l walltime=%02d:%02d:%02d 7296f63deSMatthew G Knepley#PBS -l nodes=%d:ppn=1 8296f63deSMatthew G Knepley#PBS -j oe 9296f63deSMatthew G Knepleycd $PBS_O_WORKDIR 109dddd249SSatish Balayecho Main process running on `hostname` 11296f63deSMatthew G Knepleyecho Directory is `pwd` 12296f63deSMatthew G Knepleyecho PBS has allocated the following nodes: 13296f63deSMatthew G Knepleyecho `cat $PBS_NODEFILE` 144dcdf380SSatish Balayecho Starting execution at `date +'%a, %d %b %Y %H:%M:%S %z'` 15296f63deSMatthew G KnepleyNPROCS=`wc -l < $PBS_NODEFILE` 16296f63deSMatthew G Knepleyecho This job has allocated $NPROCS CPUs 17296f63deSMatthew G Knepley# execute an MPI program 18a6404fbfSBarry Smithecho Executing mpiexec -np $NPROCS ex%d %s 19a6404fbfSBarry Smithmpiexec -np $NPROCS ex%d %s 20296f63deSMatthew G Knepley''' % (num, (time%86400)/3600, (time%3600)/60, time%60, procs, num, ' '.join(args), num, ' '.join(args)) 21296f63deSMatthew G Knepley namePattern = 'ex%d_%03d.batch' 22296f63deSMatthew G Knepley for n in range(1000): 23296f63deSMatthew G Knepley try: 243849a283SMatthew G Knepley filename = namePattern % (num, n) 253849a283SMatthew G Knepley f = file(filename) 26296f63deSMatthew G Knepley f.close() 27296f63deSMatthew G Knepley n += 1 285b6bfdb9SJed Brown except IOError as e: 29296f63deSMatthew G Knepley if e.errno == 2: 30296f63deSMatthew G Knepley break 31296f63deSMatthew G Knepley else: 32296f63deSMatthew G Knepley raise e 333849a283SMatthew G Knepley with file(filename, 'w') as f: 34296f63deSMatthew G Knepley f.write(body) 353849a283SMatthew G Knepley return filename 36296f63deSMatthew G Knepley 37296f63deSMatthew G Knepleyif __name__ == '__main__': 38296f63deSMatthew G Knepley # Waiting for argparse in 2.7 39296f63deSMatthew G Knepley import sys 40296f63deSMatthew G Knepley num = int(sys.argv[1]) 41296f63deSMatthew G Knepley time = int(sys.argv[2]) # in seconds 42296f63deSMatthew G Knepley procs = int(sys.argv[3]) 43609bdbeeSBarry Smith #args = ['-da_grid_x 800', '-da_grid_y 800', '-log_view', '-log_summary_python'] 44296f63deSMatthew G Knepley generateBatchScript(num, procs, time, *sys.argv[4:]) 45