[cig-commits] r5746 - in short/3D/PyLith/branches/pylith-0.8/pylith3d: . applications pylith3d

leif at geodynamics.org leif at geodynamics.org
Tue Jan 9 16:45:35 PST 2007


Author: leif
Date: 2007-01-09 16:45:35 -0800 (Tue, 09 Jan 2007)
New Revision: 5746

Modified:
   short/3D/PyLith/branches/pylith-0.8/pylith3d/Makefile.am
   short/3D/PyLith/branches/pylith-0.8/pylith3d/applications/pylith3dapp.py
   short/3D/PyLith/branches/pylith-0.8/pylith3d/pylith3d/Application.py
   short/3D/PyLith/branches/pylith-0.8/pylith3d/pypylith3d.cc
Log:
Use CIG-Pythia's 'launcher' and 'scheduler' facilities.  Users no
longer execute 'mpirun'.  Instead, they execute 'pylith3dapp.py'
directly, and the framework re-executes PyLith under 'mpirun'
automatically.  On a cluster with a scheduler (PBS, LSF, ...) the
framework automatically generates a batch script and submits a job to
the queue.  One uses "--launcher.nodes=XXX" to specify the number of
processors.

Currently, the framework defaults to MPICH1 with no scheduler; using
PBS, LSF, MPICH2, LAM/MPI, etc. may require additional configuration,
which is beyond the scope of this log comment.

This change breaks the "--disable-embedding" configuration.  I will
revisit this later.


Modified: short/3D/PyLith/branches/pylith-0.8/pylith3d/Makefile.am
===================================================================
--- short/3D/PyLith/branches/pylith-0.8/pylith3d/Makefile.am	2007-01-09 22:20:08 UTC (rev 5745)
+++ short/3D/PyLith/branches/pylith-0.8/pylith3d/Makefile.am	2007-01-10 00:45:35 UTC (rev 5746)
@@ -8,7 +8,7 @@
 
 bin_PROGRAMS = 
 if COND_EMBEDDING
-    bin_PROGRAMS += pypylith3d
+    bin_PROGRAMS += pypylith3d mpipypylith3d
     INTERPRETER = $(bindir)/pypylith3d
     noinstINTERPRETER = $(abs_builddir)/pypylith3d
     noinstPYTHONPATH = $(abs_top_builddir)/python
@@ -38,7 +38,7 @@
 	pylith3d/PetscUtil.py
 
 # pypylith3d (libpylith3d + pylith3dmodule + embedded Python interpreter)
-INCLUDES = -I$(top_srcdir)/pylith3d/module -I$(PYTHON_INCDIR)
+INCLUDES = -I$(top_srcdir)/pylith3d/module $(PYTHON_EGG_CPPFLAGS) -I$(PYTHON_INCDIR)
 pypylith3d_SOURCES = pypylith3d.cc
 pypylith3d_LDADD = \
 	$(top_builddir)/pylith3d/module/libpylith3dmodule.a \
@@ -55,6 +55,23 @@
 		$(PYTHON_LIBS) $(PYTHON_MODLIBS) $(PYTHON_SYSLIBS) \
 		$(LIBS) \
 		$(PYTHON_LDLAST)
+mpipypylith3d_SOURCES = pypylith3d.cc
+mpipypylith3d_CXXFLAGS = -DUSE_MPI
+mpipypylith3d_LDADD = \
+	$(top_builddir)/pylith3d/module/libpylith3dmodule.a \
+	$(top_builddir)/pylith3d/libpylith3d/libpylith3d.a
+mpipypylith3d$(EXEEXT): $(mpipypylith3d_OBJECTS) $(mpipypylith3d_DEPENDENCIES) 
+	@rm -f mpipypylith3d$(EXEEXT)
+	$(CXXLINK) $(PYTHON_LDFLAGS) $(PYTHON_LINKFORSHARED) \
+		$(mpipypylith3d_LDFLAGS) $(mpipypylith3d_OBJECTS) $(mpipypylith3d_LDADD) \
+		$(PYTHON_BLDLIBRARY) \
+		$(PYTHON_EGG_LDFLAGS) \
+		$(PETSC_FORTRAN_LIB) $(PETSC_LIB) \
+		$(MPILIBS) \
+		$(FCLIBS) \
+		$(PYTHON_LIBS) $(PYTHON_MODLIBS) $(PYTHON_SYSLIBS) \
+		$(LIBS) \
+		$(PYTHON_LDLAST)
 
 # applications
 bin_SCRIPTS = pylith3dapp.py

Modified: short/3D/PyLith/branches/pylith-0.8/pylith3d/applications/pylith3dapp.py
===================================================================
--- short/3D/PyLith/branches/pylith-0.8/pylith3d/applications/pylith3dapp.py	2007-01-09 22:20:08 UTC (rev 5745)
+++ short/3D/PyLith/branches/pylith-0.8/pylith3d/applications/pylith3dapp.py	2007-01-10 00:45:35 UTC (rev 5746)
@@ -47,14 +47,6 @@
             sys.path.insert(1, directory)
             site.addsitedir(directory)
 
-    # if we are embedding, insert the extension module in the
-    # 'pylith3d' package
-    try:
-        import builtin_pylith3d
-        sys.modules['pylith3d.pylith3d'] = builtin_pylith3d
-    except ImportError:
-        pass
-    
     from pylith3d.Application import Application
     from pyre.applications import start
     start(applicationClass=Application)

Modified: short/3D/PyLith/branches/pylith-0.8/pylith3d/pylith3d/Application.py
===================================================================
--- short/3D/PyLith/branches/pylith-0.8/pylith3d/pylith3d/Application.py	2007-01-09 22:20:08 UTC (rev 5745)
+++ short/3D/PyLith/branches/pylith-0.8/pylith3d/pylith3d/Application.py	2007-01-10 00:45:35 UTC (rev 5746)
@@ -29,13 +29,23 @@
 #
 
 
-from pyre.applications.Script import Script as BaseScript
+from mpi.Application import Application as BaseApplication
 
 
-class Application(BaseScript):
+class Application(BaseApplication):
 
 
     def main(self, *args, **kwds):
+        import sys
+        
+        # if we are embedding, insert the extension module in the
+        # 'pylith3d' package
+        try:
+            import builtin_pylith3d
+            sys.modules['pylith3d.pylith3d'] = builtin_pylith3d
+        except ImportError:
+            pass
+    
 #        from time import clock as now
 #        start = now()
         pl3dsetup = self.inventory.setup
@@ -45,7 +55,6 @@
         try:
             pl3dsetup.initialize(self.inventory.scanner)
         except self.inventory.scanner.CanNotOpenInputOutputFilesError, error:
-            import sys
             print >> sys.stderr
             error.report(sys.stderr)
             print >> sys.stderr
@@ -70,7 +79,7 @@
 
 
     def __init__(self, name="pylith3d"):
-        BaseScript.__init__(self, name)
+        BaseApplication.__init__(self, name)
         return
 
 
@@ -110,7 +119,7 @@
         return PetscCommandlineParser()
 
 
-    class Inventory(BaseScript.Inventory):
+    class Inventory(BaseApplication.Inventory):
 
         import pyre.inventory
         from Pylith3d_scan import Pylith3d_scan

Modified: short/3D/PyLith/branches/pylith-0.8/pylith3d/pypylith3d.cc
===================================================================
--- short/3D/PyLith/branches/pylith-0.8/pylith3d/pypylith3d.cc	2007-01-09 22:20:08 UTC (rev 5745)
+++ short/3D/PyLith/branches/pylith-0.8/pylith3d/pypylith3d.cc	2007-01-10 00:45:35 UTC (rev 5746)
@@ -32,6 +32,23 @@
 #include <stdio.h>
 #include "pylith3dmodule.h"
 
+#define MPICH_IGNORE_CXX_SEEK
+
+#define COMMAND \
+"import sys; " \
+"path = sys.argv[1]; " \
+"requires = sys.argv[2]; " \
+"entry = sys.argv[3]; " \
+"path = path.split(':'); " \
+"path.extend(sys.path); " \
+"sys.path = path; " \
+"from merlin import loadObject; " \
+"entry = loadObject(entry); " \
+"entry(sys.argv[3:], kwds={'requires': requires})"
+
+/* include the implementation of _mpi */
+#include "mpi/_mpi.c"
+
 static void init_builtin_pylith3d()
 {
     pypylith3d_init("builtin_pylith3d");
@@ -39,18 +56,54 @@
 }
 
 struct _inittab inittab[] = {
+    { "_mpi", init_mpi },
     { "builtin_pylith3d", init_builtin_pylith3d },
     { 0, 0 }
 };
 
 int main(int argc, char **argv)
 {
+    int status;
+    
+#ifdef USE_MPI
+    /* initialize MPI */
+    if (MPI_Init(&argc, &argv) != MPI_SUCCESS) {
+        fprintf(stderr, "%s: MPI_Init failed! Exiting ...", argv[0]);
+        return 1;
+    }
+#endif
+    
     /* add our extension module */
     if (PyImport_ExtendInittab(inittab) == -1) {
         fprintf(stderr, "%s: PyImport_ExtendInittab failed! Exiting...\n", argv[0]);
         return 1;
     }
-    return Py_Main(argc, argv);
+    
+    if (argc < 3 || strcmp(argv[1], "--pyre-start") != 0) {
+        return Py_Main(argc, argv);
+    }
+    
+    /* make sure 'sys.executable' is set to the path of this program  */
+    Py_SetProgramName(argv[0]);
+    
+    /* initialize Python */
+    Py_Initialize();
+    
+    /* initialize sys.argv */
+    PySys_SetArgv(argc - 1, argv + 1);
+    
+    /* run the Python command */
+    status = PyRun_SimpleString(COMMAND) != 0;
+    
+    /* shut down Python */
+    Py_Finalize();
+    
+#ifdef USE_MPI
+    /* shut down MPI */
+    MPI_Finalize();
+#endif
+    
+    return status;
 }
 
 // End of file



More information about the cig-commits mailing list