Skip to content

Commit

Permalink
Convenient job submition
Browse files Browse the repository at this point in the history
  • Loading branch information
SGo-Go committed Nov 13, 2013
1 parent 8de4cf3 commit 5de8eac
Show file tree
Hide file tree
Showing 8 changed files with 165 additions and 2 deletions.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,5 @@ clean:
allclean: clean
($(CD) $(TOP_DIR)/bench; $(MAKE) allclean)
$(RM) -R `find $(TOP_DIR) -name *~` $(TOP_DIR)/*.o
$(RM) -R `find $(TOP_DIR) -name *.pyc`
#$(RM) $(TOP_DIR)/config.mk
6 changes: 5 additions & 1 deletion autosetup
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,8 @@ TOP_DIR=`echo "${PWD}" | sed -e 's/\//@/g'`

cat ./config.mk.template | \
sed "s/@system@/${SYSTEM}/g;s/@top_dir@/${TOP_DIR}/g;s/@/\//g" \
> ./config.mk
> ./config.mk

cat ./bin/sys/submit.py.in | \
sed "s/@system@/${SYSTEM}/g;s/@top_dir@/${TOP_DIR}/g;s/@/\//g" \
> ./bin/sys/submit.py
24 changes: 24 additions & 0 deletions bin/sys/submit.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/usr/bin/python

# ------------------------------------------------------------------
# BSOF/I - Block structured factorization and inversion codes
# for CPU+GPU platforms
# Copyright (c) 2013, Sergiy Gogolenko
# e-mail: sgogolenko/ucdavis.edu
# ------------------------------------------------------------------
# Description:
# Script for submitting job
# ------------------------------------------------------------------

import os, sys
os.environ['BSOFI_TOPDIR'] = r"/home/sergiy/project/BSOFI"

sys.path.append(os.path.join(os.getenv('BSOFI_TOPDIR', '.'), 'python'))

from bench import BSOFIPerformanceModel, BenchReportTable
from platforms import user as platform
from platforms import Job
#Job, Platform, BashJobManager, PBSJobManager #zwolf as platform

manager = platform.job_manager
manager.submit(Job(" ".join(sys.argv[1:])))
24 changes: 24 additions & 0 deletions bin/sys/submit.py.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/usr/bin/python

# ------------------------------------------------------------------
# BSOF/I - Block structured factorization and inversion codes
# for CPU+GPU platforms
# Copyright (c) 2013, Sergiy Gogolenko
# e-mail: sgogolenko/ucdavis.edu
# ------------------------------------------------------------------
# Description:
# Script for submitting job
# ------------------------------------------------------------------

import os, sys
os.environ['BSOFI_TOPDIR'] = r"@top_dir@"

sys.path.append(os.path.join(os.getenv('BSOFI_TOPDIR', '.'), 'python'))

from bench import BSOFIPerformanceModel, BenchReportTable
from platforms import @system@ as platform
from platforms import Job
#Job, Platform, BashJobManager, PBSJobManager #zwolf as platform

manager = platform.job_manager
manager.submit(Job("ls -l"))
2 changes: 1 addition & 1 deletion python/__init__py → python/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@
# Python classes for data treatment and work of remote platforms.
# ------------------------------------------------------------------

__all__ = ['bench', ]
__all__ = ['platforms', 'bench']
21 changes: 21 additions & 0 deletions python/platforms/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/usr/bin/python

# ------------------------------------------------------------------
# BSOF/I - Block structured factorization and inversion codes
# for CPU+GPU platforms
# Copyright (c) 2013, Sergiy Gogolenko
# e-mail: [email protected]
# ------------------------------------------------------------------
# Description:
# Module for running jobs on different platforms.
# ------------------------------------------------------------------

__all__ = ['job', 'platform']

from job import Job, PBSJobManager, BashJobManager
from platform import Platform

user = Platform(BashJobManager())
zwolf = Platform(BashJobManager())
dirac_fermi = Platform(PBSJobManager(r'config/jobs/dirac_fermi.sh.in'))
dirac_tesla = Platform(PBSJobManager(r'config/jobs/dirac_tesla.sh.in'))
68 changes: 68 additions & 0 deletions python/platforms/job.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
#!/usr/bin/python

# ------------------------------------------------------------------
# BSOF/I - Block structured factorization and inversion codes
# for CPU+GPU platforms
# Copyright (c) 2013, Sergiy Gogolenko
# e-mail: [email protected]
# ------------------------------------------------------------------
# Description:
# Module for running jobs on different platforms.
# ------------------------------------------------------------------

class Job(object):
def __init__(self, cmd, **kw):
super(Job, self).__init__()
self.cmd = cmd
self.attrs = kw
pass

def __getitem__(self, k):
if k in self.attrs.keys():
return self.attrs[k]
return super(Job, self).__getitem__(k)

class JobManager(object):
def __init__(self):
super(JobManager, self).__init__()
pass

def submit(self, job):
pass

class PBSJobManager(JobManager):
def __init__(self, job_template):
super(PBSJobManager, self).__init__()
self.job_template = job_template
pass

def submit(self, job):
from popen2 import popen2
import time
output, input = popen2('qsub -S /bin/bash')
job_template_handle = open(job_template, "r")
job_script = job_template_handle.read()
job_template_handle.close()
job_script = job_script.replace(r"@cmd@", job.cmd)
input.write(job_string)
input.close()
print "Job is submited: [%s]" % output.read()
time.sleep(0.1)
pass

class BashJobManager(JobManager):
def __init__(self, cmd_submit = 'nohup'):
super(BashJobManager, self).__init__()
self.cmd_submit = cmd_submit
pass

def submit(self, job):
from popen2 import popen2
import time
output, input = popen2(r'%s %s &'% (self.cmd_submit, job.cmd))
#import os
#os.system(r'%s %s &'% (self.cmd_submit, job.cmd))
print "Job is submited: [%s]" % output.read()
time.sleep(0.1)
pass

21 changes: 21 additions & 0 deletions python/platforms/platform.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/usr/bin/python

# ------------------------------------------------------------------
# BSOF/I - Block structured factorization and inversion codes
# for CPU+GPU platforms
# Copyright (c) 2013, Sergiy Gogolenko
# e-mail: [email protected]
# ------------------------------------------------------------------
# Description:
# Module for running jobs on different platforms.
# ------------------------------------------------------------------

from job import Job, PBSJobManager, BashJobManager


class Platform(object):
def __init__(self, job_manager, **kw):
super(Platform, self).__init__()
self.job_manager = job_manager
self.attrs = kw
pass

0 comments on commit 5de8eac

Please sign in to comment.