From 854847eb9e207d06fa8f54b2e372814ecb9aadf6 Mon Sep 17 00:00:00 2001 From: Anthony Geay Date: Fri, 10 Feb 2023 17:06:55 +0100 Subject: [PATCH] [EDF26936] : End of the 2GB limit. --- idl/SALOME_Comm.idl | 8 ++++++ idl/SALOME_PyNode.idl | 3 +- src/Communication/ReceiverFactory.cxx | 40 +++++++++++++++++++++++++++ src/Communication/ReceiverFactory.hxx | 17 ++++++++++++ src/Container/SALOME_PyNode.py | 15 +++++++++- 5 files changed, 81 insertions(+), 2 deletions(-) diff --git a/idl/SALOME_Comm.idl b/idl/SALOME_Comm.idl index bf9f782b8..911629531 100644 --- a/idl/SALOME_Comm.idl +++ b/idl/SALOME_Comm.idl @@ -40,6 +40,8 @@ module SALOME { typedef sequence vectorOfLong; + typedef sequence vectorOfByte; + interface MultiCommClass { void setProtocol(in TypeOfCommunication typ); }; @@ -132,6 +134,12 @@ module SALOME { long getSizeOfColumn(); void release(); }; + + interface SenderByte + { + unsigned long getSize(); + vectorOfByte sendPart(in unsigned long n1,in unsigned long n2); + }; }; #endif diff --git a/idl/SALOME_PyNode.idl b/idl/SALOME_PyNode.idl index 23a2b4709..58e9d3898 100644 --- a/idl/SALOME_PyNode.idl +++ b/idl/SALOME_PyNode.idl @@ -26,6 +26,7 @@ #include "SALOME_GenericObj.idl" #include "SALOME_Exception.idl" +#include "SALOME_Comm.idl" /*! \file SALOME_PyNode.idl \brief interface for remote python execution */ @@ -95,7 +96,7 @@ module Engines /*! \brief second and last part of execute method. This split is to reduce the memory peak. */ - pickledArgs executeSecond(in listofstring outargsname) raises (SALOME::SALOME_Exception); + SALOME::SenderByte executeSecond(in listofstring outargsname) raises (SALOME::SALOME_Exception); pickledArgs getValueOfVarInContext(in string varName) raises (SALOME::SALOME_Exception); diff --git a/src/Communication/ReceiverFactory.cxx b/src/Communication/ReceiverFactory.cxx index 5f354df8d..44ff3a0cd 100644 --- a/src/Communication/ReceiverFactory.cxx +++ b/src/Communication/ReceiverFactory.cxx @@ -186,3 +186,43 @@ int *ReceiverFactory::getValueOneShot(SALOME::SenderInt_ptr sender,long &size) } } +SeqByteReceiver::SeqByteReceiver(SALOME::SenderByte_ptr sender):_obj(SALOME::SenderByte::_duplicate(sender)) +{ +} + +char *SeqByteReceiver::data(unsigned long& size) +{ + size = _obj->getSize(); + if(size <= CHUNK_SIZE) + { + this->fetchOneShot( size ); + return reinterpret_cast(_data_one_shot->get_buffer()); + } + else + { + this->fetchByChunks( size ); + return _data_for_split_case.get(); + } +} + +void SeqByteReceiver::fetchOneShot(unsigned long size) +{ + _data_one_shot.reset( _obj->sendPart(0,size) ); +} + +void SeqByteReceiver::fetchByChunks(unsigned long size) +{ + _data_for_split_case.reset( new char[size] ); + char *destination = _data_for_split_case.get(); + constexpr unsigned long EFF_CHUNK_SIZE = CHUNK_SIZE / 8; + unsigned long iStart = 0; + unsigned long iEnd = EFF_CHUNK_SIZE; + while( iStart!=iEnd && iEnd <= size ) + { + std::unique_ptr part( _obj->sendPart(iStart,iEnd) ); + const unsigned char *partC = part->get_buffer(); + std::copy(partC,partC+(iEnd-iStart),destination+iStart); + iStart = iEnd; iEnd = std::min(iStart + EFF_CHUNK_SIZE,size); + } +} + diff --git a/src/Communication/ReceiverFactory.hxx b/src/Communication/ReceiverFactory.hxx index 03c8b873e..3d61b262f 100644 --- a/src/Communication/ReceiverFactory.hxx +++ b/src/Communication/ReceiverFactory.hxx @@ -43,5 +43,22 @@ private: static int *getValueOneShot(SALOME::SenderInt_ptr sender,long &size); }; +#include + +class COMMUNICATION_EXPORT SeqByteReceiver +{ +public: + SeqByteReceiver(SALOME::SenderByte_ptr sender); + char *data(unsigned long& size); +private: + void fetchOneShot(unsigned long size); + void fetchByChunks(unsigned long size); +private: + static constexpr unsigned long CHUNK_SIZE = 2000000000; + std::unique_ptr _data_for_split_case; + std::unique_ptr _data_one_shot; + SALOME::SenderByte_var _obj; +}; + #endif diff --git a/src/Container/SALOME_PyNode.py b/src/Container/SALOME_PyNode.py index 74bc948ee..1a0b3eb0b 100644 --- a/src/Container/SALOME_PyNode.py +++ b/src/Container/SALOME_PyNode.py @@ -103,6 +103,16 @@ class PyNode_i (Engines__POA.PyNode,Generic): l=traceback.format_exception(exc_typ,exc_val,exc_fr) raise SALOME.SALOME_Exception(SALOME.ExceptionStruct(SALOME.BAD_PARAM,"".join(l),"PyNode: %s, function: %s" % (self.nodeName,funcName),0)) +class SenderByte_i(SALOME__POA.SenderByte): + def __init__(self,bytesToSend): + self.bytesToSend = bytesToSend + + def getSize(self): + return len(self.bytesToSend) + + def sendPart(self,n1,n2): + return self.bytesToSend[n1:n2] + class PyScriptNode_i (Engines__POA.PyScriptNode,Generic): """The implementation of the PyScriptNode CORBA IDL that executes a script""" def __init__(self, nodeName,code,poa,my_container): @@ -183,7 +193,10 @@ class PyScriptNode_i (Engines__POA.PyScriptNode,Generic): raise KeyError("There is no variable %s in context" % arg) argsout.append(self.context[arg]) argsout=pickle.dumps(tuple(argsout),-1) - return argsout + ret = SenderByte_i( argsout ) + id_o = self.poa.activate_object(ret) + retObj = self.poa.id_to_reference(id_o) + return retObj._narrow( SALOME.SenderByte ) except Exception: exc_typ,exc_val,exc_fr=sys.exc_info() l=traceback.format_exception(exc_typ,exc_val,exc_fr) -- 2.39.2