Commit 0b0f724f authored by Melesse Vergara, Veronica's avatar Melesse Vergara, Veronica
Browse files

updated HelloWorld to harness v1.0

parent d1d75450
......@@ -4,17 +4,17 @@ import os
import getopt
import sys
import re
#import popen2
import time
import subprocess
import shlex
from machine_types.machine_factory import MachineFactory
#
# Author: Arnold Tharrington
# Email: arnoldt@ornl.gov
# National Center for Computational Sciences, Scientific Computing Group.
#
# Modified by: Veronica G. Vergara Larrea
# National Center for Computational Sciences, User Assistance Group.
def main():
......@@ -57,18 +57,14 @@ def main():
#
# Make the batch script.
#
mymachine = MachineFactory.create_machine()
# try-catch around this to alert the user something was missing
mymachine.make_batch_script()
batchfilename = make_batch_script(batch_recursive_mode,path_to_workspace,test_id_string,mymachine)
scheduler = "lsf"
batchfilename = make_batch_script(batch_recursive_mode,path_to_workspace,test_id_string,scheduler)
#
# Submit the batch file to the scheduler.
#
sched_job_id = send_to_scheduler(batchfilename,mymachine.get_scheduler_type())
print("Job id =" + str(sched_job_id))
sched_job_id = send_to_scheduler(batchfilename,scheduler)
print ("Job id =" + str(sched_job_id))
#
......@@ -77,20 +73,20 @@ def main():
write_job_id_to_status(sched_job_id,test_id_string)
def make_batch_script(batch_recursive_mode,path_to_workspace,test_id_string,mymachine):
def make_batch_script(batch_recursive_mode,path_to_workspace,test_id_string,scheduler):
#
# Define the batch file names.
#
if mymachine.get_scheduler_type() == "PBS":
print("Using PBS scheduler syntax to build the job submission file")
if scheduler == "pbs":
print "Using PBS scheduler syntax"
batchtemplatefilename = "pbs.template.x"
sched_id = 0
elif mymachine.get_scheduler_type() == "LSF":
print("Using LSF scheduler syntax to build the job submission file")
elif scheduler == "lsf":
print "Using LSF scheduler syntax"
batchtemplatefilename = "lsf.template.x"
sched_id = 1
else:
print("Scheduler " + mymachine.get_scheduler_type() + " is not supported")
print "Scheduler " + scheduler + " is not supported"
sched_id = -1
batchfilename = "run_helloWorld.sh"
......@@ -113,18 +109,15 @@ def make_batch_script(batch_recursive_mode,path_to_workspace,test_id_string,myma
resubmitme = batch_recursive_mode
if sched_id == 0:
print("Setting walltime to 5 minutes for PBS + aprun job")
walltime = "00:05:00"
joblaunchcommand = "aprun -n " + str(ranks) + " -N " + str(ppn) + " $EXECUTABLE 1> std.out.txt 2> std.err.txt"
elif sched_id == 1:
print("Setting walltime to 300 seconds for LSF + poe job")
walltime = "300"
joblaunchcommand = "poe $EXECUTABLE 1> std.out.txt 2> std.err.txt"
else:
print("Executing on current node")
print "Executing on current node"
joblaunchcommand = "$EXECUTABLE 1> std.out.txt 2> std.err.txt"
rg_array = [
(re.compile("__jobname__"),jobname),
(re.compile("__walltime__"),walltime),
......@@ -208,7 +201,7 @@ def write_job_id_to_status(sched_job_id,test_id_string):
return path1
def send_to_scheduler(batchfilename,scheduler_type):
def send_to_scheduler(batchfilename,scheduler):
t1="t1.out"
......@@ -217,33 +210,31 @@ def send_to_scheduler(batchfilename,scheduler_type):
my_stdout = open(t1,"w")
my_stderr = open(t2,"w")
if scheduler_type == "PBS":
print("Using PBS scheduler syntax to submit job")
if scheduler == "pbs":
print "Using PBS scheduler syntax to submit job"
sched_id = 0
elif scheduler_type == "LSF":
print("Using LSF scheduler syntax to submit job")
elif scheduler == "lsf":
print "Using LSF scheduler syntax to submit job"
sched_id = 1
else:
print("Scheduler " + scheduler_type + " is not supported")
print "Scheduler " + scheduler + " is not supported"
sched_id = -1
# Set the appropriate qcommand for each scheduler
if sched_id == 0:
submit_command = "qsub "
print("Submitting job using " + submit_command)
qcommand = submit_command + batchfilename
elif sched_id == 1:
submit_command = "bsub "
print("Submitting job using " + submit_command)
qcommand = submit_command
else:
print("Unsupported scheduler (sched_id = " + str(sched_id) + ")")
print "Unsupported scheduler (sched_id = " + str(sched_id) + ")"
# Split the arguments for the command
args = shlex.split(qcommand)
print("args = ")
print(args)
print "args = "
print args
# Execute the command as a subprocess
if sched_id == 0:
......@@ -253,7 +244,7 @@ def send_to_scheduler(batchfilename,scheduler_type):
p = subprocess.Popen(args,stdout=my_stdout,stderr=my_stderr,stdin=my_jobfile)
my_jobfile.close()
else:
print("Unsupported scheduler (sched_id = " + str(sched_id) + ")")
print "Unsupported scheduler (sched_id = " + str(sched_id) + ")"
p.wait()
......@@ -262,8 +253,8 @@ def send_to_scheduler(batchfilename,scheduler_type):
my_stdout = open(t1,"r")
records = my_stdout.readlines()
print("records = ")
print(records)
print "records = "
print records
jobid = extract_jobid(records,sched_id)
my_stdout.close()
......@@ -272,22 +263,21 @@ def send_to_scheduler(batchfilename,scheduler_type):
def extract_jobid(records,sched_id):
if sched_id == 0:
print("Extracting PBS jobID")
print "Extracting PBS jobID"
jobid = records[0].strip()
elif sched_id == 1:
print("Extracting LSF jobID")
print "Extracting LSF jobID"
m = re.compile('\d+')
print("m = ")
print(m)
print("m.findall = ")
print "m = "
print m
print "m.findall = "
jobid = m.findall(records[0])[0]
print(jobid)
print jobid
else:
print("Non-supported scheduler requested")
print "Non-supported scheduler requested"
return jobid
def usage():
print("Usage: submit_executable.x [-h|--help] -p <path_to_worspace> -i <test_id_string>")
print("")
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment