1*296f63deSMatthew G Knepley#!/usr/bin/env python 2*296f63deSMatthew G Knepleydef generateBatchScript(num, procs, time, *args): 3*296f63deSMatthew G Knepley body = '''\ 4*296f63deSMatthew G Knepley#!/bin/bash 5*296f63deSMatthew G Knepley#PBS -N ex%d_GPU_test 6*296f63deSMatthew G Knepley#PBS -l walltime=%02d:%02d:%02d 7*296f63deSMatthew G Knepley#PBS -l nodes=%d:ppn=1 8*296f63deSMatthew G Knepley#PBS -j oe 9*296f63deSMatthew G Knepleycd $PBS_O_WORKDIR 10*296f63deSMatthew G Knepleyecho Master process running on `hostname` 11*296f63deSMatthew G Knepleyecho Directory is `pwd` 12*296f63deSMatthew G Knepleyecho PBS has allocated the following nodes: 13*296f63deSMatthew G Knepleyecho `cat $PBS_NODEFILE` 14*296f63deSMatthew G Knepleyecho Starting execution at `date` 15*296f63deSMatthew G KnepleyNPROCS=`wc -l < $PBS_NODEFILE` 16*296f63deSMatthew G Knepleyecho This job has allocated $NPROCS CPUs 17*296f63deSMatthew G Knepley# execute an MPI program 18*296f63deSMatthew G Knepleyecho Executing mpirun -np $NPROCS ex%d %s 19*296f63deSMatthew G Knepleympirun -np $NPROCS ex%d %s 20*296f63deSMatthew G Knepley''' % (num, (time%86400)/3600, (time%3600)/60, time%60, procs, num, ' '.join(args), num, ' '.join(args)) 21*296f63deSMatthew G Knepley namePattern = 'ex%d_%03d.batch' 22*296f63deSMatthew G Knepley for n in range(1000): 23*296f63deSMatthew G Knepley try: 24*296f63deSMatthew G Knepley f = file(namePattern % (num, n)) 25*296f63deSMatthew G Knepley f.close() 26*296f63deSMatthew G Knepley n += 1 27*296f63deSMatthew G Knepley except IOError, e: 28*296f63deSMatthew G Knepley if e.errno == 2: 29*296f63deSMatthew G Knepley break 30*296f63deSMatthew G Knepley else: 31*296f63deSMatthew G Knepley raise e 32*296f63deSMatthew G Knepley with file(namePattern % (num, n), 'w') as f: 33*296f63deSMatthew G Knepley f.write(body) 34*296f63deSMatthew G Knepley return 35*296f63deSMatthew G Knepley 36*296f63deSMatthew G Knepleyif __name__ == '__main__': 37*296f63deSMatthew G Knepley # Waiting for argparse in 2.7 38*296f63deSMatthew G Knepley import sys 39*296f63deSMatthew G Knepley num = int(sys.argv[1]) 40*296f63deSMatthew G Knepley time = int(sys.argv[2]) # in seconds 41*296f63deSMatthew G Knepley procs = int(sys.argv[3]) 42*296f63deSMatthew G Knepley #args = ['-da_grid_x 800', '-da_grid_y 800', '-log_summary', '-log_summary_python'] 43*296f63deSMatthew G Knepley generateBatchScript(num, procs, time, *sys.argv[4:]) 44