8 from optparse
import OptionParser
16 def checkexist (path) :
17 if not os.path.exists(path) :
18 print 'Error: file or dir "%s" is not exist.' % path
25 def checkdir (path, force) :
26 if os.path.exists(path) :
27 if not os.path.isdir(path) :
28 print 'Error: "%s" is not directory.' % path
35 print 'Error: could not create "%s".' % path
38 print 'Error: directory "%s" is not exist. create it or use -f option.' % path
53 def k_scheduler(node, infile, outfile, indir, outdir, rsctime, mapper, reducer, multi, scrfile) :
59 template = open(
'kmrgenscript.template').read()
64 dir0 = os.path.dirname(os.path.realpath(__file__))
65 dir1 = os.path.realpath(dir0 +
'/../lib')
71 dir2 = os.path.realpath(kmrhome +
'/lib')
72 template = open(dir2 +
'/kmrgenscript.template').read()
76 print 'Error: could not open job-script template.' 80 ncol = len(str(node -1))
84 stginstr +=
'#PJM --stgin "rank=* %s %%r:./"' \
85 % (
'./' + os.path.basename(reducer))
87 files = os.listdir(indir)
90 ipath = os.path.join(indir, file)
93 stginstr +=
'#PJM --stgin "rank=%s %s %%r:./work/"' % (rank, ipath)
100 ipath = os.path.join(indir, infile)
101 stginstr +=
'#PJM --stgin "rank=* %s%%0%sr %%r:./input"' % (ipath, ncol)
104 opath = os.path.join(outdir, outfile)
105 stgoutstr =
'#PJM --stgout "rank=* %%r:./output.%%r %s.%%0%sr"' % (opath, ncol)
110 execstr =
'mpiexec -n %s -of-proc output ./kmrshell -m %s ./input'\
111 % (node,
'./' + os.path.basename(mapper))
113 execstr =
'mpiexec -n %s -of-proc output ./kmrshell -m %s -r %s ./input'\
114 % (node,
'./' + os.path.basename(mapper),
'./' + os.path.basename(reducer))
117 execstr =
'mpiexec -n %s -of-proc output ./kmrshell -m %s ./work'\
118 % (node,
'./' + os.path.basename(mapper))
120 execstr =
'mpiexec -n %s -of-proc output ./kmrshell -m %s -r %s ./work'\
121 % (node,
'./' + os.path.basename(mapper),
'./' + os.path.basename(reducer))
125 script = template % {
'NODE': node,
'RSCTIME': rsctime,
'MAPPER': mapper,
'DATASTGIN': stginstr,
'DATASTGOUT': stgoutstr,
'EXEC': execstr,
'KMRHOME': kmrhome}
131 out = open(scrfile,
"w")
148 def selectscheduler(node, infile, outfile, indir, outdir, rsctime, mapper, reducer, multi, sched, scrfile) :
150 k_scheduler(node, infile, outfile, indir, outdir, rsctime, mapper, reducer, multi, scrfile)
156 if __name__ ==
"__main__" :
158 usage =
"usage: %prog [options] -m mapper [-r reducer]" 159 parser = OptionParser(usage)
161 parser.add_option(
"-e",
162 "--number-of-exec-node",
165 help=
"number of execute node",
169 parser.add_option(
"-p",
170 "--input-file-prefix",
173 help=
"input filename prefix",
177 parser.add_option(
"-o",
181 help=
"output filename prefix",
185 parser.add_option(
"-d",
189 help=
"input directory",
193 parser.add_option(
"-O",
197 help=
"output directory",
201 parser.add_option(
"-t",
205 help=
"resource time",
209 parser.add_option(
"-m",
216 parser.add_option(
"-r",
223 parser.add_option(
"-S",
227 help=
"scheduler (default is 'K')",
231 parser.add_option(
"-w",
232 "--write-scriptfile",
235 help=
"script filename",
238 parser.add_option(
"-M",
242 help=
"multi input files to one node",
245 parser.add_option(
"-f",
252 (options, args) = parser.parse_args()
257 parser.error(
"missing parameter")
260 if not options.mapper :
261 print "mapper not specified\n" 264 checkexist(options.indir)
265 checkdir(options.outdir, options.force)
268 if options.indir ==
"./" :
269 print "-M option needs -d (input directory) option.\n" 271 files = os.listdir(options.indir)
272 if len(files) < options.node :
273 print 'Node number is greater than number of files in %s.\n' % options.indir
276 selectscheduler(options.node, options.infile, options.outfile,
277 options.indir, options.outdir, options.rsctime,
278 options.mapper, options.reducer, options.multi,
279 options.sched, options.scrfile)