[cig-commits] r5081 - cs/merlin/trunk
leif at geodynamics.org
leif at geodynamics.org
Mon Oct 23 17:57:54 PDT 2006
Author: leif
Date: 2006-10-23 17:57:54 -0700 (Mon, 23 Oct 2006)
New Revision: 5081
Added:
cs/merlin/trunk/mpimain.c
cs/merlin/trunk/mpimain.h
cs/merlin/trunk/pymain.c
cs/merlin/trunk/pymain.h
Modified:
cs/merlin/trunk/Makefile.am
cs/merlin/trunk/mpi.h
cs/merlin/trunk/mpipython.cpp
cs/merlin/trunk/python.cpp
Log:
Refactored main() functions slightly, mainly to work-around
the now legendary MPI/C++ compatibility issues.
Modified: cs/merlin/trunk/Makefile.am
===================================================================
--- cs/merlin/trunk/Makefile.am 2006-10-23 20:50:23 UTC (rev 5080)
+++ cs/merlin/trunk/Makefile.am 2006-10-24 00:57:54 UTC (rev 5081)
@@ -9,7 +9,10 @@
INCLUDES = -I$(top_srcdir)/lib/mpi -I$(PYTHON_INCDIR)
-python_SOURCES = python.cpp
+python_SOURCES = \
+ pymain.c \
+ pymain.h \
+ python.cpp
python$(EXEEXT): $(python_OBJECTS) $(python_DEPENDENCIES)
@rm -f python$(EXEEXT)
@@ -22,7 +25,12 @@
$(PYTHON_LDLAST)
-mpipython_SOURCES = mpipython.cpp libmpi.c
+mpipython_SOURCES = \
+ mpimain.c \
+ mpimain.h \
+ mpipython.cpp \
+ pymain.c \
+ pymain.h
mpipython$(EXEEXT): $(mpipython_OBJECTS) $(mpipython_DEPENDENCIES)
@rm -f mpipython$(EXEEXT)
Modified: cs/merlin/trunk/mpi.h
===================================================================
--- cs/merlin/trunk/mpi.h 2006-10-23 20:50:23 UTC (rev 5080)
+++ cs/merlin/trunk/mpi.h 2006-10-24 00:57:54 UTC (rev 5081)
@@ -38,7 +38,7 @@
* POSSIBILITY OF SUCH DAMAGE.
*
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-*/
+ */
#ifndef __merlin_mpi_h__
Copied: cs/merlin/trunk/mpimain.c (from rev 5080, cs/merlin/trunk/mpipython.cpp)
===================================================================
--- cs/merlin/trunk/mpipython.cpp 2006-10-23 20:50:23 UTC (rev 5080)
+++ cs/merlin/trunk/mpimain.c 2006-10-24 00:57:54 UTC (rev 5081)
@@ -0,0 +1,84 @@
+/*
+ * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ *
+ * merlin
+ *
+ * Copyright (c) 2006, California Institute of Technology
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following
+ * disclaimer in the documentation and/or other materials provided
+ * with the distribution.
+ *
+ * * Neither the name of the California Institute of Technology nor
+ * the names of its contributors may be used to endorse or promote
+ * products derived from this software without specific prior
+ * written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ */
+
+
+#include "mpimain.h"
+
+
+#include <mpi.h>
+#include <Python.h>
+#include "pymain.h"
+
+
+/* include the implementations of our built-in extension modules */
+#include "ld.c"
+#include "_mpi.c"
+
+
+struct _inittab inittab[] = {
+ { "ld", initld },
+ { "_mpi", init_mpi },
+ { 0, 0 }
+};
+
+
+int mpimain(int argc, char **argv)
+{
+ int errorcode, status;
+
+ errorcode = MPI_Init(&argc, &argv);
+ if (errorcode != MPI_SUCCESS) {
+ fprintf(stderr,
+ "%s: MPI_Init: error %d\n",
+ argv[0], errorcode);
+ return 1;
+ }
+
+ status = pymain(argc, argv, inittab);
+
+ MPI_Finalize();
+
+ return status;
+}
+
+
+/* end of file */
Added: cs/merlin/trunk/mpimain.h
===================================================================
--- cs/merlin/trunk/mpimain.h 2006-10-23 20:50:23 UTC (rev 5080)
+++ cs/merlin/trunk/mpimain.h 2006-10-24 00:57:54 UTC (rev 5081)
@@ -0,0 +1,62 @@
+/*
+ * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ *
+ * merlin
+ *
+ * Copyright (c) 2006, California Institute of Technology
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following
+ * disclaimer in the documentation and/or other materials provided
+ * with the distribution.
+ *
+ * * Neither the name of the California Institute of Technology nor
+ * the names of its contributors may be used to endorse or promote
+ * products derived from this software without specific prior
+ * written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ */
+
+
+#ifndef __mpimain_h__
+#define __mpimain_h__
+
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+ int mpimain(int argc, char **argv);
+
+#ifdef __cplusplus
+}
+#endif
+
+
+#endif /* __mpimain_h__ */
+
+
+/* end of file */
Modified: cs/merlin/trunk/mpipython.cpp
===================================================================
--- cs/merlin/trunk/mpipython.cpp 2006-10-23 20:50:23 UTC (rev 5080)
+++ cs/merlin/trunk/mpipython.cpp 2006-10-24 00:57:54 UTC (rev 5081)
@@ -41,48 +41,14 @@
//
-// Avoid MPI/C++ interaction issues.
-#define MERLIN_MPI_IMP mpi_wrapper
-#include "merlin/mpi-wrappers.h"
-#include "mpi.h"
+// Avoid MPI/C++ compatibility issues by never including <mpi.h> from
+// C++ code.
+#include "mpimain.h"
-#include <Python.h>
-#include <stdio.h>
-
-// include the implementations of our built-in extension modules
-#include "ld.c"
-#include "_mpi.c"
-
-
-struct _inittab inittab[] = {
- { "ld", initld },
- { "_mpi", init_mpi },
- { 0, 0 }
-};
-
-
int main(int argc, char **argv)
{
- int errorcode = MPI_Init(&argc, &argv);
- if (errorcode != MPI_SUCCESS) {
- fprintf(stderr,
- "%s: MPI_Init: error %d\n",
- argv[0], errorcode);
- }
-
- // add our extension modules
- if (PyImport_ExtendInittab(inittab) == -1) {
- fprintf(stderr,
- "%s: PyImport_ExtendInittab failed! Exiting...\n",
- argv[0]);
- return 1;
- }
- int status = Py_Main(argc, argv);
-
- MPI_Finalize();
-
- return status;
+ return mpimain(argc, argv);
}
Copied: cs/merlin/trunk/pymain.c (from rev 5080, cs/merlin/trunk/python.cpp)
===================================================================
--- cs/merlin/trunk/python.cpp 2006-10-23 20:50:23 UTC (rev 5080)
+++ cs/merlin/trunk/pymain.c 2006-10-24 00:57:54 UTC (rev 5081)
@@ -0,0 +1,64 @@
+/*
+ * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ *
+ * merlin
+ *
+ * Copyright (c) 2006, California Institute of Technology
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following
+ * disclaimer in the documentation and/or other materials provided
+ * with the distribution.
+ *
+ * * Neither the name of the California Institute of Technology nor
+ * the names of its contributors may be used to endorse or promote
+ * products derived from this software without specific prior
+ * written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ */
+
+
+#include "pymain.h"
+
+
+#include <Python.h>
+#include <stdio.h>
+
+
+int pymain(int argc, char **argv, struct _inittab *inittab)
+{
+ /* add our extension modules */
+ if (PyImport_ExtendInittab(inittab) == -1) {
+ fprintf(stderr,
+ "%s: PyImport_ExtendInittab failed! Exiting...\n",
+ argv[0]);
+ return 1;
+ }
+ return Py_Main(argc, argv);
+}
+
+
+/* end of file */
Added: cs/merlin/trunk/pymain.h
===================================================================
--- cs/merlin/trunk/pymain.h 2006-10-23 20:50:23 UTC (rev 5080)
+++ cs/merlin/trunk/pymain.h 2006-10-24 00:57:54 UTC (rev 5081)
@@ -0,0 +1,64 @@
+/*
+ * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ *
+ * merlin
+ *
+ * Copyright (c) 2006, California Institute of Technology
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following
+ * disclaimer in the documentation and/or other materials provided
+ * with the distribution.
+ *
+ * * Neither the name of the California Institute of Technology nor
+ * the names of its contributors may be used to endorse or promote
+ * products derived from this software without specific prior
+ * written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ */
+
+
+#ifndef __pymain_h__
+#define __pymain_h__
+
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+ struct _inittab;
+
+ int pymain(int argc, char **argv, struct _inittab *inittab);
+
+#ifdef __cplusplus
+}
+#endif
+
+
+#endif /* __pymain_h__ */
+
+
+/* end of file */
Modified: cs/merlin/trunk/python.cpp
===================================================================
--- cs/merlin/trunk/python.cpp 2006-10-23 20:50:23 UTC (rev 5080)
+++ cs/merlin/trunk/python.cpp 2006-10-24 00:57:54 UTC (rev 5081)
@@ -42,7 +42,7 @@
#include <Python.h>
-#include <stdio.h>
+#include "pymain.h"
// include the implementations of our built-in extension modules
@@ -57,14 +57,7 @@
int main(int argc, char **argv)
{
- // add our extension modules
- if (PyImport_ExtendInittab(inittab) == -1) {
- fprintf(stderr,
- "%s: PyImport_ExtendInittab failed! Exiting...\n",
- argv[0]);
- return 1;
- }
- return Py_Main(argc, argv);
+ return pymain(argc, argv, inittab);
}
More information about the cig-commits
mailing list