1 //=============================================================================
2 // File : SALOME_MPILifeCycleCORBA.cxx
3 // Created : mar jui 03 14:55:50 CEST 2003
4 // Author : Bernard SECHER CEA
6 // Copyright : CEA 2003
8 //=============================================================================
18 #include "utilities.h"
20 #include <ServiceUnreachable.hxx>
22 #include "SALOME_MPILifeCycleCORBA.hxx"
23 #include CORBA_CLIENT_HEADER(SALOME_ModuleCatalog)
24 #include "SALOME_NamingService.hxx"
27 SALOME_MPILifeCycleCORBA::SALOME_MPILifeCycleCORBA() :
28 SALOME_LifeCycleCORBA()
30 _MPIFactoryServer = NULL;
33 SALOME_MPILifeCycleCORBA::SALOME_MPILifeCycleCORBA(SALOME_NamingService *ns) :
34 SALOME_LifeCycleCORBA(ns)
36 _MPIFactoryServer = NULL;
39 SALOME_MPILifeCycleCORBA::~SALOME_MPILifeCycleCORBA()
43 Engines::MPIContainer_var SALOME_MPILifeCycleCORBA::FindOrStartMPIContainer(
44 const std::string theComputer ,
45 const std::string theMPIContainerRoot,
50 sprintf(nbp,"_%d",nbproc);
51 std::string theMPIContainer = theMPIContainerRoot + nbp;
52 std::string aComputerContainer = theComputer + "/" + theMPIContainer;
54 SCRUTE( aComputerContainer ) ;
55 SCRUTE( theComputer ) ;
56 SCRUTE( theMPIContainer ) ;
58 // On recherche si le containe rest deja lance
59 Engines::MPIContainer_var aMPIContainer = Engines::MPIContainer::_narrow(FindContainer(aComputerContainer.c_str()));
61 //On a trouve le container: on renvoie une poigne dessus
62 if ( !CORBA::is_nil( aMPIContainer ) ) {
63 MESSAGE("MPIContainer " << aComputerContainer << " found!!!");
64 return aMPIContainer ;
66 // On a pas trouve le container
68 MESSAGE("MPIContainer " << aComputerContainer << " not found!!!");
69 // On recherche un container generique
71 int len = theMPIContainer.length() ;
72 if ( !strcmp( &theMPIContainerRoot.c_str()[len-2] , "Py" ) ) {
75 std::string MPIFactoryServer = theComputer ;
77 MPIFactoryServer += "/MPIFactoryServerPy" ;
80 MPIFactoryServer += "/MPIFactoryServer" ;
82 MPIFactoryServer += nbp;
83 Engines::MPIContainer_var aMPIFactoryServer = Engines::MPIContainer::_narrow(FindContainer( MPIFactoryServer.c_str()));
85 // On n'a pas trouve le container generique: on lance le container demande
86 if ( CORBA::is_nil( aMPIFactoryServer ) ) {
87 // rsh -n ikkyo /export/home/rahuel/SALOME_ROOT/bin/runSession SALOME_Container -ORBInitRef NameService=corbaname::dm2s0017:1515 &
88 std::string rsh( "" ) ;
89 if ( theComputer!= GetHostname() ) {
94 std::string path = ComputerPath( theComputer.c_str() ) ;
96 // rsh += "runSession " ;
98 MESSAGE("MPI python container not implemented");
99 return Engines::MPIContainer::_nil();
100 // rsh += "SALOME_MPIContainerPy.py " ;
101 // rsh += "MPIFactoryServerPy -" ;
104 sprintf(nbp,"mpirun -np %d %sSALOME_MPIContainer ",nbproc,path.c_str());
106 rsh += theMPIContainer +" -" ;
108 std::string omniORBcfg( getenv( "OMNIORB_CONFIG" ) ) ;
109 ifstream omniORBfile( omniORBcfg.c_str() ) ;
110 char ORBInitRef[12] ;
111 char nameservice[132] ;
112 omniORBfile >> ORBInitRef ;
115 omniORBfile >> nameservice ;
116 omniORBfile.close() ;
117 char * bsn = strchr( nameservice , '\n' ) ;
123 rsh += " > /tmp/MPIFactoryServerPy_" ;
126 rsh += " > /tmp/MPIFactoryServer_" ;
128 sprintf(nbp,"%d_",nbproc);
131 rsh += ".log 2>&1 &" ;
133 int status = system( rsh.c_str() ) ;
135 INFOS("SALOME_MPILifeCycleCORBA::FindOrStartMPIContainer rsh failed (system command status -1)") ;
137 else if (status == 217) {
138 INFOS("SALOME_MPILifeCycleCORBA::FindOrStartContainer rsh failed (system command status 217)") ;
142 while ( CORBA::is_nil( aMPIFactoryServer ) && count ) {
146 MESSAGE( count << ". Waiting for FactoryServer on " << theComputer)
147 aMPIFactoryServer = Engines::MPIContainer::_narrow(FindContainer( MPIFactoryServer.c_str()));
149 if ( CORBA::is_nil( aMPIFactoryServer ) ) {
150 INFOS("SALOME_MPILifeCycleCORBA::FindOrStartMPIContainer rsh failed") ;
152 else if ( strcmp( theComputer.c_str() , GetHostname().c_str() ) ) {
153 _MPIFactoryServer = aMPIFactoryServer ;
157 // On a trouve le container generique distant: on se sert de lui
158 // pour lancer un nouveau container MPI
160 if ( !CORBA::is_nil( aMPIFactoryServer ) ) {
161 if ( strcmp( theMPIContainer.c_str() , "MPIFactoryServer" ) ||
162 strcmp( theMPIContainer.c_str() , "MPIFactoryServerPy" ) ) {
163 MESSAGE("MPI Container not found ! trying to start " << aComputerContainer);
164 Engines::MPIContainer_var myMPIContainer = aMPIFactoryServer->start_MPIimpl( theMPIContainer.c_str(), nbproc ) ;
165 if ( !CORBA::is_nil( myMPIContainer ) ) {
166 MESSAGE("MPIContainer " << aComputerContainer << " started");
167 return myMPIContainer ;
170 MESSAGE("MPIContainer " << aComputerContainer << " NOT started");
174 MESSAGE("MPIContainer " << aComputerContainer << " started");
175 return aMPIFactoryServer ;
179 return Engines::MPIContainer::_nil();
182 // Engines::Component_var SALOME_MPILifeCycleCORBA::FindOrLoad_MPIComponent
183 // (const char *MPIcontainerName,
184 // const char *MPIcomponentName,
185 // const char *implementation,
188 // BEGIN_OF("FindOrLoad_MPIComponent(1)");
189 // ASSERT(_NS != NULL);
190 // string theComputer ;
191 // string theMPIContainer ;
192 // string theComputerContainer = ContainerName( MPIcontainerName ,
194 // &theMPIContainer ) ;
195 // Engines::MPIContainer_var cont = FindOrStartMPIContainer( theComputerContainer ,
199 // // ASSERT(!CORBA::is_nil(cont));
201 // string path( theComputerContainer );
202 // path = path + "/";
203 // path = path + MPIcomponentName;
207 // CORBA::Object_var obj = _NS->Resolve(path.c_str());
208 // if (CORBA::is_nil(obj))
210 // MESSAGE("MPIComponent not found ! trying to load " << path);
211 // Engines::Component_var compo
212 // = cont->load_impl(MPIcomponentName, implementation);
213 // // ASSERT(!CORBA::is_nil(compo));
214 // MESSAGE("MPIComponent launched !" << path);
219 // MESSAGE("MPIComponent found !" << path);
220 // Engines::Component_var compo = Engines::Component::_narrow(obj);
221 // // ASSERT(!CORBA::is_nil(compo));
226 // catch (CORBA::COMM_FAILURE&)
228 // INFOS("Caught CORBA::SystemException CommFailure. Engine "
229 // << path << "does not respond" );
234 // catch (ServiceUnreachable&)
236 // INFOS("Caught exception: Naming Service Unreachable");
240 // INFOS("Caught unknown exception.");
242 // return Engines::Component::_nil();
245 Engines::Component_var SALOME_MPILifeCycleCORBA::FindOrLoad_MPIComponent
246 (const char *MPIcontainerName,
247 const char *MPIcomponentName,
253 sprintf(nbp,"_%d",nbproc);
254 // BEGIN_OF("FindOrLoad_Component(2)");
257 string theMPIContainerRoot ;
258 string theMPIContainer;
259 string theComputerContainer = ContainerName( MPIcontainerName ,
261 &theMPIContainerRoot ) ;
262 theMPIContainer = theMPIContainerRoot + nbp;
263 Engines::MPIContainer_var cont = FindOrStartMPIContainer( theComputer ,
267 if ( CORBA::is_nil( cont ) ) {
268 MESSAGE("MPIContainer not found ! " << theComputerContainer );
269 return Engines::Component::_nil();
272 // char * machine = cont->machineName() ;
273 const char * machine = theComputer.c_str() ;
275 string path( theComputerContainer );
278 path += MPIcomponentName;
282 CORBA::Object_var obj = _NS->Resolve(path.c_str());
283 if ( CORBA::is_nil( obj ) ) {
284 MESSAGE("MPIComponent not found ! trying to load " << path);
285 CORBA::Object_var obj2 = _NS->Resolve("/Kernel/ModulCatalog");
286 SALOME_ModuleCatalog::ModuleCatalog_var Catalog =
287 SALOME_ModuleCatalog::ModuleCatalog::_narrow(obj2);
289 SALOME_ModuleCatalog::Acomponent_ptr compoInfo =
290 Catalog->GetComponent(MPIcomponentName);
291 if (CORBA::is_nil (compoInfo))
293 INFOS("Catalog Error : Component not found in the catalog")
294 return Engines::Component::_nil();
301 path = compoInfo->GetPathPrefix( machine ) ;
304 catch (SALOME_ModuleCatalog::NotFound&)
306 MESSAGE("GetPathPrefix(" << machine << ") not found!"
307 << "trying localhost");
309 path = compoInfo->GetPathPrefix("localhost") ;
312 catch (SALOME_ModuleCatalog::NotFound&) {
313 MESSAGE("GetPathPrefix(localhost) not found!") ;
319 string implementation(path);
320 implementation += "lib";
321 implementation += MPIcomponentName;
322 implementation += "Engine.so";
324 Engines::Component_var compo
325 = cont->load_impl(MPIcomponentName, implementation.c_str());
327 // ASSERT(!CORBA::is_nil(compo));
328 // MESSAGE("Component launched !" << path);
333 MESSAGE("MPIComponent found !" << path);
334 Engines::Component_var compo = Engines::Component::_narrow(obj);
335 // ASSERT(!CORBA::is_nil(compo));
338 string instanceName = compo->instanceName();
340 catch (CORBA::SystemException&)
342 INFOS("Caught CORBA::SystemException CommFailure. Engine "
343 << path << "does not respond" );
348 catch (ServiceUnreachable&)
350 INFOS("Caught exception: Naming Service Unreachable");
354 INFOS("Caught unknown exception.");
356 return Engines::Component::_nil();