Salome HOME
launch ompi-server with salome, and kill it at the end of Salome
[modules/kernel.git] / src / Container / SALOME_ContainerManager.cxx
index 989ca2c4bf858d7abdaf58db4146931bb5af520a..84900334dcd51f2e1878575fa21389a67058e9b8 100644 (file)
@@ -81,6 +81,19 @@ SALOME_ContainerManager::SALOME_ContainerManager(CORBA::ORB_ptr orb, PortableSer
 
   _NS->Register(refContMan,_ContainerManagerNameInNS);
   _isAppliSalomeDefined = (getenv("APPLI") != 0);
+
+#ifdef HAVE_MPI2
+  if( getenv("OMPI_URI_FILE") != NULL ){
+    system("killall ompi-server");
+    string command;
+    command = "ompi-server -r ";
+    command += getenv("OMPI_URI_FILE");
+    int status=system(command.c_str());
+    if(status!=0)
+      throw SALOME_Exception("Error when launching ompi-server");
+  }
+#endif
+
   MESSAGE("constructor end");
 }
 
@@ -93,6 +106,10 @@ SALOME_ContainerManager::SALOME_ContainerManager(CORBA::ORB_ptr orb, PortableSer
 SALOME_ContainerManager::~SALOME_ContainerManager()
 {
   MESSAGE("destructor");
+#ifdef HAVE_MPI2
+  if( getenv("OMPI_URI_FILE") != NULL )
+    system("killall ompi-server");
+#endif
 }
 
 //=============================================================================
@@ -273,7 +290,11 @@ SALOME_ContainerManager::StartContainer(const Engines::MachineParameters& params
   //check if an entry exists in Naming service
   //if params.mode == "start" or "" shutdown the existing container before launching a new one with that name
   //if params.mode == "getorstart" or "get" use the existing container
-  containerNameInNS = _NS->BuildContainerNameForNS(params,theMachine.c_str());
+  if(params.isMPI)
+    // A parallel container register on zero node in NS
+    containerNameInNS = _NS->BuildContainerNameForNS(params,GetMPIZeroNode(theMachine).c_str());
+  else
+    containerNameInNS = _NS->BuildContainerNameForNS(params,theMachine.c_str());
 
   SCRUTE(containerNameInNS);
   CORBA::Object_var obj = _NS->Resolve(containerNameInNS.c_str());
@@ -313,8 +334,29 @@ SALOME_ContainerManager::StartContainer(const Engines::MachineParameters& params
     command = BuildCommandToLaunchRemoteContainer(theMachine,params,container_exe);
 
   //redirect stdout and stderr in a file
-  string logFilename="/tmp/"+_NS->ContainerName(params)+"_"+ theMachine +"_"+getenv( "USER" )+".log" ;
-  command += " > " + logFilename + " 2>&1 &";
+#ifdef WNT
+  string logFilename=getenv("TEMP");
+  logFilename += "\\";
+#else
+  string logFilename="/tmp";
+  char* val = getenv("SALOME_TMP_DIR");
+  if(val)
+    {
+      struct stat file_info;
+      stat(val, &file_info);
+      bool is_dir = S_ISDIR(file_info.st_mode);
+      if (is_dir)logFilename=val;
+      else std::cerr << "SALOME_TMP_DIR environment variable is not a directory use /tmp instead" << std::endl;
+    }
+  logFilename += "/";
+#endif
+  logFilename += _NS->ContainerName(params)+"_"+ theMachine +"_"+getenv( "USER" )+".log" ;
+  command += " > " + logFilename + " 2>&1";
+#ifdef WNT
+  command = "%PYTHONBIN% -c \"import win32pm ; win32pm.spawnpid(r'" + command + "', '')\"";
+#else
+  command += " &";
+#endif
 
   // launch container with a system call
   int status=system(command.c_str());