[cig-commits] r5571 - in cs/pythia/trunk: mpi pyre/odb/fs pyre/schedulers pyre/schedulers/scripts pyre/schedulers/scripts/lsf pyre/schedulers/scripts/pbs

leif at geodynamics.org leif at geodynamics.org
Fri Dec 8 16:41:17 PST 2006


Author: leif
Date: 2006-12-08 16:41:16 -0800 (Fri, 08 Dec 2006)
New Revision: 5571

Added:
   cs/pythia/trunk/pyre/schedulers/SchedulerPBS.py
   cs/pythia/trunk/pyre/schedulers/pbs.odb
   cs/pythia/trunk/pyre/schedulers/scripts/pbs/
   cs/pythia/trunk/pyre/schedulers/scripts/pbs/__vault__.odb
   cs/pythia/trunk/pyre/schedulers/scripts/pbs/batch.sh.tmpl
Modified:
   cs/pythia/trunk/mpi/Launcher.py
   cs/pythia/trunk/pyre/odb/fs/CodecODB.py
   cs/pythia/trunk/pyre/schedulers/SchedulerLSF.py
   cs/pythia/trunk/pyre/schedulers/scripts/lsf/batch.sh.tmpl
Log:
Added support for PBS.  This included adding 'os.environ' to the MPI
launcher macro substitutions, so that one can reference PBS_NODEFILE
as follows:

    [CitcomS.launcher]
    command = mpirun -np ${nodes} -machinefile ${PBS_NODEFILE}

Nuked all references to FileLocking (actually there was only one, in
CodecODB).  This is the annoying code that prevented Pyre from working
on NFS-mounted filesystems (!).  The locking seems to serve no
purpose, anyway.

Renamed 'scheduler.batch-command' to simply 'scheduler.command'.  The
'batch-' was an anachonism: it was to avoid a name conflict with the
'command' property used for 'mpirun', back when Launcher and Scheduler
were the same thing.


Modified: cs/pythia/trunk/mpi/Launcher.py
===================================================================
--- cs/pythia/trunk/mpi/Launcher.py	2006-12-09 00:35:19 UTC (rev 5570)
+++ cs/pythia/trunk/mpi/Launcher.py	2006-12-09 00:41:16 UTC (rev 5571)
@@ -69,8 +69,11 @@
         # 'ibrun' (the number of nodes is not given).
         
         from pyre.util import expandMacros
+        from os import environ
         args = self.command.split(' ')
-        substitutions = {'nodes': '%d' % self.nodes }
+        substitutions = dict()
+        substitutions.update(environ) # to allow, for example, ${PBS_NODEFILE}
+        substitutions['nodes'] =  '%d' % self.nodes
         args = [expandMacros(arg, substitutions) for arg in args]
         
         # use only the specific nodes specified explicitly

Modified: cs/pythia/trunk/pyre/odb/fs/CodecODB.py
===================================================================
--- cs/pythia/trunk/pyre/odb/fs/CodecODB.py	2006-12-09 00:35:19 UTC (rev 5570)
+++ cs/pythia/trunk/pyre/odb/fs/CodecODB.py	2006-12-09 00:41:16 UTC (rev 5571)
@@ -53,9 +53,6 @@
         # public data
         self.renderer = self._createRenderer()
 
-        # private data
-        self._locker = self._createLocker()
-        
         return
 
 
@@ -71,9 +68,7 @@
 
         stream = file(shelf.name)
 
-        self._locker.lock(stream, self._locker.LOCK_EX)
         exec stream in shelf
-        self._locker.unlock(stream)
 
         return
 
@@ -85,11 +80,6 @@
         weaver = Weaver()
         return weaver
 
-
-    def _createLocker(self):
-        from FileLocking import FileLocking
-        return FileLocking()
-
         
 # version
 __id__ = "$Id: CodecODB.py,v 1.1.1.1 2005/03/08 16:13:41 aivazis Exp $"

Modified: cs/pythia/trunk/pyre/schedulers/SchedulerLSF.py
===================================================================
--- cs/pythia/trunk/pyre/schedulers/SchedulerLSF.py	2006-12-09 00:35:19 UTC (rev 5570)
+++ cs/pythia/trunk/pyre/schedulers/SchedulerLSF.py	2006-12-09 00:41:16 UTC (rev 5571)
@@ -22,9 +22,8 @@
 
     import pyre.inventory as pyre
     
-    command         = pyre.str("command", default="mpijob mpirun")
-    batchCommand    = pyre.str("batch-command", default="bsub")
-    bsubOptions     = pyre.list("bsub-options")
+    command      = pyre.str("command", default="bsub")
+    bsubOptions  = pyre.list("bsub-options")
     
     
     def schedule(self, job):
@@ -53,7 +52,7 @@
             import os
             from popen2 import Popen4
 
-            cmd = [self.batchCommand]
+            cmd = [self.command]
             if self.wait:
                 cmd.append("-K")
             self._info.log("spawning: %s" % ' '.join(cmd))
@@ -82,7 +81,7 @@
             self._info.log("%s: %s" % (cmd[0], statusStr))
         
         except IOError, e:
-            self._error.log("%s: %s" % (self.batchCommand, e))
+            self._error.log("%s: %s" % (self.command, e))
             return
         
         # "[When given the -K option], bsub will exit with the same

Added: cs/pythia/trunk/pyre/schedulers/SchedulerPBS.py
===================================================================
--- cs/pythia/trunk/pyre/schedulers/SchedulerPBS.py	2006-12-09 00:35:19 UTC (rev 5570)
+++ cs/pythia/trunk/pyre/schedulers/SchedulerPBS.py	2006-12-09 00:41:16 UTC (rev 5571)
@@ -0,0 +1,108 @@
+#!/usr/bin/env python
+#
+# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+#
+#                      California Institute of Technology
+#                        (C) 2006  All Rights Reserved
+#
+# {LicenseText}
+#
+# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+#
+
+
+from BatchScheduler import BatchScheduler
+
+
+class SchedulerPBS(BatchScheduler):
+    
+    
+    name = "pbs"
+    
+
+    import pyre.inventory as pyre
+    
+    command      = pyre.str("command", default="qsub")
+    qsubOptions  = pyre.list("qsub-options")
+    ppn          = pyre.int("ppn", default=1)
+    
+    
+    def schedule(self, job):
+        import os, sys
+        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)
+        job.resourceList = self.buildResourceList(job)
+        
+        # Generate the main PBS batch script.
+        script = self.retrieveTemplate('batch.sh', ['schedulers', 'scripts', 'pbs'])
+        script.scheduler = self
+        script.job = job
+        
+        if self.dry:
+            print script
+            return
+
+        try:
+            import os
+            from popen2 import Popen4
+
+            cmd = [self.command]
+            self._info.log("spawning: %s" % ' '.join(cmd))
+            child = Popen4(cmd)
+            self._info.log("spawned process %d" % child.pid)
+
+            print >> child.tochild, script
+            child.tochild.close()
+
+            for line in child.fromchild:
+                self._info.line("    " + line.rstrip())
+            status = child.wait()
+            self._info.log()
+
+            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 buildResourceList(self, job):
+
+        resourceList = []
+        if self.ppn:
+            resourceList.append(
+                "nodes=%d:ppn=%d" % ((job.nodes / self.ppn) + (job.nodes % self.ppn and 1 or 0), self.ppn)
+                )
+        else:
+            resourceList.append(
+                "nodes=%d" % job.nodes
+                )
+
+        walltime = job.walltime
+        if max(walltime):
+            resourceList.append("walltime=%d:%02d:%02d" % walltime)
+
+        return resourceList
+
+
+# end of file 

Added: cs/pythia/trunk/pyre/schedulers/pbs.odb
===================================================================
--- cs/pythia/trunk/pyre/schedulers/pbs.odb	2006-12-09 00:35:19 UTC (rev 5570)
+++ cs/pythia/trunk/pyre/schedulers/pbs.odb	2006-12-09 00:41:16 UTC (rev 5571)
@@ -0,0 +1,19 @@
+#!/usr/bin/env python
+#
+# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+#
+#                      California Institute of Technology
+#                        (C) 2006  All Rights Reserved
+#
+# {LicenseText}
+#
+# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+#
+
+
+def scheduler():
+    from pyre.schedulers.SchedulerPBS import SchedulerPBS
+    return SchedulerPBS()
+
+
+# end of file

Modified: cs/pythia/trunk/pyre/schedulers/scripts/lsf/batch.sh.tmpl
===================================================================
--- cs/pythia/trunk/pyre/schedulers/scripts/lsf/batch.sh.tmpl	2006-12-09 00:35:19 UTC (rev 5570)
+++ cs/pythia/trunk/pyre/schedulers/scripts/lsf/batch.sh.tmpl	2006-12-09 00:41:16 UTC (rev 5571)
@@ -49,4 +49,4 @@
 @end if
 
 # ~~~~ submit command ~~~~
-# ${scheduler.batchCommand} < [script]
+# ${scheduler.command} < [script]

Added: cs/pythia/trunk/pyre/schedulers/scripts/pbs/__vault__.odb
===================================================================
--- cs/pythia/trunk/pyre/schedulers/scripts/pbs/__vault__.odb	2006-12-09 00:35:19 UTC (rev 5570)
+++ cs/pythia/trunk/pyre/schedulers/scripts/pbs/__vault__.odb	2006-12-09 00:41:16 UTC (rev 5571)
@@ -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/pbs/batch.sh.tmpl
===================================================================
--- cs/pythia/trunk/pyre/schedulers/scripts/pbs/batch.sh.tmpl	2006-12-09 00:35:19 UTC (rev 5570)
+++ cs/pythia/trunk/pyre/schedulers/scripts/pbs/batch.sh.tmpl	2006-12-09 00:41:16 UTC (rev 5571)
@@ -0,0 +1,39 @@
+## -*- 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': "${PBS_JOBID}"}
+#!${scheduler.shell}
+#PBS -S ${scheduler.shell}
+#PBS -N ${job.task}
+ at if $job.queue
+#PBS -q ${job.queue}
+ at end if
+ at if $self.stdout
+#PBS -o ${self.stdout}
+ at end if
+ at if $self.stderr
+#PBS -e ${self.stderr}
+ at end if
+ at if $job.resourceList
+#PBS -l @echo ','.join($job.resourceList)
+ at end if
+ at for option in $scheduler.qsubOptions
+#PBS ${option}
+ at end for
+
+cd \$PBS_O_WORKDIR
+${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]



More information about the cig-commits mailing list