Salome HOME
[EDF28562] : Possibility of exclusion output port of squeezeMemory mecanism in Python... emc2p/BR_V1_4_0 V9_12_0a1 V9_12_0a2 emc2p_1.4.0-rc1
authorGilles DAVID <gilles-g.david@edf.fr>
Wed, 13 Sep 2023 13:38:12 +0000 (15:38 +0200)
committerAnthony Geay <anthony.geay@edf.fr>
Wed, 13 Sep 2023 14:57:18 +0000 (16:57 +0200)
src/runtime/PythonNode.cxx
src/runtime/PythonNode.hxx
src/yacsloader_swig/Test/testYacsPerfTest0.py
src/yacsloader_swig/Test/testYacsProxy.py

index f82b88fe0a7a94f321f6509ee2a013f0a00a23ad..57a13a016448a21fbd9322d87bd9550823187f5d 100644 (file)
@@ -415,7 +415,8 @@ void PythonEntry::UnlinkOnDestructorIfProxy( PyObject *ob )
   IfProxyDoSomething(ob,"unlinkOnDestructor");
 }
 
-PythonNode::PythonNode(const PythonNode& other, ComposedNode *father):InlineNode(other,father),_autoSqueeze(other._autoSqueeze)
+PythonNode::PythonNode(const PythonNode& other, ComposedNode *father):
+InlineNode(other,father),_autoSqueeze(other._autoSqueeze),_nonSqueezableOutputNodes(other._nonSqueezableOutputNodes)
 {
   _pynode = Engines::PyScriptNode::_nil();
   _implementation=IMPL_NAME;
@@ -848,6 +849,16 @@ void PythonNode::executeLocal()
   DEBTRACE( "++++++++++++++ End PyNode::execute: " << getName() << " ++++++++++++++++++++" );
 }
 
+/*!
+ * [EDF28562]
+ * \param in squeezeExceptions list on output port name excluded from the squeeze mecanism
+ */
+void PythonNode::setSqueezeStatusWithExceptions(bool sqStatus, const std::vector<std::string>& squeezeExceptions)
+{
+  this->setSqueezeStatus(sqStatus);
+  this->_nonSqueezableOutputNodes = std::set<std::string>(squeezeExceptions.begin(), squeezeExceptions.end());
+}
+
 void PythonNode::squeezeMemorySafe()
 {
   AutoGIL agil;
@@ -868,6 +879,8 @@ void PythonNode::squeezeMemory()
     }
   for(auto p : _setOfOutputPort)
     {
+      if (!this->_nonSqueezableOutputNodes.empty() && this->_nonSqueezableOutputNodes.find(p->getName()) != this->_nonSqueezableOutputNodes.end())
+        continue;
       PyDict_DelItemString(_context,p->getName().c_str());
       OutputPyPort *p2(static_cast<OutputPyPort *>(p));
       p2->putWithoutForward(Py_None);
@@ -884,6 +897,8 @@ void PythonNode::squeezeMemoryRemote()
     }
   for(auto p : _setOfOutputPort)
     {
+      if (!this->_nonSqueezableOutputNodes.empty() && this->_nonSqueezableOutputNodes.find(p->getName()) != this->_nonSqueezableOutputNodes.end())
+        continue;
       OutputPyPort *p2(static_cast<OutputPyPort *>(p));
       p2->putWithoutForward(Py_None);
     }
index 49b6a2e7c136a4e7df630a4316a13048829cd2dd..2e1482dd94dd39e04d2d45ad2c55afd36c284d1f 100644 (file)
@@ -28,6 +28,8 @@
 
 #include <Python.h>
 
+#include <set>
+
 namespace YACS
 {
   namespace ENGINE
@@ -105,6 +107,7 @@ namespace YACS
       PythonNode* cloneNode(const std::string& name);
       virtual std::string typeName() { return "YACS__ENGINE__PythonNode"; }
       void applyDPLScope(ComposedNode *gfn);
+      void setSqueezeStatusWithExceptions(bool sqStatus, const std::vector<std::string>& squeezeExceptions);
       void setSqueezeStatus(bool sqStatus) { _autoSqueeze=sqStatus; }
       bool getSqueezeStatus() const { return _autoSqueeze; }
       void squeezeMemorySafe();
@@ -123,6 +126,8 @@ namespace YACS
       static const char DPL_INFO_NAME[];
     protected:
       bool _autoSqueeze = false;
+      //! list on output port name excluded from the squeeze mecanism
+      std::set<std::string> _nonSqueezableOutputNodes;
       Engines::PyScriptNode_var _pynode;
     };
 
index 296e436307a9c78d71106235835a9fcdada8bd71..deda46ad6dfd8223fb9f8f9cdb161f6ecff8d465 100644 (file)
@@ -96,10 +96,80 @@ ret = 3*ppp
         ex=pilot.ExecutorSwig()
         ex.setMaxNbOfThreads(NB_OF_PARALLEL_THREADS)
         ex.RunW(p,0)
+        self.assertEqual(p.getState(),pilot.DONE)
         salome.cm.ShutdownContainers()
         print("End of computation {}".format( str(datetime.datetime.now()-st) ) )
         if p.getChildByName("end").getOutputPort("ozeret").getPyObj() != [3*i for i in range(NB_OF_PARALLEL_NODES)]:
             raise RuntimeError("Ooops")
+        
+    def test1(self):
+        """
+        [EDF28562] : test of exclusion output port of squeezeMemory mecanism
+        """
+        salome.salome_init()
+        import KernelBasis
+        KernelBasis.SetVerbosityActivated(False)
+        SALOMERuntime.RuntimeSALOME.setRuntime()
+        r=SALOMERuntime.getSALOMERuntime()
+        p=r.createProc("Squeeze")
+        pyobj=p.createInterfaceTc("python:obj:1.0","pyobj",[])
+        cont=p.createContainer("gg","Salome")
+        cont.setProperty("nb_parallel_procs","1")
+        cont.setAttachOnCloningStatus(True)
+        cont.setProperty("attached_on_cloning","1")
+        cont.setProperty("type","multi")
+        cont.setProperty("container_name","gilles")
+        startNode = r.createScriptNode("Salome","startNode")
+        startNode.setExecutionMode("remote")
+        startNode.setContainer(cont)
+        startNode.setSqueezeStatus(True)
+        startNode.setScript("""
+o1,o2,o3,o4 = 31,32,33,34
+""")
+        o1 = startNode.edAddOutputPort("o1",pyobj)
+        o2 = startNode.edAddOutputPort("o2",pyobj)
+        o3 = startNode.edAddOutputPort("o3",pyobj)
+        o4 = startNode.edAddOutputPort("o4",pyobj)
+        p.edAddChild(startNode)
+        endNode = r.createScriptNode("Salome","endNode")
+        endNode.setExecutionMode("remote")
+        endNode.setContainer(cont)
+        endNode.setSqueezeStatus(True)
+        endNode.setScript("""
+o5,o6 = 45,46
+""")
+        o5 = endNode.edAddOutputPort("o5",pyobj)
+        o6 = endNode.edAddOutputPort("o6",pyobj)
+        p.edAddChild(endNode)
+        p.edAddCFLink(startNode,endNode)
+        # disable proxy
+        salome.cm.SetOverrideEnvForContainersSimple([("SALOME_BIG_OBJ_ON_DISK_THRES","-1")])
+        # First part squeeze. 
+        ex=pilot.ExecutorSwig()
+        ex.RunW(p,0)
+        self.assertEqual(p.getState(),pilot.DONE)
+        for outp in ["o1","o2","o3","o4"]:
+            self.assertTrue( p.getChildByName("startNode").getOutputPort(outp).getPyObj() is None )
+        for outp in ["o5","o6"]:
+            self.assertTrue( p.getChildByName("endNode").getOutputPort(outp).getPyObj() is None )
+        #### Now it s time
+        #KernelBasis.SetVerbosityActivated(True)
+        startNode.setSqueezeStatusWithExceptions(True,["o1","o3"])#<- The key point is here
+        endNode.setSqueezeStatusWithExceptions(True,["o5"])#<- The key point is here
+        ex=pilot.ExecutorSwig()
+        ex.RunW(p,0)
+        self.assertEqual(p.getState(),pilot.DONE)
+        salome.cm.ShutdownContainers()
+        for outp in ["o2","o4"]:
+            self.assertTrue( p.getChildByName("startNode").getOutputPort(outp).getPyObj() is None )
+        for outp in ["o6"]:
+            self.assertTrue( p.getChildByName("endNode").getOutputPort(outp).getPyObj() is None )
+        #
+        for outp,valExp in [("o1",31),("o3",33)]:
+            self.assertEqual( p.getChildByName("startNode").getOutputPort(outp).getPyObj(), valExp )
+        for outp,valExp in [("o5",45)]:
+            self.assertEqual( p.getChildByName("endNode").getOutputPort(outp).getPyObj(), valExp )
+
 
 if __name__ == '__main__':
   with tempfile.TemporaryDirectory() as dir_test:
index 9ad528c1d76da53d6e2f71005b330dd6e5fb160c..5fbe79718a7f39ba08d58967063e7ad78bafc2b5 100755 (executable)
@@ -138,7 +138,7 @@ o7 = i7""")
 
       pp = p
       fname = "stressTest3.xml"
-      pp.saveSchema(fname)
+      #pp.saveSchema(fname)
       ####
       l=loader.YACSLoader()
       #p=l.load(fname)