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