From: secher Date: Wed, 20 Jul 2005 11:42:43 +0000 (+0000) Subject: last version after merge X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=refs%2Fheads%2FBR_V300_lcrm;p=modules%2Fkernel.git last version after merge --- diff --git a/idl/SALOME_MPIContainer.idl b/idl/SALOME_MPIContainer.idl index dfe23ec5e..13e135f6b 100644 --- a/idl/SALOME_MPIContainer.idl +++ b/idl/SALOME_MPIContainer.idl @@ -32,6 +32,8 @@ module Engines interface MPIContainer:Container,MPIObject { // asynchronous version to load and remove parallel component in parallel + oneway void Asload_component_Library(in string componentName); + oneway void Ascreate_component_instance(in string componentName,in long studyId); oneway void Asload_impl(in string nameToRegister, in string componentName); oneway void Asremove_impl(in Component component_i); oneway void Asfinalize_removal(); diff --git a/src/Container/SALOME_Container_i.hxx b/src/Container/SALOME_Container_i.hxx index d64dd22a0..c6135bb8d 100644 --- a/src/Container/SALOME_Container_i.hxx +++ b/src/Container/SALOME_Container_i.hxx @@ -58,9 +58,9 @@ public: // --- CORBA methods - bool load_component_Library(const char* componentName); + virtual bool load_component_Library(const char* componentName); - Engines::Component_ptr + virtual Engines::Component_ptr create_component_instance( const char* componentName, CORBA::Long studyId); // 0 for multiStudy diff --git a/src/MPIContainer/MPIContainer_i.cxx b/src/MPIContainer/MPIContainer_i.cxx index 97e6bcffa..3b97ad793 100644 --- a/src/MPIContainer/MPIContainer_i.cxx +++ b/src/MPIContainer/MPIContainer_i.cxx @@ -27,11 +27,14 @@ #include #include #include +#include "SALOME_Component_i.hxx" #include "MPIContainer_i.hxx" #include "SALOME_NamingService.hxx" #include "Utils_SINGLETON.hxx" #include "OpUtil.hxx" #include "utilities.h" +#include +#include "Container_init_python.hxx" using namespace std; // L'appel au registry SALOME ne se fait que pour le process 0 @@ -79,14 +82,295 @@ Engines_MPIContainer_i::~Engines_MPIContainer_i(void) } // Load component -Engines::Component_ptr Engines_MPIContainer_i::load_impl(const char* nameToRegister, - const char* componentName) +void Engines_MPIContainer_i::Shutdown() { int ip; + MESSAGE("[" << _numproc << "] shutdown of MPI Corba Server"); + if( _numproc == 0 ){ + _NS->Destroy_FullDirectory(_containerName.c_str()); + for(ip= 1;ip<_nbproc;ip++) + (Engines::MPIContainer::_narrow((*_tior)[ip]))->Shutdown(); + } + _orb->shutdown(0); +} + +// Load a component library +bool Engines_MPIContainer_i::load_component_Library(const char* componentName) +{ if( _numproc == 0 ){ // Invocation du chargement du composant dans les autres process - for(ip= 1;ip<_nbproc;ip++) + for(int ip= 1;ip<_nbproc;ip++) + (Engines::MPIContainer::_narrow((*_tior)[ip]))->Asload_component_Library(componentName); + } + + return Lload_component_Library(componentName); +} + +void Engines_MPIContainer_i::Asload_component_Library(const char* componentName) +{ + Lload_component_Library(componentName); +} + +bool Engines_MPIContainer_i::Lload_component_Library(const char* componentName) +{ + string aCompName = componentName; + + // --- try dlopen C++ component + + string impl_name = string ("lib") + aCompName + string("Engine.so"); + SCRUTE(impl_name); + + _numInstanceMutex.lock(); // lock to be alone + // (see decInstanceCnt, finalize_removal)) + if (_toRemove_map[impl_name]) _toRemove_map.erase(impl_name); + if (_library_map[impl_name]) + { + MESSAGE("[" << _numproc << "] Library " << impl_name << " already loaded"); + _numInstanceMutex.unlock(); + return true; + } + + void* handle; + handle = dlopen( impl_name.c_str() , RTLD_LAZY ) ; + if ( handle ) + { + _library_map[impl_name] = handle; + _numInstanceMutex.unlock(); + return true; + } + else + { + INFOS("[" << _numproc << "] Can't load shared library : " << impl_name); + INFOS("[" << _numproc << "] error dlopen: " << dlerror()); + } + _numInstanceMutex.unlock(); + + // --- try import Python component + + INFOS("[" << _numproc << "] try import Python component "<Ascreate_component_instance(componentName,studyId); + } + + return Lcreate_component_instance(componentName,studyId); +} + +void Engines_MPIContainer_i::Ascreate_component_instance( const char* componentName, + CORBA::Long studyId) +{ + Lcreate_component_instance(componentName,studyId); +} + +Engines::Component_ptr +Engines_MPIContainer_i::Lcreate_component_instance( const char* genericRegisterName, CORBA::Long studyId) +{ + if (studyId < 0) { + INFOS("studyId must be > 0 for mono study instance, =0 for multiStudy"); + return Engines::Component::_nil() ; + } + + Engines::Component_var iobject = Engines::Component::_nil() ; + Engines::MPIObject_var pobj; + + string aCompName = genericRegisterName; + if (_library_map[aCompName]) { // Python component + if (_isSupervContainer) { + INFOS("Supervision Container does not support Python Component Engines"); + return Engines::Component::_nil(); + } + _numInstanceMutex.lock() ; // lock on the instance number + _numInstance++ ; + int numInstance = _numInstance ; + _numInstanceMutex.unlock() ; + + char aNumI[12]; + sprintf( aNumI , "%d" , numInstance ) ; + string instanceName = aCompName + "_inst_" + aNumI ; + string component_registerName = + _containerName + "/" + instanceName; + + Py_ACQUIRE_NEW_THREAD; + PyObject *mainmod = PyImport_AddModule("__main__"); + PyObject *globals = PyModule_GetDict(mainmod); + PyObject *pyCont = PyDict_GetItemString(globals, "pyCont"); + PyObject *result = PyObject_CallMethod(pyCont, + "create_component_instance", + "ssl", + aCompName.c_str(), + instanceName.c_str(), + studyId); + string iors = PyString_AsString(result); + SCRUTE(iors); + Py_RELEASE_NEW_THREAD; + + CORBA::Object_var obj = _orb->string_to_object(iors.c_str()); + iobject = Engines::Component::_narrow( obj ) ; + pobj = Engines::MPIObject::_narrow(obj) ; + if( _numproc == 0 ) + _NS->Register(iobject, component_registerName.c_str()) ; + // Root recupere les ior des composants des autre process + BCastIOR(_orb,pobj,false); + + return iobject._retn(); + } + + //--- try C++ + + string impl_name = string ("lib") + genericRegisterName +string("Engine.so"); + void* handle = _library_map[impl_name]; + if ( !handle ) { + INFOS("shared library " << impl_name <<"must be loaded before instance"); + return Engines::Component::_nil() ; + } + else { + iobject = createMPIInstance(genericRegisterName, + handle, + studyId); + return iobject._retn(); + } +} + +Engines::Component_ptr +Engines_MPIContainer_i::createMPIInstance(string genericRegisterName, + void *handle, + int studyId) +{ + Engines::Component_var iobject; + Engines::MPIObject_var pobj; + // --- find the factory + + string aGenRegisterName = genericRegisterName; + string factory_name = aGenRegisterName + string("Engine_factory"); + SCRUTE(factory_name) ; + + typedef PortableServer::ObjectId * (*MPIFACTORY_FUNCTION) + (int,int, + CORBA::ORB_ptr, + PortableServer::POA_ptr, + PortableServer::ObjectId *, + const char *, + const char *) ; + + MPIFACTORY_FUNCTION MPIComponent_factory + = (MPIFACTORY_FUNCTION) dlsym(handle, factory_name.c_str()); + + char *error ; + if ( (error = dlerror() ) != NULL) { + // Try to load a sequential component + MESSAGE("[" << _numproc << "] Try to load a sequential component"); + _numInstanceMutex.unlock() ; + iobject = Engines_Container_i::createInstance(genericRegisterName,handle,studyId); + if( CORBA::is_nil(iobject) ) return Engines::Component::_duplicate(iobject); + } + + // --- create instance + + iobject = Engines::Component::_nil() ; + + try + { + _numInstanceMutex.lock() ; // lock on the instance number + _numInstance++ ; + int numInstance = _numInstance ; + _numInstanceMutex.unlock() ; + + char aNumI[12]; + sprintf( aNumI , "%d" , numInstance ) ; + string instanceName = aGenRegisterName + "_inst_" + aNumI ; + string component_registerName = + _containerName + "/" + instanceName; + + // --- Instanciate required CORBA object + + PortableServer::ObjectId *id ; //not owner, do not delete (nore use var) + id = (MPIComponent_factory) ( _nbproc,_numproc,_orb, _poa, _id, instanceName.c_str(), + aGenRegisterName.c_str() ) ; + + // --- get reference & servant from id + + CORBA::Object_var obj = _poa->id_to_reference(*id); + iobject = Engines::Component::_narrow( obj ) ; + pobj = Engines::MPIObject::_narrow(obj) ; + + Engines_Component_i *servant = + dynamic_cast(_poa->reference_to_servant(iobject)); + ASSERT(servant); + //SCRUTE(servant->pd_refCount); + servant->_remove_ref(); // compensate previous id_to_reference + //SCRUTE(servant->pd_refCount); + _listInstances_map[instanceName] = iobject; + _cntInstances_map[aGenRegisterName] += 1; + SCRUTE(aGenRegisterName); + SCRUTE(_cntInstances_map[aGenRegisterName]); + //SCRUTE(servant->pd_refCount); + bool ret_studyId = servant->setStudyId(studyId); + ASSERT(ret_studyId); + + // --- register the engine under the name + // containerName(.dir)/instanceName(.object) + + if( _numproc == 0 ){ + _NS->Register( iobject , component_registerName.c_str() ) ; + MESSAGE( component_registerName.c_str() << " bound" ) ; + } + // Root recupere les ior des composants des autre process + BCastIOR(_orb,pobj,false); + + } + catch (...) + { + INFOS( "Container_i::createInstance exception catched" ) ; + } + return iobject._retn(); +} + +// Load component +Engines::Component_ptr Engines_MPIContainer_i::load_impl(const char* nameToRegister, + const char* componentName) +{ + if( _numproc == 0 ){ + // Invocation du chargement du composant dans les autres process + for(int ip= 1;ip<_nbproc;ip++) (Engines::MPIContainer::_narrow((*_tior)[ip]))->Asload_impl(nameToRegister, componentName); } @@ -268,18 +552,3 @@ void Engines_MPIContainer_i::Lfinalize_removal() END_OF("[" << _numproc << "] MPIContainer_i::Lfinalize_removal"); } - -// Load component -void Engines_MPIContainer_i::Shutdown() -{ - int ip; - MESSAGE("[" << _numproc << "] shutdown of MPI Corba Server"); - if( _numproc == 0 ){ - _NS->Destroy_FullDirectory(_containerName.c_str()); - for(ip= 1;ip<_nbproc;ip++) - (Engines::MPIContainer::_narrow((*_tior)[ip]))->Shutdown(); - } - _orb->shutdown(0); - -} - diff --git a/src/MPIContainer/MPIContainer_i.hxx b/src/MPIContainer/MPIContainer_i.hxx index a805639a1..a73af8b38 100644 --- a/src/MPIContainer/MPIContainer_i.hxx +++ b/src/MPIContainer/MPIContainer_i.hxx @@ -48,13 +48,28 @@ class Engines_MPIContainer_i : public POA_Engines::MPIContainer, // Destructor ~Engines_MPIContainer_i(); + // shutdown corba server + void Shutdown(); + + // Load a component library + // synchronous version for process 0 + bool load_component_Library(const char* componentName); + // asynchronous version for other process + void Asload_component_Library(const char* componentName); + + // Create an instance of component + // synchronous version for process 0 + Engines::Component_ptr + create_component_instance( const char* componentName, + CORBA::Long studyId); // 0 for multiStudy + // asynchronous version for other process + void Ascreate_component_instance( const char* componentName, + CORBA::Long studyId); // 0 for multiStudy + // Load a component in current MPI container // synchronous version for process 0 Engines::Component_ptr load_impl(const char* nameToRegister, const char* componentName); - // shutdown corba server - void Shutdown(); - // asynchronous version for other process void Asload_impl(const char* nameToRegister, const char* componentName); @@ -72,10 +87,19 @@ class Engines_MPIContainer_i : public POA_Engines::MPIContainer, private: // local version to not duplicate code // called by synchronous and asynchronous version + bool Lload_component_Library(const char* componentName); + Engines::Component_ptr + Lcreate_component_instance( const char* componentName, + CORBA::Long studyId); // 0 for multiStudy Engines::Component_ptr Lload_impl(const char* nameToRegister, const char* componentName); void Lremove_impl(Engines::Component_ptr component_i); void Lfinalize_removal(); + Engines::Component_ptr + createMPIInstance(std::string genericRegisterName, + void *handle, + int studyId); + }; #endif diff --git a/src/MPIContainer/Makefile.in b/src/MPIContainer/Makefile.in index ad437b005..af110328f 100644 --- a/src/MPIContainer/Makefile.in +++ b/src/MPIContainer/Makefile.in @@ -52,12 +52,13 @@ BIN = SALOME_MPIContainer BIN_SRC = BIN_SERVER_IDL = SALOME_MPIObject.idl SALOME_MPIContainer.idl +CPPFLAGS+= $(PYTHON_INCLUDES) LDFLAGS+= -lSalomeContainer -lSalomeNS -lRegistry -lOpUtil -lSalomeNotification -lSALOMELocalTrace -lSalomeResourcesManager ifeq (@WITHMPI@,yes) + LIBS += $(PYTHON_LIBS) $(MPI_LIBS) CXXFLAGS+=${MPI_INCLUDES} CXX_DEPEND_FLAG+=${MPI_INCLUDES} - LDFLAGS+= ${MPI_LIBS} LDFLAGSFORBIN= $(LDFLAGS) -lSALOMETraceCollector LIBSFORBIN= $(LIBS) endif diff --git a/src/NamingService/SALOME_NamingService.cxx b/src/NamingService/SALOME_NamingService.cxx index 4cae11af8..bca86ef09 100644 --- a/src/NamingService/SALOME_NamingService.cxx +++ b/src/NamingService/SALOME_NamingService.cxx @@ -452,7 +452,7 @@ CORBA::Object_ptr SALOME_NamingService::ResolveComponent(const char* hostname, c name += containerName; name += "/"; name += componentName; - return Resolve(name.c_str()); + return ResolveFirst(name.c_str()); } else { Change_Directory(name.c_str()); @@ -461,7 +461,7 @@ CORBA::Object_ptr SALOME_NamingService::ResolveComponent(const char* hostname, c name = contList[ind].c_str(); name += "/"; name += componentName; - CORBA::Object_ptr obj = Resolve(name.c_str()); + CORBA::Object_ptr obj = ResolveFirst(name.c_str()); if( !CORBA::is_nil(obj) ) return obj; } diff --git a/src/ResourcesManager/SALOME_ResourcesManager.cxx b/src/ResourcesManager/SALOME_ResourcesManager.cxx index 8edf5a264..c3a339e18 100644 --- a/src/ResourcesManager/SALOME_ResourcesManager.cxx +++ b/src/ResourcesManager/SALOME_ResourcesManager.cxx @@ -220,14 +220,12 @@ string SALOME_ResourcesManager::BuildTempFileToLaunchRemoteContainer(const strin } tempOutputFile << (*(resInfo.ModulesPath.find("KERNEL"))).second << "/bin/salome/"; if(params.isMPI){ - cout << "PARALLELE" << endl; if(Engines_Container_i::isPythonContainer(params.container_name)) tempOutputFile << "pyMPI SALOME_ContainerPy.py "; else tempOutputFile << "SALOME_MPIContainer "; } else{ - cout << "SEQUENTIEL" << endl; if(Engines_Container_i::isPythonContainer(params.container_name)) tempOutputFile << "SALOME_ContainerPy.py "; else