xref: /petsc/src/benchmarks/benchmarkBatch.py (revision 4ad8454beace47809662cdae21ee081016eaa39a)
1#!/usr/bin/env python3
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 Main process running on `hostname`
11echo Directory is `pwd`
12echo PBS has allocated the following nodes:
13echo `cat $PBS_NODEFILE`
14echo Starting execution at `date +'%a, %d %b %Y %H:%M:%S %z'`
15NPROCS=`wc -l < $PBS_NODEFILE`
16echo This job has allocated $NPROCS CPUs
17# execute an MPI program
18echo Executing mpiexec -np $NPROCS ex%d %s
19mpiexec -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      filename = namePattern % (num, n)
25      f = file(filename)
26      f.close()
27      n += 1
28    except IOError as e:
29      if e.errno == 2:
30        break
31      else:
32        raise e
33  with file(filename, 'w') as f:
34    f.write(body)
35  return filename
36
37if __name__ == '__main__':
38  # Waiting for argparse in 2.7
39  import sys
40  num   = int(sys.argv[1])
41  time  = int(sys.argv[2]) # in seconds
42  procs = int(sys.argv[3])
43  #args  = ['-da_grid_x 800', '-da_grid_y 800', '-log_view',  '-log_summary_python']
44  generateBatchScript(num, procs, time, *sys.argv[4:])
45