using namespace ParaMEDMEM;
using namespace ICoCo;
+
+ enum mpi_constants { mpi_comm_world, mpi_comm_self, mpi_double, mpi_int };
+
%}
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 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+//=============================================================================================
+// Interface for MPI-realization-specific constants like MPI_COMM_WORLD.
+//
+// Type and values of constants like MPI_COMM_WORLD depends on MPI realization
+// and usually such constants actually are macros. To have such symbols in python
+// and translate them into correct values we use the following technique.
+// We define some constants (enum mpi_constants) and map them into real MPI values
+// using typemaps, and we create needed python symbols equal to 'mpi_constants'
+// via %pythoncode directive.
+
+// Constants corresponding to similar MPI definitions
+enum mpi_constants { mpi_comm_world, mpi_comm_self, mpi_double, mpi_int };
+
+// Map mpi_comm_world and mpi_comm_self -> MPI_COMM_WORLD and MPI_COMM_SELF
+%typemap(in) MPI_Comm
+{
+ switch (PyInt_AsLong($input)) {
+ case mpi_comm_world: $1 = MPI_COMM_WORLD; break;
+ case mpi_comm_self: $1 = MPI_COMM_SELF; break;
+ default:
+ PyErr_SetString(PyExc_TypeError,"unexpected value");
+ return NULL;
+ }
+}
+// Map mpi_double and mpi_int -> MPI_DOUBLE and MPI_INT
+%typemap(in) MPI_Datatype
+{
+ switch (PyInt_AsLong($input)) {
+ case mpi_double: $1 = MPI_DOUBLE; break;
+ case mpi_int: $1 = MPI_INT; break;
+ default:
+ PyErr_SetString(PyExc_TypeError,"unexpected value");
+ return NULL;
+ }
+}
+// The following code gets inserted into the result python file:
+// create needed python symbols
+%pythoncode %{
+ MPI_COMM_WORLD = mpi_comm_world
+ MPI_COMM_SELF = mpi_comm_self
+ MPI_DOUBLE = mpi_double
+ MPI_INT = mpi_int
+%}
+//=============================================================================================
// ==============
// MPI_Comm_size