From: Gilles DAVID Date: Wed, 13 Sep 2023 13:38:12 +0000 (+0200) Subject: [EDF28562] : Possibility of exclusion output port of squeezeMemory mecanism in Python... X-Git-Tag: emc2p_1.4.0-rc1^0 X-Git-Url: http://git.salome-platform.org/gitweb/?p=modules%2Fyacs.git;a=commitdiff_plain;h=d4af5aa95ba95d6e4b301323050ccd0d843d67a8 [EDF28562] : Possibility of exclusion output port of squeezeMemory mecanism in PythonNodes --- diff --git a/src/runtime/PythonNode.cxx b/src/runtime/PythonNode.cxx index f82b88fe0..57a13a016 100644 --- a/src/runtime/PythonNode.cxx +++ b/src/runtime/PythonNode.cxx @@ -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& squeezeExceptions) +{ + this->setSqueezeStatus(sqStatus); + this->_nonSqueezableOutputNodes = std::set(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(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(p)); p2->putWithoutForward(Py_None); } diff --git a/src/runtime/PythonNode.hxx b/src/runtime/PythonNode.hxx index 49b6a2e7c..2e1482dd9 100644 --- a/src/runtime/PythonNode.hxx +++ b/src/runtime/PythonNode.hxx @@ -28,6 +28,8 @@ #include +#include + 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& 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 _nonSqueezableOutputNodes; Engines::PyScriptNode_var _pynode; }; diff --git a/src/yacsloader_swig/Test/testYacsPerfTest0.py b/src/yacsloader_swig/Test/testYacsPerfTest0.py index 296e43630..deda46ad6 100644 --- a/src/yacsloader_swig/Test/testYacsPerfTest0.py +++ b/src/yacsloader_swig/Test/testYacsPerfTest0.py @@ -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: diff --git a/src/yacsloader_swig/Test/testYacsProxy.py b/src/yacsloader_swig/Test/testYacsProxy.py index 9ad528c1d..5fbe79718 100755 --- a/src/yacsloader_swig/Test/testYacsProxy.py +++ b/src/yacsloader_swig/Test/testYacsProxy.py @@ -138,7 +138,7 @@ o7 = i7""") pp = p fname = "stressTest3.xml" - pp.saveSchema(fname) + #pp.saveSchema(fname) #### l=loader.YACSLoader() #p=l.load(fname)