include $(top_srcdir)/adm_local/unix/make_common_starter.am
-lib_LTLIBRARIES = _libParaMED_Swig.la
+lib_LTLIBRARIES = _libParaMEDMEM_Swig.la
salomeinclude_HEADERS = \
- libParaMED_Swig.i
+ libParaMEDMEM_Swig.i
-SWIG_DEF = libParaMED_Swig.i
+SWIG_DEF = libParaMEDMEM_Swig.i
SWIG_FLAGS = @SWIG_FLAGS@ -I$(srcdir) $(MPI_INCLUDES) -I$(srcdir)/../MEDMEM_SWIG
-dist__libParaMED_Swig_la_SOURCES = libParaMED_Swig.i
-nodist__libParaMED_Swig_la_SOURCES = libParaMED_Swig_wrap.cxx
-libParaMED_Swig.py: libParaMED_Swig_wrap.cxx
+dist__libParaMEDMEM_Swig_la_SOURCES = libParaMEDMEM_Swig.i
+nodist__libParaMEDMEM_Swig_la_SOURCES = libParaMEDMEM_Swig_wrap.cxx
+libParaMEDMEM_Swig.py: libParaMEDMEM_Swig_wrap.cxx
-libParaMED_Swig_wrap.cxx: $(SWIG_DEF)
+libParaMEDMEM_Swig_wrap.cxx: $(SWIG_DEF)
$(SWIG) $(SWIG_FLAGS) -o $@ $<
-_libParaMED_Swig_la_CPPFLAGS = $(CORBA_CXXFLAGS) $(CORBA_INCLUDES) $(PYTHON_INCLUDES) \
+_libParaMEDMEM_Swig_la_CPPFLAGS = $(CORBA_CXXFLAGS) $(CORBA_INCLUDES) $(PYTHON_INCLUDES) \
$(MED2_INCLUDES) $(HDF5_INCLUDES) @CXXTMPDPTHFLAGS@ \
-I$(srcdir)/../MEDMEM -I$(srcdir)/../MEDWrapper/V2_1/Core -I$(srcdir)/../INTERP_KERNEL \
$(MPI_INCLUDES) -I$(srcdir)/../ParaMEDMEM -I$(srcdir)/../MEDMEM_SWIG
-_libParaMED_Swig_la_LDFLAGS = -module $(MED2_LIBS) $(HDF5_LIBS) $(PYTHON_LIBS) $(MPI_LIBS) \
+_libParaMEDMEM_Swig_la_LDFLAGS = -module $(MED2_LIBS) $(HDF5_LIBS) $(PYTHON_LIBS) $(MPI_LIBS) \
../MEDMEM/libmedmem.la ../INTERP_KERNEL/libinterpkernel.la \
../ParaMEDMEM/libparamedmem.la
if MED_ENABLE_KERNEL
- _libParaMED_Swig_la_CPPFLAGS += ${KERNEL_CXXFLAGS}
- _libParaMED_Swig_la_LDFLAGS += ${KERNEL_LDFLAGS} -lSALOMELocalTrace
+ _libParaMEDMEM_Swig_la_CPPFLAGS += ${KERNEL_CXXFLAGS}
+ _libParaMEDMEM_Swig_la_LDFLAGS += ${KERNEL_LDFLAGS} -lSALOMELocalTrace
endif
-CLEANFILES = libParaMED_Swig_wrap.cxx libParaMED_Swig.py
+CLEANFILES = libParaMEDMEM_Swig_wrap.cxx libParaMEDMEM_Swig.py
-nodist_salomescript_DATA= libParaMED_Swig.py
+nodist_salomescript_DATA= libParaMEDMEM_Swig.py
dist_salomescript_DATA= test_intersectiondec.py \
test_noncoincidentdec.py \
# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
#
-from libParaMED_Swig import *
+from libParaMEDMEM_Swig import *
--- /dev/null
+// Copyright (C) 2005 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License.
+//
+// This library is distributed in the hope that it will be useful
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+%module libParaMEDMEM_Swig
+
+%include "libParaMEDMEM_Swig.typemap"
+%include "../MEDMEM_SWIG/libMEDMEM_Swig.i"
+
+%{
+#include <CommInterface.hxx>
+#include <ProcessorGroup.hxx>
+#include <Topology.hxx>
+#include <MPIProcessorGroup.hxx>
+#include <DEC.hxx>
+#include <IntersectionDEC.hxx>
+#include <NonCoincidentDEC.hxx>
+#include <StructuredCoincidentDEC.hxx>
+#include <ParaMESH.hxx>
+#include <UnstructuredParaSUPPORT.hxx>
+#include <StructuredParaSUPPORT.hxx>
+#include <ParaFIELD.hxx>
+#include <ICoCoMEDField.hxx>
+
+#include <mpi.h>
+
+using namespace ParaMEDMEM;
+using namespace ICoCo;
+%}
+
+
+class CommInterface {
+public:
+ CommInterface();
+};
+
+class ProcessorGroup {
+public:
+ %extend {
+ // avoid error when SWIG creates a default constructor of an abstract class
+ ProcessorGroup() { return NULL; }
+ }
+};
+
+class MPIProcessorGroup: public ProcessorGroup {
+public:
+ MPIProcessorGroup(const CommInterface& interface);
+ MPIProcessorGroup(const CommInterface& interface, set<int> proc_ids);
+ MPIProcessorGroup(const CommInterface& interface,int pstart, int pend);
+
+ int translateRank(const ProcessorGroup* group, int rank) const;
+ ProcessorGroup* createComplementProcGroup() const;
+ ProcessorGroup* fuse (const ProcessorGroup&) const;
+
+ bool containsMyRank() const;
+ int myRank() const;
+};
+
+%rename(ICoCo_MEDField) ICoCo::MEDField;
+namespace ICoCo {
+class Field {
+};
+
+class MEDField: public Field {
+public:
+ MEDField(ParaMESH* mesh, ParaFIELD* field);
+};
+}
+
+class DEC {
+public:
+ %extend {
+ // avoid error when SWIG creates a default constructor of an abstract class
+ DEC() { return NULL; };
+ }
+ void recvData();
+ void sendData();
+ void synchronize();
+
+ void attachLocalField(FIELD<double>* field, const char* method="P0");
+ void attachLocalField(const ParaFIELD* field, const char* method="P0");
+ void attachLocalField(const ICoCo::Field* field, const char* method="P0");
+
+ void renormalizeTargetField();
+};
+
+
+typedef enum{WithoutTimeInterp,LinearTimeInterp} TimeInterpolationMethod;
+
+typedef enum{Native,PointToPoint} AllToAllMethod;
+
+class IntersectionDEC: public DEC {
+public:
+
+ IntersectionDEC(ProcessorGroup& local_group, ProcessorGroup& distant_group);
+
+ void recvData();
+ void recvData( double time );
+
+ void sendData();
+ void sendData( double time, double deltatime );
+
+ void setTimeInterpolationMethod(TimeInterpolationMethod it);
+ TimeInterpolationMethod getTimeInterpolationMethod();
+
+ void setAsynchronous( bool dr);
+ bool getAsynchronous();
+
+ AllToAllMethod getAllToAllMethod();
+ void setAllToAllMethod(AllToAllMethod sp);
+
+ bool getForcedRenormalization();
+ void setForcedRenormalization( bool dr);
+};
+
+
+
+/* This object can be used only if MED_ENABLE_FVM is defined*/
+#ifdef MED_ENABLE_FVM
+class NonCoincidentDEC: public DEC {
+public:
+ NonCoincidentDEC(ProcessorGroup& source, ProcessorGroup& target);
+};
+#endif
+
+
+class StructuredCoincidentDEC: public DEC {
+public:
+ StructuredCoincidentDEC(ProcessorGroup& source, ProcessorGroup& target);
+ void prepareSourceDE();
+ void prepareTargetDE();
+};
+
+
+class ParaMESH {
+public:
+ ParaMESH(driverTypes driver_type, const char* file_name, const ProcessorGroup& group);
+ ParaMESH(MESH& subdomain_mesh, const ProcessorGroup& proc_group, const char* name);
+
+ void write(driverTypes driverType, const char* fileName="");
+ MESH* getMesh() const;
+};
+
+
+
+class ParaSUPPORT {
+public:
+ %extend {
+ // avoid error when SWIG creates a default constructor of an abstract class
+ ParaSUPPORT() { return NULL; }
+
+ PyObject* getGlobalNumbering() {
+ const int * numIndex = self->getGlobalNumbering();
+ int aSize = self->getSupport()->getNumberOfElements(999);
+ TYPEMAP_OUTPUT_ARRAY(numIndex, aSize, PyInt_FromLong, ParaSUPPORT::getGlobalNumbering);
+ }
+ }
+};
+
+
+class UnstructuredParaSUPPORT: public ParaSUPPORT {
+public:
+ UnstructuredParaSUPPORT(const ParaMESH* const mesh, const SUPPORT* support );
+ UnstructuredParaSUPPORT(const ParaMESH* const mesh, const medEntityMesh entity);
+ UnstructuredParaSUPPORT(const SUPPORT* support, const ProcessorGroup& group);
+};
+
+class StructuredParaSUPPORT: public ParaSUPPORT {
+public:
+ StructuredParaSUPPORT(const ParaGRID* const grid, const medEntityMesh entity);
+ StructuredParaSUPPORT(const ParaMESH* const mesh, const medEntityMesh entity);
+};
+
+class ComponentTopology {
+public:
+ ComponentTopology();
+ ComponentTopology(int nb_comp);
+ ComponentTopology(int nb_comp, int nb_blocks);
+ ComponentTopology(int nb_comp, ProcessorGroup* group);
+
+ int nbComponents();
+ int nbLocalComponents();
+};
+
+
+class ParaFIELD {
+public:
+ ParaFIELD(const ParaSUPPORT* support,
+ const ComponentTopology& component_topology);
+
+ ParaFIELD(driverTypes driver_type,
+ const char* file_name,
+ const char* driver_name,
+ const ComponentTopology& component_topology);
+
+ ParaFIELD(FIELDDOUBLE* field, const ProcessorGroup& group);
+
+ void write(driverTypes driverType,
+ const char* fileName="",
+ const char* meshName="");
+
+ FIELDDOUBLE* getField() const;
+
+ double getVolumeIntegral(int icomp) const;
+};
+
+
+// MPI realization specific definition !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+
+//#ifdef MPICH2
+// MPICH2
+typedef int MPI_Datatype;
+typedef int MPI_Comm;
+#define MPI_COMM_WORLD 0x44000000
+#define MPI_COMM_SELF 0x44000001
+#define MPI_DOUBLE 0x4c00080b
+#define MPI_INT 0x4c000405
+
+//#endif
+// END OF MPI realization specific definition !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+
+// ==============
+// MPI_Comm_size
+// ==============
+%inline %{ PyObject* MPI_Comm_size(MPI_Comm comm) {
+ int res = 0;
+ int err = MPI_Comm_size(comm, &res);
+ if ( err != MPI_SUCCESS ) {
+ PyErr_SetString(PyExc_RuntimeError,"Erorr in MPI_Comm_size()");
+ return NULL;
+ }
+ return PyInt_FromLong( res );
+} %}
+
+// ==============
+// MPI_Comm_rank
+// ==============
+%inline %{ PyObject* MPI_Comm_rank(MPI_Comm comm) {
+ int res = 0;
+ int err = MPI_Comm_rank(comm, &res);
+ if ( err != MPI_SUCCESS ) {
+ PyErr_SetString(PyExc_RuntimeError,"Erorr in MPI_Comm_rank()");
+ return NULL;
+ }
+ return PyInt_FromLong( res );
+} %}
+
+int MPI_Init(int *argc, char ***argv );
+int MPI_Barrier(MPI_Comm comm);
+int MPI_Finalize();
+
+// ==========
+// MPI_Bcast
+// ==========
+
+%inline %{ PyObject* MPI_Bcast(PyObject* buffer, int nb, MPI_Datatype type, int root, MPI_Comm c) {
+ // buffer must be a list
+ if (!PyList_Check(buffer)) {
+ PyErr_SetString(PyExc_TypeError, "buffer is expected to be a list");
+ return NULL;
+ }
+ // check list size
+ int aSize = PyList_Size(buffer);
+ if ( aSize != nb ) {
+ PyErr_SetString(PyExc_ValueError, MEDMEM::STRING("buffer is expected to be of size ")<<nb);
+ return NULL;
+ }
+ // allocate and fill a buffer
+ void* aBuf = 0;
+ int* intBuf = 0;
+ double* dblBuf = 0;
+ if ( type == MPI_DOUBLE ) {
+ aBuf = (void*) ( dblBuf = new double[ nb ] );
+ for ( int i = 0; i < aSize; ++i )
+ dblBuf[i] = PyFloat_AS_DOUBLE( PyList_GetItem( buffer, i ));
+ }
+ else if ( type == MPI_INT ) {
+ aBuf = (void*) ( intBuf = new int[ nb ] );
+ for ( int i = 0; i < aSize; ++i )
+ intBuf[i] = int( PyInt_AS_LONG( PyList_GetItem( buffer, i )));
+ }
+ else {
+ PyErr_SetString(PyExc_TypeError, "Only MPI_DOUBLE and MPI_INT supported");
+ return NULL;
+ }
+ // call MPI_Bcast
+ int err = MPI_Bcast(aBuf, nb, type, root, c);
+ // treat error
+ if ( err != MPI_SUCCESS ) {
+ PyErr_SetString(PyExc_RuntimeError,"Erorr in MPI_Bcast()");
+ delete [] intBuf; delete [] dblBuf;
+ return NULL;
+ }
+ // put recieved data into the list
+ int pyerr = 0;
+ if ( type == MPI_DOUBLE ) {
+ for ( int i = 0; i < aSize && !pyerr; ++i )
+ pyerr = PyList_SetItem(buffer, i, PyFloat_FromDouble( dblBuf[i] ));
+ delete [] dblBuf;
+ }
+ else {
+ for ( int i = 0; i < aSize && !pyerr; ++i )
+ pyerr = PyList_SetItem(buffer, i, PyInt_FromLong( intBuf[i] ));
+ delete [] intBuf;
+ }
+ if ( pyerr ) {
+ PyErr_SetString(PyExc_RuntimeError, "Error of PyList_SetItem()");
+ return NULL;
+ }
+ return PyInt_FromLong( err );
+
+} %}
+
--- /dev/null
+
+// Creates "int *argc, char ***argv" parameters from input list
+%typemap(in) (int *argc, char ***argv) {
+ int i;
+ if (!PyList_Check($input)) {
+ PyErr_SetString(PyExc_ValueError, "Expecting a list");
+ return NULL;
+ }
+ int aSize = PyList_Size($input);
+ $1 = &aSize;
+ char** aStrs = (char **) malloc((aSize+1)*sizeof(char *));
+ for (i = 0; i < aSize; i++) {
+ PyObject *s = PyList_GetItem($input,i);
+ if (!PyString_Check(s)) {
+ free(aStrs);
+ PyErr_SetString(PyExc_ValueError, "List items must be strings");
+ return NULL;
+ }
+ aStrs[i] = PyString_AsString(s);
+ }
+ aStrs[i] = 0;
+ $2 = &aStrs;
+}
+
+%typemap(freearg) (int *argc, char ***argv) {
+ if ($2) free(*($2));
+}
+
+/* MACRO: IN typemap for std::set<TYPE> C++ object */
+%define TYPEMAP_INPUT_SET_BY_VALUE( TYPE )
+{
+ /* typemap in for set<TYPE> */
+ /* Check if is a list */
+ if (PyList_Check($input))
+ {
+ int size = PyList_Size($input);
+ set< TYPE > tmpSet;
+
+ for (int i=0; i < size; i++)
+ {
+ PyObject * tmp = PyList_GetItem($input,i);
+ TYPE elem = PyInt_AsLong(tmp);
+ tmpSet.insert(elem);
+ }
+ $1 = tmpSet;
+ }
+ else
+ {
+ PyErr_SetString(PyExc_TypeError,"not a list");
+ return NULL;
+ }
+}
+%enddef
+
+%typemap(in) set<int>
+{
+ TYPEMAP_INPUT_SET_BY_VALUE( int )
+}
+%typecheck(SWIG_TYPECHECK_POINTER) set<int> {
+ $1 = PyList_Check($input) ? 1 : 0;
+}
+++ /dev/null
-// Copyright (C) 2005 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
-// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
-//
-// This library is free software; you can redistribute it and/or
-// modify it under the terms of the GNU Lesser General Public
-// License as published by the Free Software Foundation; either
-// version 2.1 of the License.
-//
-// This library is distributed in the hope that it will be useful
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-// Lesser General Public License for more details.
-//
-// You should have received a copy of the GNU Lesser General Public
-// License along with this library; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-//
-// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
-//
-%module libParaMED_Swig
-
-%include "libParaMED_Swig.typemap"
-%include "../MEDMEM_SWIG/libMEDMEM_Swig.i"
-
-%{
-#include <CommInterface.hxx>
-#include <ProcessorGroup.hxx>
-#include <Topology.hxx>
-#include <MPIProcessorGroup.hxx>
-#include <DEC.hxx>
-#include <IntersectionDEC.hxx>
-#include <NonCoincidentDEC.hxx>
-#include <StructuredCoincidentDEC.hxx>
-#include <ParaMESH.hxx>
-#include <UnstructuredParaSUPPORT.hxx>
-#include <StructuredParaSUPPORT.hxx>
-#include <ParaFIELD.hxx>
-#include <ICoCoMEDField.hxx>
-
-#include <mpi.h>
-
-using namespace ParaMEDMEM;
-using namespace ICoCo;
-%}
-
-
-class CommInterface {
-public:
- CommInterface();
-};
-
-class ProcessorGroup {
-public:
- %extend {
- // avoid error when SWIG creates a default constructor of an abstract class
- ProcessorGroup() { return NULL; }
- }
-};
-
-class MPIProcessorGroup: public ProcessorGroup {
-public:
- MPIProcessorGroup(const CommInterface& interface);
- MPIProcessorGroup(const CommInterface& interface, set<int> proc_ids);
- MPIProcessorGroup(const CommInterface& interface,int pstart, int pend);
-
- int translateRank(const ProcessorGroup* group, int rank) const;
- ProcessorGroup* createComplementProcGroup() const;
- ProcessorGroup* fuse (const ProcessorGroup&) const;
-
- bool containsMyRank() const;
- int myRank() const;
-};
-
-%rename(ICoCo_MEDField) ICoCo::MEDField;
-namespace ICoCo {
-class Field {
-};
-
-class MEDField: public Field {
-public:
- MEDField(ParaMESH* mesh, ParaFIELD* field);
-};
-}
-
-class DEC {
-public:
- %extend {
- // avoid error when SWIG creates a default constructor of an abstract class
- DEC() { return NULL; };
- }
- void recvData();
- void sendData();
- void synchronize();
-
- void attachLocalField(FIELD<double>* field, const char* method="P0");
- void attachLocalField(const ParaFIELD* field, const char* method="P0");
- void attachLocalField(const ICoCo::Field* field, const char* method="P0");
-
- void renormalizeTargetField();
-};
-
-
-typedef enum{WithoutTimeInterp,LinearTimeInterp} TimeInterpolationMethod;
-
-typedef enum{Native,PointToPoint} AllToAllMethod;
-
-class IntersectionDEC: public DEC {
-public:
-
- IntersectionDEC(ProcessorGroup& local_group, ProcessorGroup& distant_group);
-
- void recvData();
- void recvData( double time );
-
- void sendData();
- void sendData( double time, double deltatime );
-
- void setTimeInterpolationMethod(TimeInterpolationMethod it);
- TimeInterpolationMethod getTimeInterpolationMethod();
-
- void setAsynchronous( bool dr);
- bool getAsynchronous();
-
- AllToAllMethod getAllToAllMethod();
- void setAllToAllMethod(AllToAllMethod sp);
-
- bool getForcedRenormalization();
- void setForcedRenormalization( bool dr);
-};
-
-
-
-/* This object can be used only if MED_ENABLE_FVM is defined*/
-#ifdef MED_ENABLE_FVM
-class NonCoincidentDEC: public DEC {
-public:
- NonCoincidentDEC(ProcessorGroup& source, ProcessorGroup& target);
-};
-#endif
-
-
-class StructuredCoincidentDEC: public DEC {
-public:
- StructuredCoincidentDEC(ProcessorGroup& source, ProcessorGroup& target);
- void prepareSourceDE();
- void prepareTargetDE();
-};
-
-
-class ParaMESH {
-public:
- ParaMESH(driverTypes driver_type, const char* file_name, const ProcessorGroup& group);
- ParaMESH(MESH& subdomain_mesh, const ProcessorGroup& proc_group, const char* name);
-
- void write(driverTypes driverType, const char* fileName="");
- MESH* getMesh() const;
-};
-
-
-
-class ParaSUPPORT {
-public:
- %extend {
- // avoid error when SWIG creates a default constructor of an abstract class
- ParaSUPPORT() { return NULL; }
-
- PyObject* getGlobalNumbering() {
- const int * numIndex = self->getGlobalNumbering();
- int aSize = self->getSupport()->getNumberOfElements(999);
- TYPEMAP_OUTPUT_ARRAY(numIndex, aSize, PyInt_FromLong, ParaSUPPORT::getGlobalNumbering);
- }
- }
-};
-
-
-class UnstructuredParaSUPPORT: public ParaSUPPORT {
-public:
- UnstructuredParaSUPPORT(const ParaMESH* const mesh, const SUPPORT* support );
- UnstructuredParaSUPPORT(const ParaMESH* const mesh, const medEntityMesh entity);
- UnstructuredParaSUPPORT(const SUPPORT* support, const ProcessorGroup& group);
-};
-
-class StructuredParaSUPPORT: public ParaSUPPORT {
-public:
- StructuredParaSUPPORT(const ParaGRID* const grid, const medEntityMesh entity);
- StructuredParaSUPPORT(const ParaMESH* const mesh, const medEntityMesh entity);
-};
-
-class ComponentTopology {
-public:
- ComponentTopology();
- ComponentTopology(int nb_comp);
- ComponentTopology(int nb_comp, int nb_blocks);
- ComponentTopology(int nb_comp, ProcessorGroup* group);
-
- int nbComponents();
- int nbLocalComponents();
-};
-
-
-class ParaFIELD {
-public:
- ParaFIELD(const ParaSUPPORT* support,
- const ComponentTopology& component_topology);
-
- ParaFIELD(driverTypes driver_type,
- const char* file_name,
- const char* driver_name,
- const ComponentTopology& component_topology);
-
- ParaFIELD(FIELDDOUBLE* field, const ProcessorGroup& group);
-
- void write(driverTypes driverType,
- const char* fileName="",
- const char* meshName="");
-
- FIELDDOUBLE* getField() const;
-
- double getVolumeIntegral(int icomp) const;
-};
-
-
-// MPI realization specific definition !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-
-//#ifdef MPICH2
-// MPICH2
-typedef int MPI_Datatype;
-typedef int MPI_Comm;
-#define MPI_COMM_WORLD 0x44000000
-#define MPI_COMM_SELF 0x44000001
-#define MPI_DOUBLE 0x4c00080b
-#define MPI_INT 0x4c000405
-
-//#endif
-// END OF MPI realization specific definition !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-
-// ==============
-// MPI_Comm_size
-// ==============
-%inline %{ PyObject* MPI_Comm_size(MPI_Comm comm) {
- int res = 0;
- int err = MPI_Comm_size(comm, &res);
- if ( err != MPI_SUCCESS ) {
- PyErr_SetString(PyExc_RuntimeError,"Erorr in MPI_Comm_size()");
- return NULL;
- }
- return PyInt_FromLong( res );
-} %}
-
-// ==============
-// MPI_Comm_rank
-// ==============
-%inline %{ PyObject* MPI_Comm_rank(MPI_Comm comm) {
- int res = 0;
- int err = MPI_Comm_rank(comm, &res);
- if ( err != MPI_SUCCESS ) {
- PyErr_SetString(PyExc_RuntimeError,"Erorr in MPI_Comm_rank()");
- return NULL;
- }
- return PyInt_FromLong( res );
-} %}
-
-int MPI_Init(int *argc, char ***argv );
-int MPI_Barrier(MPI_Comm comm);
-int MPI_Finalize();
-
-// ==========
-// MPI_Bcast
-// ==========
-
-%inline %{ PyObject* MPI_Bcast(PyObject* buffer, int nb, MPI_Datatype type, int root, MPI_Comm c) {
- // buffer must be a list
- if (!PyList_Check(buffer)) {
- PyErr_SetString(PyExc_TypeError, "buffer is expected to be a list");
- return NULL;
- }
- // check list size
- int aSize = PyList_Size(buffer);
- if ( aSize != nb ) {
- PyErr_SetString(PyExc_ValueError, MEDMEM::STRING("buffer is expected to be of size ")<<nb);
- return NULL;
- }
- // allocate and fill a buffer
- void* aBuf = 0;
- int* intBuf = 0;
- double* dblBuf = 0;
- if ( type == MPI_DOUBLE ) {
- aBuf = (void*) ( dblBuf = new double[ nb ] );
- for ( int i = 0; i < aSize; ++i )
- dblBuf[i] = PyFloat_AS_DOUBLE( PyList_GetItem( buffer, i ));
- }
- else if ( type == MPI_INT ) {
- aBuf = (void*) ( intBuf = new int[ nb ] );
- for ( int i = 0; i < aSize; ++i )
- intBuf[i] = int( PyInt_AS_LONG( PyList_GetItem( buffer, i )));
- }
- else {
- PyErr_SetString(PyExc_TypeError, "Only MPI_DOUBLE and MPI_INT supported");
- return NULL;
- }
- // call MPI_Bcast
- int err = MPI_Bcast(aBuf, nb, type, root, c);
- // treat error
- if ( err != MPI_SUCCESS ) {
- PyErr_SetString(PyExc_RuntimeError,"Erorr in MPI_Bcast()");
- delete [] intBuf; delete [] dblBuf;
- return NULL;
- }
- // put recieved data into the list
- int pyerr = 0;
- if ( type == MPI_DOUBLE ) {
- for ( int i = 0; i < aSize && !pyerr; ++i )
- pyerr = PyList_SetItem(buffer, i, PyFloat_FromDouble( dblBuf[i] ));
- delete [] dblBuf;
- }
- else {
- for ( int i = 0; i < aSize && !pyerr; ++i )
- pyerr = PyList_SetItem(buffer, i, PyInt_FromLong( intBuf[i] ));
- delete [] intBuf;
- }
- if ( pyerr ) {
- PyErr_SetString(PyExc_RuntimeError, "Error of PyList_SetItem()");
- return NULL;
- }
- return PyInt_FromLong( err );
-
-} %}
-
+++ /dev/null
-
-// Creates "int *argc, char ***argv" parameters from input list
-%typemap(in) (int *argc, char ***argv) {
- int i;
- if (!PyList_Check($input)) {
- PyErr_SetString(PyExc_ValueError, "Expecting a list");
- return NULL;
- }
- int aSize = PyList_Size($input);
- $1 = &aSize;
- char** aStrs = (char **) malloc((aSize+1)*sizeof(char *));
- for (i = 0; i < aSize; i++) {
- PyObject *s = PyList_GetItem($input,i);
- if (!PyString_Check(s)) {
- free(aStrs);
- PyErr_SetString(PyExc_ValueError, "List items must be strings");
- return NULL;
- }
- aStrs[i] = PyString_AsString(s);
- }
- aStrs[i] = 0;
- $2 = &aStrs;
-}
-
-%typemap(freearg) (int *argc, char ***argv) {
- if ($2) free(*($2));
-}
-
-/* MACRO: IN typemap for std::set<TYPE> C++ object */
-%define TYPEMAP_INPUT_SET_BY_VALUE( TYPE )
-{
- /* typemap in for set<TYPE> */
- /* Check if is a list */
- if (PyList_Check($input))
- {
- int size = PyList_Size($input);
- set< TYPE > tmpSet;
-
- for (int i=0; i < size; i++)
- {
- PyObject * tmp = PyList_GetItem($input,i);
- TYPE elem = PyInt_AsLong(tmp);
- tmpSet.insert(elem);
- }
- $1 = tmpSet;
- }
- else
- {
- PyErr_SetString(PyExc_TypeError,"not a list");
- return NULL;
- }
-}
-%enddef
-
-%typemap(in) set<int>
-{
- TYPEMAP_INPUT_SET_BY_VALUE( int )
-}
-%typecheck(SWIG_TYPECHECK_POINTER) set<int> {
- $1 = PyList_Check($input) ? 1 : 0;
-}