/usr/share/pyshared/adios/skel_submit.py is in python3-adios 1.13.0-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 | #!/usr/bin/env python
import argparse
import os
import skelconf
import adios
import skel_bpy
import skel_settings
# To produce submit scripts, we'll work from a template. There will
# be two types of replacement, simple variables, and macros (for the
# tests)
def generate_submit_scripts_from_xml (params):
settings = skel_settings.skel_settings()
for batch in params.get_batches():
#platform = params.get_target()
settings = skel_settings.skel_settings()
platform = settings.get_submit_target()
sfile = open ('submit_' + platform + '_' + batch.get_name(), 'w')
sfile_template = open (os.path.expanduser('~/.skel/templates/submit_' + platform + '.tpl'), 'r')
i = 0
template_lines = sfile_template.readlines()
while i < len (template_lines):
template_line = template_lines[i]
if '$$START_TEST$$' in template_line:
# This is the test macro, run through it for each test
template_start_index = i + 1
for test in batch.get_tests():
j = template_start_index
template_line = template_lines[j]
while not '$$END_TEST$$' in template_line:
sfile.write (submit_line_template_replace (template_line, params, batch, test, settings))
j = j + 1
template_line = template_lines[j]
# Point at the first line after the macro
i = j + 1
else:
# Fill in any replacement vars in this line...
template_line = submit_line_template_replace (template_line, params, batch, None, settings)
sfile.write (template_line)
i = i + 1
sfile_template.close()
sfile.close()
import re
import math
def submit_line_template_replace (template_line, params, batch, test, settings):
template_line = template_line.replace ('$$JOB_NAME$$', batch.get_name() + '_%d'%batch.get_cores() + '_skel_' + params.get_application() )
template_line = template_line.replace ('$$WALLTIME$$', batch.get_walltime() )
template_line = template_line.replace ('$$APP$$', params.get_application() )
template_line = template_line.replace ('$$CORES_USED$$', '%d'%batch.get_cores() )
template_line = template_line.replace ('$$TARGET$$', params.get_target() )
template_line = template_line.replace ('$$ACCOUNT$$', settings.get_account() )
if test != None:
#Test specific replacements
template_line = template_line.replace ('$$TAGS$$', test.get_tags() )
template_line = template_line.replace ('$$METHOD$$', test.get_method() )
template_line = template_line.replace ('$$EXEC$$', params.get_application() + '_skel_' + test.get_group_name() + '_' + test.get_type() )
template_line = template_line.replace ('$$ITERATIONS$$', test.get_iterations() )
template_line = template_line.replace ('$$METHOD_PARAMS$$', test.get_method_params() )
template_line = template_line.replace ('$$EXT$$', test.get_ext() )
if test.get_rm() == 'pre' or test.get_rm() == 'both':
prerm = 'rm -rf out*'
else:
prerm = ''
template_line = template_line.replace ('$$PRE_RM$$', prerm)
if test.get_rm() == 'post' or test.get_rm() == 'both':
postrm = 'rm -rf out*'
else:
postrm = ''
template_line = template_line.replace ('$$POST_RM$$', postrm)
if '$$CORES_TOTAL$$' in template_line:
pattern = re.compile (r"\$\$CORES_TOTAL\$\$[\d]*\$\$")
match = pattern.search (template_line)
match_term = match.group()
# If we split the matched string at the dollar signs, the cores/node will be
# at index 4
count = float(match_term.split('$')[4])
total_cores = int (math.ceil( (batch.get_cores() / count) ) * count)
template_line = template_line.replace (match_term, '%d'%total_cores)
if '$$NODES_TOTAL$$' in template_line:
pattern = re.compile (r"\$\$NODES_TOTAL\$\$[\d]*\$\$")
match = pattern.search (template_line)
match_term = match.group()
count = float(match_term.split('$')[4])
total_nodes = int (math.ceil( (batch.get_cores() / count) ) )
template_line = template_line.replace (match_term, '%d'%total_nodes)
return template_line
def generate_submit_scripts_from_yaml (args):
#print "Generating submission script using yaml file"
bpy = skel_bpy.skel_bpy (args.yamlfile)
outfilename = "submit.pbs"
template_file_name = "~/.skel/templates/submit_sith.tmpl"
# Only proceed if outfilename does not already exist, or if -f was used
if os.path.exists (outfilename) and not args.force:
print "%s exists, aborting. Delete the file or use -f to overwrite." % outfilename
return 999
skel_file = open (outfilename, 'w')
# Now for the Cheetah magic:
from Cheetah.Template import Template
template_file = open (os.path.expanduser(template_file_name), 'r')
t = Template(file=template_file)
settings = skel_settings.skel_settings()
t.bpy = bpy
t.project = args.project
t.target = settings.get_submit_target()
t.account = settings.get_account()
t.job_name = "skel_%s_%d" % (args.project, bpy.get_num_procs() )
t.walltime = "1:00:00"
t.iteration_count = 1
t.executable = "%s_skel_%s" % (t.project, bpy.get_group_name() )
skel_file.write (str(t) )
def generate_submit_scripts_with_args (parent_parser):
args = pparse_command_line (parent_parser)
try:
config = adios.adiosConfig (args.project + '_skel.xml')
except (IOError):
print "XXError reading " + args.project + "_skel.xml. Try running skel xml " + args.project + " first."
return 1
if args.yamlfile is not None:
generate_submit_scripts_from_yaml(args)
else:
try:
params = skelconf.skelConfig (args.project + '_params.xml')
except (IOError):
print "Error reading " + args.project + "_params.xml. Try running skel params " + args.project + " first,"
print "then check that " + args.project + "_params.xml exists."
return 1
generate_submit_scripts_from_xml (params)
def pparse_command_line (parent_parser):
parser = argparse.ArgumentParser (
parents = [parent_parser],
formatter_class=argparse.RawDescriptionHelpFormatter,
prog='skel',
#add_help=False,
description='''\
skel source
create source code to access the I/O pattern for the target skeletal application''')
parser.add_argument ('project', metavar='project', help='Name of the skel project')
parser.add_argument ('-y', '--yaml-file', dest='yamlfile', help='yaml file to use for I/O pattern')
parser.add_argument ('-f', '--force', dest='force', action='store_true', help='overwrite existing source file')
parser.set_defaults(force=False)
return parser.parse_args()
def parse_command_line():
parser = argparse.ArgumentParser (description='Create submission scripts for the given skel project')
parser.add_argument ('project', metavar='project', help='Name of the skel project')
return parser.parse_args()
def main(argv=None):
skel_settings.create_settings_dir_if_needed()
args = parse_command_line()
config = adios.adiosConfig (args.project + '_skel.xml')
params = skelconf.skelConfig (args.project + '_params.xml')
#generate_makefiles_c (params)
generate_submit_scripts_from_xml (params)
if __name__ == "__main__":
main()
|