[cig-commits] r11795 - in cs/pythia/trunk/pyre/schedulers: . scripts scripts/sge

leif at geodynamics.org leif at geodynamics.org
Thu Apr 10 15:28:13 PDT 2008


Author: leif
Date: 2008-04-10 15:28:13 -0700 (Thu, 10 Apr 2008)
New Revision: 11795

Added:
   cs/pythia/trunk/pyre/schedulers/SchedulerSGE.py
   cs/pythia/trunk/pyre/schedulers/scripts/sge/
   cs/pythia/trunk/pyre/schedulers/scripts/sge/__vault__.odb
   cs/pythia/trunk/pyre/schedulers/scripts/sge/batch.sh.tmpl
   cs/pythia/trunk/pyre/schedulers/sge.odb
Log:
Issue117:  SGE support.


Added: cs/pythia/trunk/pyre/schedulers/SchedulerSGE.py
===================================================================
--- cs/pythia/trunk/pyre/schedulers/SchedulerSGE.py	                        (rev 0)
+++ cs/pythia/trunk/pyre/schedulers/SchedulerSGE.py	2008-04-10 22:28:13 UTC (rev 11795)
@@ -0,0 +1,91 @@
+#!/usr/bin/env python
+#
+# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+#
+#                      California Institute of Technology
+#                        (C) 2008  All Rights Reserved
+#
+# {LicenseText}
+#
+# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+#
+
+
+from BatchScheduler import BatchScheduler
+import os, sys
+
+
+class SchedulerSGE(BatchScheduler):
+    
+    
+    name = "sge"
+    
+
+    import pyre.inventory as pyre
+    
+    command      = pyre.str("command", default="qsub")
+    peName       = pyre.str("pe-name", default="mpi")
+    peNumber     = pyre.str("pe-number", default="n")
+    qsubOptions  = pyre.list("qsub-options")
+    
+    
+    def schedule(self, job):
+        import pyre.util as util
+
+        # Fix-up the job.
+        if not job.task:
+            job.task = "jobname"
+        job.walltime = util.hms(job.dwalltime.value)
+        job.arguments = ' '.join(job.arguments)
+        
+        # Generate the main SGE batch script.
+        script = self.retrieveTemplate('batch.sh', ['schedulers', 'scripts', 'sge'])
+        script.scheduler = self
+        script.job = job
+        
+        if self.dry:
+            print script
+            return
+
+        try:
+            import os, tempfile
+
+            filename = tempfile.mktemp()
+            s = open(filename, 'w')
+            print >>s, script
+            s.close()
+
+            cmd = [self.command, filename]
+            self._info.log("spawning: %s" % ' '.join(cmd))
+            status = os.spawnvp(os.P_WAIT, cmd[0], cmd)
+
+            os.remove(filename)
+
+            exitStatus = None
+            if (os.WIFSIGNALED(status)):
+                statusStr = "signal %d" % os.WTERMSIG(status)
+            elif (os.WIFEXITED(status)):
+                exitStatus = os.WEXITSTATUS(status)
+                statusStr = "exit %d" % exitStatus
+            else:
+                statusStr = "status %d" % status
+            self._info.log("%s: %s" % (cmd[0], statusStr))
+        
+        except IOError, e:
+            self._error.log("%s: %s" % (self.command, e))
+            return
+        
+        if exitStatus == 0:
+            pass
+        else:
+            sys.exit("%s: %s: %s" % (sys.argv[0], cmd[0], statusStr))
+        
+        return
+
+
+    def jobId(cls):
+        return os.environ['JOB_ID']
+    jobId = classmethod(jobId)
+
+
+# end of file 

Added: cs/pythia/trunk/pyre/schedulers/scripts/sge/__vault__.odb
===================================================================
--- cs/pythia/trunk/pyre/schedulers/scripts/sge/__vault__.odb	                        (rev 0)
+++ cs/pythia/trunk/pyre/schedulers/scripts/sge/__vault__.odb	2008-04-10 22:28:13 UTC (rev 11795)
@@ -0,0 +1,13 @@
+#!/usr/bin/env python
+#
+# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+#
+#                      California Institute of Technology
+#                        (C) 2006  All Rights Reserved
+#
+# {LicenseText}
+#
+# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+#
+
+# end of file

Added: cs/pythia/trunk/pyre/schedulers/scripts/sge/batch.sh.tmpl
===================================================================
--- cs/pythia/trunk/pyre/schedulers/scripts/sge/batch.sh.tmpl	                        (rev 0)
+++ cs/pythia/trunk/pyre/schedulers/scripts/sge/batch.sh.tmpl	2008-04-10 22:28:13 UTC (rev 11795)
@@ -0,0 +1,41 @@
+## -*- sh -*-
+#compiler-settings
+directiveStartToken = @
+#end compiler-settings
+ at from pyre.schedulers import BatchScriptTemplate
+ at extends BatchScriptTemplate
+ at implements respond
+ at set $self.substitutions = {'job.id': "$JOB_ID"}
+#$ -S ${scheduler.shell}
+#$ -cwd
+#$ -N ${job.task}
+ at if $job.queue
+#$ -q ${job.queue}
+ at end if
+ at if max($job.walltime)
+#$ -l h_rt=@echo ("%d:%02d:%02d" % $job.walltime[0:3])
+ at end if
+#$ -pe $scheduler.peName @echo eval($scheduler.peNumber, dict(n = $job.nodes))
+ at if $self.stdout
+#$ -o ${self.stdout}
+ at end if
+ at if $self.stderr
+#$ -e ${self.stderr}
+ at end if
+ at for option in $scheduler.qsubOptions
+#$ ${option}
+ at end for
+
+ at set $self.substitutions = {'job.id': "${JOB_ID}"}
+
+${job.executable} @echo ' '.join($job.arguments)
+
+ at if $job.comments
+# ~~~~ comments ~~~~
+ at for line in $job.comments
+# ${line}
+ at end for
+ at end if
+
+# ~~~~ submit command ~~~~
+# ${scheduler.command} < [script]

Added: cs/pythia/trunk/pyre/schedulers/sge.odb
===================================================================
--- cs/pythia/trunk/pyre/schedulers/sge.odb	                        (rev 0)
+++ cs/pythia/trunk/pyre/schedulers/sge.odb	2008-04-10 22:28:13 UTC (rev 11795)
@@ -0,0 +1,19 @@
+#!/usr/bin/env python
+#
+# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+#
+#                      California Institute of Technology
+#                        (C) 2006  All Rights Reserved
+#
+# {LicenseText}
+#
+# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+#
+
+
+def scheduler():
+    from pyre.schedulers.SchedulerSGE import SchedulerSGE
+    return SchedulerSGE()
+
+
+# end of file



More information about the cig-commits mailing list