1 #==============================================================================
2 # File : MPILifeCycleCORBA.py
3 # Created : ven may 30 08:42:01 CEST 2003
4 # Author : Bernard SECHER, CEA
8 #==============================================================================
10 from LifeCycleCORBA import *
11 from Utils_Identity import getShortHostName
13 class MPILifeCycleCORBA(LifeCycleCORBA):
14 #-------------------------------------------------------------------------
16 def __init__(self, orb):
17 MESSAGE( "MPILifeCycleCORBA::__init__" )
18 LifeCycleCORBA.__init__(self, orb)
20 #-------------------------------------------------------------------------
22 def FindOrStartMPIContainer(self, theComputer , theMPIContainerRoot, nbproc ):
23 theMPIContainer = theMPIContainerRoot + "_" + str(nbproc)
24 MESSAGE( "FindOrStartMPIContainer" + theComputer + theMPIContainer )
25 aMPIContainer = self.FindContainer( theComputer + "/" + theMPIContainer )
26 if aMPIContainer is None :
27 if (theMPIContainerRoot == "MPIFactoryServer") | (theMPIContainerRoot == "MPIFactoryServerPy") :
28 if theComputer == getShortHostName() :
31 rshstr = "rsh -n " + theComputer + " "
32 path = self.ComputerPath( theComputer )
34 ## rshstr = rshstr + path + "/../bin/salome/"
36 ## rshstr = rshstr + os.getenv( "KERNEL_ROOT_DIR" ) + "/bin/"
37 # rshstr = rshstr + os.getenv( "PWD" ) + "/"
38 if theMPIContainerRoot == "MPIFactoryServer" :
39 rshstr = rshstr + "mpirun -np " + str(nbproc) + " " + path + "SALOME_MPIContainer "
41 rshstr = rshstr + path + "SALOME_MPIContainerPy.py '"
42 rshstr = rshstr + theMPIContainer + " -"
43 omniORBcfg = os.getenv( "OMNIORB_CONFIG" )
44 # omniORBcfg = os.getenv( "HOME" ) + "/.omniORB.cfg"
45 file = os.open( omniORBcfg , os.O_RDONLY )
46 ORBInitRef = os.read(file,132)
47 if ORBInitRef[len(ORBInitRef)-1] == '\n' :
48 ORBInitRef,bsn = ORBInitRef.split('\n')
50 rshstr = rshstr + ORBInitRef
51 if theMPIContainerRoot == "MPIFactoryServerPy" :
53 rshstr = rshstr + " > /tmp/" + theMPIContainer + "_"
54 rshstr = rshstr + theComputer
55 rshstr = rshstr + ".log 2>&1 &"
57 MESSAGE( "FindOrStartMPIContainer" + rshstr + " done" )
59 if theMPIContainer.find('Py') == -1 :
60 aMPIContainer = self.FindContainer( theComputer + "/" + "MPIFactoryServer_" + str(nbproc) )
62 aMPIContainer = self.FindContainer( theComputer + "/" + "MPIFactoryServerPy_" + str(nbproc) )
63 aMPIContainer = aMPIContainer.start_impl( theMPIContainer )
66 while aMPIContainer is None :
69 MESSAGE( str(count) + ". Waiting for " + theComputer + "/" + theMPIContainer )
70 aMPIContainer = self.FindContainer( theComputer + "/" + theMPIContainer )
75 #os.system("rsh -n dm2s0017 /export/home/SALOME_ROOT/bin/runSession SALOME_Container -ORBInitRef NameService=corbaname::dm2s0017:1515")
77 #-------------------------------------------------------------------------
79 def FindOrLoadMPIComponent(self, MPIcontainerName, MPIcomponentName, nbproc):
81 theComputer,theMPIContainerRoot = self.ContainerName( MPIcontainerName )
82 theMPIContainer = theMPIContainerRoot + "_" + str(nbproc)
83 name = [CosNaming.NameComponent(theComputer,"dir"),
84 CosNaming.NameComponent(theMPIContainer,"dir"),
85 CosNaming.NameComponent(MPIcomponentName,"object")]
87 obj = self._containerRootContext.resolve(name)
88 except CosNaming.NamingContext.NotFound, ex:
89 MESSAGE( "component " + MPIcomponentName + " not found, trying to load" )
90 MPIcontainer = self.FindContainer(theComputer + "/" + theMPIContainer)
91 if MPIcontainer is None:
92 MESSAGE( "MPIcontainer " + theComputer + "/" + theMPIContainer + " not found in Naming Service, trying to start" )
93 if (theMPIContainerRoot != "MPIFactoryServer") & (theMPIContainerRoot != "MPIFactoryServerPy") :
94 if theMPIContainer.find('Py') == -1 :
95 theMPIFactorycontainerRoot = "MPIFactoryServer"
96 theMPIFactorycontainer = theMPIFactorycontainerRoot + "_" + str(nbproc)
98 theMPIFactorycontainerRoot = "MPIFactoryServerPy"
99 theMPIFactorycontainer = theMPIFactorycontainerRoot + "_" + str(nbproc)
100 MPIFactorycontainer = self.FindContainer(theComputer + "/" + theMPIFactorycontainer)
101 if MPIFactorycontainer is None:
102 MESSAGE( "MPIcontainer " + theComputer + "/" + theMPIFactorycontainer + " not found in Naming Service, trying to start" )
103 MPIFactorycontainer = self.FindOrStartMPIContainer(theComputer,theMPIFactorycontainerRoot,nbproc)
105 MPIFactorycontainer = self.FindOrStartMPIContainer(theComputer,theMPIContainerRoot,nbproc)
106 if MPIFactorycontainer != None :
107 MPIcontainer = self.FindOrStartMPIContainer(theComputer,theMPIContainerRoot,nbproc)
109 if MPIcontainer != None:
110 compoinfo = self._catalog.GetComponent(MPIcomponentName)
111 if compoinfo is None:
112 MESSAGE( "MPIcomponent " + MPIcomponentName + " not found in Module Catalog" )
115 machineName = theComputer
116 path = compoinfo.GetPathPrefix(machineName) + "/"
117 except SALOME_ModuleCatalog.NotFound, ex:
118 MESSAGE( "machine " + machineName + " not found in Module Catalog" )
119 MESSAGE( "trying localhost" )
121 path = compoinfo.GetPathPrefix("localhost") + "/"
122 except SALOME_ModuleCatalog.NotFound, ex:
124 implementation = path + "lib" + MPIcomponentName + "Engine.so"
125 MESSAGE( "Trying to load " + implementation )
127 MPIcomponent = MPIcontainer.load_impl(MPIcomponentName, implementation)
128 MESSAGE( "component " + MPIcomponent._get_instanceName() + " launched !" )
131 MESSAGE( "component " + MPIcomponentName + " NOT launched !" )
135 MPIcomponent = obj._narrow(Engines.Component)
136 if MPIcomponent is None:
137 MESSAGE( MPIcomponentName + " is not a component !" )
139 MESSAGE( "MPIcomponent " + MPIcomponent._get_instanceName() + " found !" )
142 MESSAGE( MPIcomponentName + " failure" )