From 6898fdfe61fc6d5c12e909172ead53ad7e8ceb04 Mon Sep 17 00:00:00 2001 From: eap Date: Tue, 30 Dec 2008 12:22:42 +0000 Subject: [PATCH] MEDMEM Industrialization 2008 fix pb with MPI_COMM_WORLD constant --- src/ParaMEDMEM_Swig/libParaMEDMEM_Swig.i | 61 ++++++++++++++++++------ 1 file changed, 47 insertions(+), 14 deletions(-) diff --git a/src/ParaMEDMEM_Swig/libParaMEDMEM_Swig.i b/src/ParaMEDMEM_Swig/libParaMEDMEM_Swig.i index 3cf0573c7..570c2b864 100644 --- a/src/ParaMEDMEM_Swig/libParaMEDMEM_Swig.i +++ b/src/ParaMEDMEM_Swig/libParaMEDMEM_Swig.i @@ -41,6 +41,9 @@ using namespace ParaMEDMEM; using namespace ICoCo; + + enum mpi_constants { mpi_comm_world, mpi_comm_self, mpi_double, mpi_int }; + %} @@ -219,20 +222,50 @@ public: 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 -- 2.39.2