]> SALOME platform Git repositories - tools/medcoupling.git/commitdiff
Salome HOME
second try without mpi4py.h ...
authorabn <adrien.bruneton@cea.fr>
Fri, 12 May 2023 15:46:03 +0000 (17:46 +0200)
committerabn <adrien.bruneton@cea.fr>
Fri, 12 May 2023 15:46:03 +0000 (17:46 +0200)
CMakeLists.txt
doc/developer/doxygen/doxfiles/reference/misc/swig_mpi.dox
src/ParaMEDMEM/InterpKernelDEC.hxx
src/ParaMEDMEM_Swig/CMakeLists.txt
src/ParaMEDMEM_Swig/ParaMEDMEMCommon.i
src/ParaMEDMEM_Swig/test_InterpKernelDEC.py
src/ParaMEDMEM_Swig/test_OverlapDEC.py
src/PyWrapping/CMakeLists.txt

index 181e98cb3f98d151bda11bf7a2ce0f85247096f7..952609497182e0fc73b61d86e526ea2a8e38e860 100644 (file)
@@ -220,14 +220,6 @@ IF(MEDCOUPLING_ENABLE_PYTHON)
   IF(MEDCOUPLING_SWIG4_COMPAT)
     LIST(APPEND CMAKE_SWIG_FLAGS "-DMEDCOUPLING_SWIG4_COMPAT")
   ENDIF()
-
-  # Possibility to specify a mpi4py installation
-  SET(MEDCOUPLING_MPI4PY_DIR "" CACHE PATH "Path to the mpi4py installation")
-  IF(MEDCOUPLING_MPI4PY_DIR)
-     MESSAGE(STATUS "Using mpi4py directory: ${MEDCOUPLING_MPI4PY_DIR}")
-     SET(MEDCOUPLING_MPI4PY_INCLUDE_DIR "${MEDCOUPLING_MPI4PY_DIR}/include")
-     SET(MEDCOUPLING_MPI4PY_I_FILE "${MEDCOUPLING_MPI4PY_DIR}/include/mpi4py/mpi4py.i")
-  ENDIF()
 ENDIF(MEDCOUPLING_ENABLE_PYTHON)
 
 IF(MEDCOUPLING_BUILD_DOC)
index 84004333ea28ac4a00498abaaa968fc69f449755..dc8898b455d9a1094eb0678bd5f97b35c53cee44 100644 (file)
@@ -21,4 +21,11 @@ void method_taking_a_MPI_Comm(MPI_Comm mpicomm);
 
 where the path to mpi4py.i needs to be adapted to your configuration.
 
+In MEDCoupling DEC APIs (InterpKernelDEC and OverlapDEC constructors), the Python interface deals with that using the following trick to get the C++ adress of the MPI communicator:
+
+\code{.py}
+from mpi4py import MPI
+MPI._addressof(mpicomm) # returns the C++ adress of the MPI communicator
+\endcode
+
 */
index 95c40f705ed23592f0a678e0d1209e9e66c61aea..f4b156329c65bd88e52e5232fa57591d62deab31 100644 (file)
@@ -130,8 +130,7 @@ namespace MEDCoupling
   public:  
     InterpKernelDEC();
     InterpKernelDEC(ProcessorGroup& source_group, ProcessorGroup& target_group);
-    InterpKernelDEC(const std::set<int>& src_ids, const std::set<int>& trg_ids,
-                    const MPI_Comm& world_comm=MPI_COMM_WORLD);
+    InterpKernelDEC(const std::set<int>& src_ids, const std::set<int>& trg_ids, const MPI_Comm& world_comm=MPI_COMM_WORLD);
     virtual ~InterpKernelDEC();
     void release();
 
index 28a11ad5ef4891c7373ede50a65ffdffe22997b0..47320923d5cba54972c064cec4f977660ba2986d 100644 (file)
@@ -36,10 +36,6 @@ SET(SWIG_MODULE_ParaMEDMEM_EXTRA_FLAGS "${NUMPY_DEFINITIONS};${SCIPY_DEFINITIONS
 IF(MEDCOUPLING_USE_64BIT_IDS)
   STRING(APPEND SWIG_MODULE_ParaMEDMEM_EXTRA_FLAGS ";-DMEDCOUPLING_USE_64BIT_IDS")
 ENDIF(MEDCOUPLING_USE_64BIT_IDS)
-IF(MEDCOUPLING_MPI4PY_DIR)
-  INCLUDE_DIRECTORIES(${MEDCOUPLING_MPI4PY_INCLUDE_DIR})
-  STRING(APPEND SWIG_MODULE_ParaMEDMEM_EXTRA_FLAGS ";-DMEDCOUPLING_MPI4PY_I_FILE=${MEDCOUPLING_MPI4PY_I_FILE}")
-ENDIF()
 
 INCLUDE_DIRECTORIES(
   ${PYTHON_INCLUDE_DIRS}
index e8d1cf11401b1381d81dda34444e4381bb43699e..50c42b136e0d43901a3deeb99f5f100622f2eda0 100644 (file)
@@ -60,9 +60,7 @@ using namespace ICoCo;
 %include "ComponentTopology.hxx"
 %include "DEC.hxx"
 %include "DisjointDEC.hxx"
-%include "InterpKernelDEC.hxx"
 %include "StructuredCoincidentDEC.hxx"
-%include "OverlapDEC.hxx"
 
 %newobject MEDCoupling::ParaUMesh::New;
 %newobject MEDCoupling::ParaUMesh::getMesh;
@@ -81,6 +79,9 @@ using namespace ICoCo;
 %newobject MEDCoupling::ParaSkyLineArray::getSkyLineArray;
 %newobject MEDCoupling::ParaSkyLineArray::getGlobalIdsArray;
 
+%newobject MEDCoupling::InterpKernelDEC::_NewWithComm_internal;
+%newobject MEDCoupling::OverlapDEC::_NewWithComm_internal;
+
 %feature("unref") ParaSkyLineArray "$this->decrRef();"
 %feature("unref") ParaUMesh "$this->decrRef();"
 %feature("unref") ParaDataArrayInt32 "$this->decrRef();"
@@ -280,16 +281,80 @@ namespace MEDCoupling
       }
     }
   };
-}
 
-/* 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
+  /* 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 InterpKernelDEC : public DisjointDEC, public INTERP_KERNEL::InterpolationOptions
+  {
+    public:
+      InterpKernelDEC();
+      InterpKernelDEC(ProcessorGroup& source_group, ProcessorGroup& target_group);
+      virtual ~InterpKernelDEC();
+      void release();
+
+      void synchronize();
+      void recvData();
+      void recvData(double time);
+      void sendData();
+      void sendData(double time , double deltatime);
+      void prepareSourceDE();
+      void prepareTargetDE();
+
+      %extend {
+        // This one should really not be called directly by the user since it still has an interface with a pointer to MPI_Comm 
+        // which Swig doesn't handle nicely.
+        // It is just here to provide a constructor taking a **pointer** to a comm - See pythoncode below.
+        static InterpKernelDEC* _NewWithComm_internal(const std::set<int>& src_ids, const std::set<int>& trg_ids, long another_comm)
+        {
+          return new InterpKernelDEC(src_ids,trg_ids, *(MPI_Comm*)another_comm); // I know, ugly cast ...
+        }
+      }
+  };
+
+  class OverlapDEC : public DEC, public INTERP_KERNEL::InterpolationOptions
+  {
+      public:
+        OverlapDEC(const std::set<int>& procIds);
+        virtual ~OverlapDEC();
+        void release();
+
+        void sendRecvData(bool way=true);
+        void sendData();
+        void recvData();
+        void synchronize();
+        void attachSourceLocalField(ParaFIELD *field, bool ownPt=false);
+        void attachTargetLocalField(ParaFIELD *field, bool ownPt=false);
+        void attachSourceLocalField(MEDCouplingFieldDouble *field);
+        void attachTargetLocalField(MEDCouplingFieldDouble *field);
+        void attachSourceLocalField(ICoCo::MEDDoubleField *field);
+        void attachTargetLocalField(ICoCo::MEDDoubleField *field);
+        ProcessorGroup *getGroup();
+        bool isInGroup() const;
+
+        void setDefaultValue(double val);
+        void setWorkSharingAlgo(int method);
+
+        void debugPrintWorkSharing(std::ostream & ostr) const;
+
+        %extend {
+          // This one should really not be called directly by the user since it still has an interface with a pointer to MPI_Comm 
+          // which Swig doesn't handle nicely.
+          // It is just here to provide a constructor taking a **pointer** to a comm - See pythoncode below.
+          static OverlapDEC* _NewWithComm_internal(const std::set<int>& ids, long another_comm)
+          {
+            return new OverlapDEC(ids, *(MPI_Comm*)another_comm); // I know, ugly cast ...
+          }
+        }
+   };
+
+} // end namespace MEDCoupling
 
 %extend MEDCoupling::ParaMESH
 {
@@ -330,3 +395,19 @@ if MEDCouplingUse64BitIDs():
 else:
   ParaDataArrayInt = ParaDataArrayInt32
 %}
+
+%pythoncode %{
+
+# And here we use mpi4py ability to provide its internal (C++) pointer to the communicator:
+def _InterpKernelDEC_WithComm_internal(src_procs, tgt_procs, mpicomm):
+  from mpi4py import MPI
+  return InterpKernelDEC._NewWithComm_internal(src_procs, tgt_procs, MPI._addressof(mpicomm))
+
+def _OverlapDEC_WithComm_internal(procs, mpicomm):
+  from mpi4py import MPI
+  return OverlapDEC._NewWithComm_internal(procs, MPI._addressof(mpicomm))
+
+InterpKernelDEC.NewWithCustomComm = _InterpKernelDEC_WithComm_internal
+OverlapDEC.NewWithCustomComm = _OverlapDEC_WithComm_internal
+
+%}
index ef68d76a063972e6f1559b830f0ad008128ed6da..79f8686b4698b6a022d9fcdca164ad52eb92f001 100755 (executable)
@@ -101,7 +101,8 @@ class ParaMEDMEM_IK_DEC_Tests(unittest.TestCase):
         interface = CommInterface()
         source_group = MPIProcessorGroup(interface, procs_source)
         target_group = MPIProcessorGroup(interface, procs_target)
-        idec = InterpKernelDEC(source_group, target_group)
+        #idec = InterpKernelDEC(source_group, target_group)
+        idec = InterpKernelDEC.NewWithCustomComm(procs_source, procs_target, MPI.COMM_WORLD)
 
         # Write out full size meshes/fields for inspection
         if rank == 0:
index 48df8f4dc17051c1b63cdb467b2786ce774abdaf..3cbc2ffc374802bde4327454d9e813bf30407d4f 100755 (executable)
@@ -98,7 +98,8 @@ class ParaMEDMEM_O_DEC_Tests(unittest.TestCase):
 
         # Define (single) processor group - note the difference with InterpKernelDEC which needs two groups.
         proc_group = list(range(size))   # No need for ProcessorGroup object here.
-        odec = OverlapDEC(proc_group)
+        #odec = OverlapDEC(proc_group)
+        odec = OverlapDEC.NewWithCustomComm(proc_group, MPI.COMM_WORLD)
 
         # Write out full size meshes/fields for inspection
         if rank == 0:
index 94ab53ebd7d4dfe3905314bdbdad4dc05097c8e2..5bf9f8181c7991d357afe35b5cc43657e768674b 100644 (file)
@@ -36,10 +36,6 @@ SET(SWIG_MODULE_medcoupling_EXTRA_FLAGS "${NUMPY_DEFINITIONS};${SCIPY_DEFINITION
 IF(MEDCOUPLING_USE_64BIT_IDS)
   STRING(APPEND SWIG_MODULE_medcoupling_EXTRA_FLAGS ";-DMEDCOUPLING_USE_64BIT_IDS")
 ENDIF(MEDCOUPLING_USE_64BIT_IDS)
-IF(MEDCOUPLING_MPI4PY_DIR)
-  INCLUDE_DIRECTORIES(${MEDCOUPLING_MPI4PY_INCLUDE_DIR})
-  STRING(APPEND SWIG_MODULE_medcoupling_EXTRA_FLAGS ";-DMEDCOUPLING_MPI4PY_I_FILE=${MEDCOUPLING_MPI4PY_I_FILE}")
-ENDIF()
 
 SET(medcoupling_SWIG_DPYS_FILES medcoupling.i)