Salome HOME
YACS in SSL mode
[modules/kernel.git] / src / Container / SALOME_ContainerManager.cxx
index 36b5df43e39e763d70a5f871f4c7644ee5d33131..f709319f22cb268909d9a7ea7b2b1e8894c400f9 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007-2015  CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2021  CEA/DEN, EDF R&D, OPEN CASCADE
 //
 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
@@ -25,6 +25,7 @@
 #include "SALOME_LoadRateManager.hxx"
 #include "SALOME_NamingService.hxx"
 #include "SALOME_ResourcesManager_Client.hxx"
+#include "SALOME_Embedded_NamingService.hxx"
 #include "SALOME_ModuleCatalog.hh"
 #include "Basics_Utils.hxx"
 #include "Basics_DirUtils.hxx"
 
 #ifdef HAVE_MPI2
 #include <mpi.h>
+#include <sys/wait.h>
 #endif
 
 #ifdef WIN32
 #include <process.h>
 #define getpid _getpid
+
+#ifndef S_ISREG
+#define S_ISREG(mode)  (((mode) & S_IFMT) == S_IFREG)
+#endif
+
 #endif
 
 #ifdef WITH_PACO_PARALLEL
@@ -75,7 +82,7 @@ Utils_Mutex SALOME_ContainerManager::_systemMutex;
  */
 //=============================================================================
 
-SALOME_ContainerManager::SALOME_ContainerManager(CORBA::ORB_ptr orb, PortableServer::POA_var poa, SALOME_NamingService *ns)
+SALOME_ContainerManager::SALOME_ContainerManager(CORBA::ORB_ptr orb, PortableServer::POA_var poa, SALOME_NamingService_Abstract *ns)
   : _nbprocUsed(1)
 {
   MESSAGE("constructor");
@@ -93,10 +100,9 @@ SALOME_ContainerManager::SALOME_ContainerManager(CORBA::ORB_ptr orb, PortableSer
   threadPol->destroy();
   PortableServer::ObjectId_var id = _poa->activate_object(this);
   CORBA::Object_var obj = _poa->id_to_reference(id);
-  Engines::ContainerManager_var refContMan =
-    Engines::ContainerManager::_narrow(obj);
-
-  _NS->Register(refContMan,_ContainerManagerNameInNS);
+  Engines::ContainerManager_var refContMan = Engines::ContainerManager::_narrow(obj);
+  if(_NS)
+    _NS->Register(refContMan,_ContainerManagerNameInNS);
   _isAppliSalomeDefined = (GetenvThreadSafe("APPLI") != 0);
 
 #ifdef HAVE_MPI2
@@ -107,40 +113,42 @@ SALOME_ContainerManager::SALOME_ContainerManager(CORBA::ORB_ptr orb, PortableSer
   urifile << GetenvThreadSafeAsString("HOME") << "/.urifile_" << getpid();
   setenv("OMPI_URI_FILE",urifile.str().c_str(),1);
   if( GetenvThreadSafe("OMPI_URI_FILE") != NULL ){
-    // get the pid of all ompi-server
-    std::set<pid_t> thepids1 = getpidofprogram("ompi-server");
-    // launch a new ompi-server
-    std::string command;
-    command = "ompi-server -r ";
-    command += GetenvThreadSafeAsString("OMPI_URI_FILE");
-    int status=SystemThreadSafe(command.c_str());
-    if(status!=0)
-      throw SALOME_Exception("Error when launching ompi-server");
-    // get the pid of all ompi-server
-    std::set<pid_t> thepids2 = getpidofprogram("ompi-server");
-    // my ompi-server is the new one
-    std::set<pid_t>::const_iterator it;
-    for(it=thepids2.begin();it!=thepids2.end();it++)
-      if(thepids1.find(*it) == thepids1.end())
-        _pid_mpiServer = *it;
-    if(_pid_mpiServer < 0)
-      throw SALOME_Exception("Error when getting ompi-server id");
+    // Linux specific code
+    pid_t pid = fork(); // spawn a child process, following code is executed in both processes
+    if ( pid == 0 ) // I'm a child, replace myself with a new ompi-server
+    {
+      std::string uriarg = GetenvThreadSafeAsString("OMPI_URI_FILE");
+      execlp( "ompi-server", "ompi-server", "-r", uriarg.c_str(), NULL );
+      throw SALOME_Exception("Error when launching ompi-server"); // execlp failed
+    }
+    else if ( pid < 0 )
+    {
+      throw SALOME_Exception("fork() failed");
+    }
+    else // I'm a parent
+    {
+      //wait(NULL); // wait(?) for a child end
+      _pid_mpiServer = pid;
+    }
   }
 #elif defined(MPICH)
   _pid_mpiServer = -1;
-  // get the pid of all hydra_nameserver
-  std::set<pid_t> thepids1 = getpidofprogram("hydra_nameserver");
-  // launch a new hydra_nameserver
-  std::string command;
-  command = "hydra_nameserver &";
-  SystemThreadSafe(command.c_str());
-  // get the pid of all hydra_nameserver
-  std::set<pid_t> thepids2 = getpidofprogram("hydra_nameserver");
-  // my hydra_nameserver is the new one
-  std::set<pid_t>::const_iterator it;
-  for(it=thepids2.begin();it!=thepids2.end();it++)
-    if(thepids1.find(*it) == thepids1.end())
-      _pid_mpiServer = *it;
+  // Linux specific code
+  pid_t pid = fork(); // spawn a child process, following code is executed in both processes
+  if ( pid == 0 ) // I'm a child, replace myself with a new hydra_nameserver
+  {
+    execlp( "hydra_nameserver", "hydra_nameserver", NULL );
+    throw SALOME_Exception("Error when launching hydra_nameserver"); // execlp failed
+  }
+  else if ( pid < 0 )
+  {
+    throw SALOME_Exception("fork() failed");
+  }
+  else // I'm a parent
+  {
+    //wait(NULL);
+    _pid_mpiServer = pid;
+  }
 #endif
 #endif
 
@@ -187,7 +195,8 @@ void SALOME_ContainerManager::Shutdown()
 {
   MESSAGE("Shutdown");
   ShutdownContainers();
-  _NS->Destroy_Name(_ContainerManagerNameInNS);
+  if(_NS)
+    _NS->Destroy_Name(_ContainerManagerNameInNS);
   PortableServer::ObjectId_var oid = _poa->servant_to_id(this);
   _poa->deactivate_object(oid);
 }
@@ -201,7 +210,8 @@ void SALOME_ContainerManager::Shutdown()
 void SALOME_ContainerManager::ShutdownContainers()
 {
   MESSAGE("ShutdownContainers");
-
+  if(!_NS)
+    return ;
   SALOME::Session_var session = SALOME::Session::_nil();
   CORBA::Long pid = 0;
   CORBA::Object_var objS = _NS->Resolve("/Kernel/Session");
@@ -227,7 +237,7 @@ void SALOME_ContainerManager::ShutdownContainers()
             if(!CORBA::is_nil(cont) && pid != cont->getPID())
               lstCont.push_back((*iter));
           }
-        catch(const CORBA::Exception& e)
+        catch(const CORBA::Exception&)
           {
             // ignore this entry and continue
           }
@@ -360,7 +370,7 @@ Engines::Container_ptr SALOME_ContainerManager::GiveContainer(const Engines::Con
             break;
           }
       }
-      catch(const SALOME_Exception &ex)
+      catch(const SALOME_Exception &ex) //!< TODO: unused variable
       {
         MESSAGE("[GiveContainer] Exception in ResourceManager find !: " << ex.what());
         return ret;
@@ -372,11 +382,7 @@ Engines::Container_ptr SALOME_ContainerManager::GiveContainer(const Engines::Con
       std::string hostname(resource_definition.HostName);
       std::string containerNameInNS;
       if(params.isMPI){
-        int nbproc;
-        if ( params.nb_proc <= 0 )
-          nbproc = 1;
-        else
-          nbproc = params.nb_proc;
+        int nbproc = params.nb_proc <= 0 ? 1 : params.nb_proc;
         try
         {
           if( GetenvThreadSafe("LIBBATCH_NODEFILE") != NULL )
@@ -390,7 +396,8 @@ Engines::Container_ptr SALOME_ContainerManager::GiveContainer(const Engines::Con
           return ret;
         }
         // A mpi parallel container register on zero node in NS
-        containerNameInNS = _NS->BuildContainerNameForNS(params, GetMPIZeroNode(hostname,machFile).c_str());
+        std::string mpiZeroNode = GetMPIZeroNode(resource_selected,machFile).c_str();
+        containerNameInNS = _NS->BuildContainerNameForNS(params, mpiZeroNode.c_str());
       }
       else
         containerNameInNS = _NS->BuildContainerNameForNS(params, hostname.c_str());
@@ -463,7 +470,7 @@ SALOME_ContainerManager::LaunchContainer(const Engines::ContainerParameters& par
     // Mpi already tested in step 5, specific code on BuildCommandToLaunch Local/Remote Container methods
     // TODO -> separates Mpi from Classic/Exe
     // Classic or Exe ?
-    std::string container_exe = "SALOME_Container"; // Classic container
+    std::string container_exe = this->_isSSL ? "SALOME_Container_No_NS_Serv" : "SALOME_Container"; // Classic container
     Engines::ContainerParameters local_params(params);
     int found=0;
     try
@@ -515,27 +522,15 @@ SALOME_ContainerManager::LaunchContainer(const Engines::ContainerParameters& par
     // Only if an application directory is set
     if(hostname != Kernel_Utils::GetHostname() && _isAppliSalomeDefined)
       {
-        // Preparing remote command
-        std::string command = "";
+
         const ParserResourcesType resInfo(_resManager->GetResourceDefinition(resource_selected));
-        command = getCommandToRunRemoteProcess(resInfo.Protocol, resInfo.HostName, resInfo.UserName);
-        if (resInfo.AppliPath != "")
-          command += resInfo.AppliPath;
-        else
-          {
-            ASSERT(GetenvThreadSafe("APPLI"));
-            command += GetenvThreadSafeAsString("APPLI");
-          }
-        command += "/runRemote.sh ";
-        ASSERT(GetenvThreadSafe("NSHOST"));
-        command += GetenvThreadSafeAsString("NSHOST"); // hostname of CORBA name server
-        command += " ";
-        ASSERT(GetenvThreadSafe("NSPORT"));
-        command += GetenvThreadSafeAsString("NSPORT"); // port of CORBA name server
-        command += " \"ls /tmp >/dev/null 2>&1\"";
+        std::string command = getCommandToRunRemoteProcess(resInfo.Protocol, resInfo.HostName, 
+                                                           resInfo.UserName, resInfo.AppliPath);
 
         // Launch remote command
-        int status = SystemThreadSafe(command.c_str());
+          command += " \"ls /tmp >/dev/null 2>&1\"";
+        // Anthony : command is NO MORE launched to improve dramatically time to launch containers
+        int status = 0;
         if (status != 0)
           {
             // Error on resource - cannot launch commands
@@ -687,7 +682,7 @@ SALOME_ContainerManager::FindContainer(const Engines::ContainerParameters& param
     else
       return Engines::Container::_narrow(obj);
   }
-  catch(const CORBA::Exception& e)
+  catch(const CORBA::Exception&)
   {
     return Engines::Container::_nil();
   }
@@ -705,7 +700,7 @@ bool isPythonContainer(const char* ContainerName)
 {
   return false; // VSR 02/08/2013: Python containers are no more supported
   bool ret = false;
-  int len = strlen(ContainerName);
+  size_t len = strlen(ContainerName);
 
   if (len >= 2)
     if (strcmp(ContainerName + len - 2, "Py") == 0)
@@ -725,7 +720,7 @@ bool isPythonContainer(const char* ContainerName)
  *  ssh user@machine distantPath/runRemote.sh hostNS portNS WORKINGDIR workingdir \
  *                   SALOME_Container containerName &"
 
- *  - where user is ommited if not specified in CatalogResources,
+ *  - where user is omitted if not specified in CatalogResources,
  *  - where distant path is always relative to user@machine $HOME, and
  *    equal to $APPLI if not specified in CatalogResources,
  *  - where hostNS is the hostname of CORBA naming server (set by scripts to
@@ -745,51 +740,22 @@ SALOME_ContainerManager::BuildCommandToLaunchRemoteContainer(const std::string&
     command = BuildTempFileToLaunchRemoteContainer(resource_name, params, tmpFileName);
   else
   {
-    int nbproc;
     const ParserResourcesType resInfo(_resManager->GetResourceDefinition(resource_name));
 
-    if (params.isMPI)
-    {
-      if ( params.nb_proc <= 0 )
-        nbproc = 1;
-      else
-        nbproc = params.nb_proc;
-    }
-
-    // "ssh -l user machine distantPath/runRemote.sh hostNS portNS WORKINGDIR workingdir \
-    //  SALOME_Container containerName &"
-    command = getCommandToRunRemoteProcess(resInfo.Protocol, resInfo.HostName, resInfo.UserName);
-
-    if (resInfo.AppliPath != "")
-      command += resInfo.AppliPath; // path relative to user@machine $HOME
-    else
-    {
-      ASSERT(GetenvThreadSafe("APPLI"));
-      command += GetenvThreadSafeAsString("APPLI"); // path relative to user@machine $HOME
-    }
-
-    command += "/runRemote.sh ";
-
-    ASSERT(GetenvThreadSafe("NSHOST"));
-    command += GetenvThreadSafeAsString("NSHOST"); // hostname of CORBA name server
-
-    command += " ";
-    ASSERT(GetenvThreadSafe("NSPORT"));
-    command += GetenvThreadSafeAsString("NSPORT"); // port of CORBA name server
-
     std::string wdir = params.workingdir.in();
-    if(wdir != "")
-    {
-      command += " WORKINGDIR ";
-      command += " '";
-      if(wdir == "$TEMPDIR")
-        wdir="\\$TEMPDIR";
-      command += wdir; // requested working directory
-      command += "'";
-    }
+
+    // "ssh -l user machine distantPath/runRemote.sh hostNS portNS WORKINGDIR workingdir
+    //      SALOME_Container containerName -ORBInitRef NameService=IOR:01000..."
+    //  or 
+    //  "ssh -l user machine distantLauncher remote -p hostNS -m portNS -d dir
+    //      --  SALOME_Container contName -ORBInitRef NameService=IOR:01000..."
+    command = getCommandToRunRemoteProcess(resInfo.Protocol, resInfo.HostName, 
+                                           resInfo.UserName, resInfo.AppliPath,
+                                           wdir);
 
     if(params.isMPI)
     {
+      int nbproc = params.nb_proc <= 0 ? 1 : params.nb_proc;
       command += " mpirun -np ";
       std::ostringstream o;
       o << nbproc << " ";
@@ -830,18 +796,14 @@ std::string SALOME_ContainerManager::BuildCommandToLaunchLocalContainer(const En
 {
   tmpFileName = BuildTemporaryFileName();
   std::string command;
-  int nbproc = 0;
 
   std::ostringstream o;
 
   if (params.isMPI)
     {
-      o << "mpirun -np ";
+      int nbproc = params.nb_proc <= 0 ? 1 : params.nb_proc;
 
-      if ( params.nb_proc <= 0 )
-        nbproc = 1;
-      else
-        nbproc = params.nb_proc;
+      o << "mpirun -np ";
 
       o << nbproc << " ";
 
@@ -903,11 +865,21 @@ std::string SALOME_ContainerManager::BuildCommandToLaunchLocalContainer(const En
         o << container_exe + " ";
 
     }
+  
+  o << _NS->ContainerName(params) << " ";
 
-  o << _NS->ContainerName(params);
-  o << " -";
-  AddOmninamesParams(o);
-
+  if( this->_isSSL )
+  {
+    Engines::EmbeddedNamingService_var ns = GetEmbeddedNamingService();
+    CORBA::String_var iorNS = _orb->object_to_string(ns);
+    o << iorNS;
+  }
+  else
+  {
+    o << "-";
+    AddOmninamesParams(o);
+  }
+  
   std::ofstream command_file( tmpFileName.c_str() );
   command_file << o.str();
   command_file.close();
@@ -932,16 +904,16 @@ std::string SALOME_ContainerManager::BuildCommandToLaunchLocalContainer(const En
 
 void SALOME_ContainerManager::RmTmpFile(std::string& tmpFileName)
 {
-  int lenght = tmpFileName.size();
-  if ( lenght  > 0)
+  size_t length = tmpFileName.size();
+  if ( length  > 0)
     {
 #ifdef WIN32
       std::string command = "del /F ";
 #else
       std::string command = "rm ";
 #endif
-      if ( lenght > 4 )
-        command += tmpFileName.substr(0, lenght - 3 );
+      if ( length > 4 )
+        command += tmpFileName.substr(0, length - 3 );
       else
         command += tmpFileName;
       command += '*';
@@ -990,11 +962,15 @@ void SALOME_ContainerManager::AddOmninamesParams(std::ostream& fileStream) const
  */
 //=============================================================================
 
-void SALOME_ContainerManager::AddOmninamesParams(std::ostream& fileStream, SALOME_NamingService *ns)
+void SALOME_ContainerManager::AddOmninamesParams(std::ostream& fileStream, SALOME_NamingService_Abstract *ns)
 {
-  CORBA::String_var iorstr(ns->getIORaddr());
-  fileStream << "ORBInitRef NameService=";
-  fileStream << iorstr;
+  SALOME_NamingService *nsTrad(dynamic_cast<SALOME_NamingService *>(ns));
+  if(nsTrad)
+  {
+    CORBA::String_var iorstr(nsTrad->getIORaddr());
+    fileStream << "ORBInitRef NameService=";
+    fileStream << iorstr;
+  }
 }
 
 void SALOME_ContainerManager::MakeTheCommandToBeLaunchedASync(std::string& command)
@@ -1044,6 +1020,9 @@ std::string SALOME_ContainerManager::BuildTemporaryFileName()
 {
   //build more complex file name to support multiple salome session
   std::string aFileName = Kernel_Utils::GetTmpFileName();
+  std::ostringstream str_pid;
+  str_pid << ::getpid();
+  aFileName = aFileName + "-" + str_pid.str();
 #ifndef WIN32
   aFileName += ".sh";
 #else
@@ -1081,15 +1060,9 @@ std::string SALOME_ContainerManager::BuildTempFileToLaunchRemoteContainer (const
 
   if (params.isMPI)
     {
-      tempOutputFile << "mpirun -np ";
-      int nbproc;
-
-      if ( params.nb_proc <= 0 )
-        nbproc = 1;
-      else
-        nbproc = params.nb_proc;
+      int nbproc = params.nb_proc <= 0 ? 1 : params.nb_proc;
 
-      std::ostringstream o;
+      tempOutputFile << "mpirun -np ";
 
       tempOutputFile << nbproc << " ";
 #ifdef LAM_MPI
@@ -1163,7 +1136,7 @@ std::string SALOME_ContainerManager::BuildTempFileToLaunchRemoteContainer (const
 
   else if (resInfo.Protocol == srun)
     {
-      command = "srun -n 1 -N 1 --share --nodelist=";
+      command = "srun -n 1 -N 1 -s --mem-per-cpu=0 --cpu-bind=none --nodelist=";
       std::string commandRcp = "rcp ";
       commandRcp += tmpFileName;
       commandRcp += " ";
@@ -1194,49 +1167,19 @@ std::string SALOME_ContainerManager::GetMPIZeroNode(const std::string machine, c
   std::string zeronode;
   std::string command;
   std::string tmpFile = BuildTemporaryFileName();
+  const ParserResourcesType resInfo(_resManager->GetResourceDefinition(machine));
+
+  if(resInfo.Protocol == sh)
+  {
+    return resInfo.HostName;
+  }
 
   if( GetenvThreadSafe("LIBBATCH_NODEFILE") == NULL )
     {
       if (_isAppliSalomeDefined)
         {
-          const ParserResourcesType resInfo(_resManager->GetResourceDefinition(machine));
-
-          if (resInfo.Protocol == rsh)
-            command = "rsh ";
-          else if (resInfo.Protocol == ssh)
-            command = "ssh ";
-          else if (resInfo.Protocol == srun)
-            command = "srun -n 1 -N 1 --share --nodelist=";
-          else
-            throw SALOME_Exception("Unknown protocol");
-
-          if (resInfo.UserName != "")
-            {
-              command += "-l ";
-              command += resInfo.UserName;
-              command += " ";
-            }
-
-          command += resInfo.HostName;
-          command += " ";
-
-          if (resInfo.AppliPath != "")
-            command += resInfo.AppliPath; // path relative to user@machine $HOME
-          else
-            {
-              ASSERT(GetenvThreadSafe("APPLI"));
-              command += GetenvThreadSafeAsString("APPLI"); // path relative to user@machine $HOME
-            }
-
-          command += "/runRemote.sh ";
-
-          ASSERT(GetenvThreadSafe("NSHOST"));
-          command += GetenvThreadSafeAsString("NSHOST"); // hostname of CORBA name server
-
-          command += " ";
-          ASSERT(GetenvThreadSafe("NSPORT"));
-          command += GetenvThreadSafeAsString("NSPORT"); // port of CORBA name server
-
+          command = getCommandToRunRemoteProcess(resInfo.Protocol, resInfo.HostName, 
+                                                 resInfo.UserName, resInfo.AppliPath);
           command += " mpirun -np 1 hostname -s > " + tmpFile;
         }
       else
@@ -1285,24 +1228,11 @@ std::string SALOME_ContainerManager::machinesFile(const int nbproc)
 
 }
 
-std::set<pid_t> SALOME_ContainerManager::getpidofprogram(const std::string program)
-{
-  std::set<pid_t> thepids;
-  std::string tmpFile = Kernel_Utils::GetTmpFileName();
-  std::string cmd;
-  std::string thepid;
-  cmd = "pidof " + program + " > " + tmpFile;
-  SystemThreadSafe(cmd.c_str());
-  std::ifstream fpi(tmpFile.c_str(),std::ios::in);
-  while(fpi >> thepid){
-    thepids.insert(atoi(thepid.c_str()));
-  }
-  return thepids;
-}
-
 std::string SALOME_ContainerManager::getCommandToRunRemoteProcess(AccessProtocolType protocol,
                                                                   const std::string & hostname,
-                                                                  const std::string & username)
+                                                                  const std::string & username,
+                                                                  const std::string & applipath,
+                                                                  const std::string & workdir)
 {
   std::ostringstream command;
   switch (protocol)
@@ -1326,7 +1256,7 @@ std::string SALOME_ContainerManager::getCommandToRunRemoteProcess(AccessProtocol
   case srun:
     // no need to redefine the user with srun, the job user is taken by default
     // (note: for srun, user id can be specified with " --uid=<user>")
-    command << "srun -n 1 -N 1 --share --nodelist=" << hostname << " ";
+    command << "srun -n 1 -N 1 -s --mem-per-cpu=0 --cpu-bind=none --nodelist=" << hostname << " ";
     break;
   case pbsdsh:
     command << "pbsdsh -o -h " << hostname << " ";
@@ -1338,6 +1268,52 @@ std::string SALOME_ContainerManager::getCommandToRunRemoteProcess(AccessProtocol
     throw SALOME_Exception("Unknown protocol");
   }
 
+  std::string remoteapplipath;
+  if (applipath=="")
+    remoteapplipath = GetenvThreadSafeAsString("APPLI");
+  else
+    remoteapplipath = applipath;
+
+  ASSERT(GetenvThreadSafe("NSHOST"));
+  ASSERT(GetenvThreadSafe("NSPORT"));
+
+  // $APPLI points either to an application directory, or to a salome launcher file
+  // we prepare the remote command according to the case
+  struct stat statbuf;
+  if (stat(GetenvThreadSafe("APPLI"), &statbuf) ==0 &&  S_ISREG(statbuf.st_mode))
+  {
+    // if $APPLI is a regular file, we asume it's a salome Launcher
+    // generate a command with a salome launcher
+    command << remoteapplipath 
+            << " remote"
+            << " -m "
+            <<  GetenvThreadSafeAsString("NSHOST") // hostname of CORBA name server
+            << " -p "
+            <<  GetenvThreadSafeAsString("NSPORT"); // port of CORBA name server
+    if (workdir != "")
+      command << "-d " << workdir;
+    command <<  " -- " ;
+  }
+  else  // we assume it's a salome application directory
+  {
+    // generate a command with runRemote.sh
+    command <<  remoteapplipath;
+    command <<  "/runRemote.sh ";
+    command <<  GetenvThreadSafeAsString("NSHOST"); // hostname of CORBA name server
+    command <<  " ";
+    command <<  GetenvThreadSafeAsString("NSPORT"); // port of CORBA name server
+    if(workdir != "")
+    {
+      command << " WORKINGDIR ";
+      command << " '";
+      if(workdir == "$TEMPDIR")
+          command << "\\$TEMPDIR";
+      else
+        command << workdir; // requested working directory
+      command << "'";
+    }
+  }
+
   return command.str();
 }
 
@@ -1418,6 +1394,38 @@ int SALOME_ContainerManager::SystemThreadSafe(const char *command)
   return system(command);
 }
 
+long SALOME_ContainerManager::SystemWithPIDThreadSafe(const std::vector<std::string>& command)
+{
+  Utils_Locker lock(&_systemMutex);
+  if(command.size()<1)
+    throw SALOME_Exception("SystemWithPIDThreadSafe : command is expected to have a length of size 1 at least !");
+#ifndef WIN32
+  pid_t pid ( fork() ) ; // spawn a child process, following code is executed in both processes
+#else 
+  pid_t pid = -1; //Throw SALOME_Exception on Windows
+#endif
+  if ( pid == 0 ) // I'm a child, replace myself with a new ompi-server
+    {
+      std::size_t sz(command.size());
+      char **args = new char *[sz+1];
+      for(std::size_t i=0;i<sz;i++)
+        args[i] = strdup(command[i].c_str());
+      args[sz] = nullptr;
+      execvp( command[0].c_str() , args ); 
+      std::ostringstream oss;
+      oss << "Error when launching " << command[0];
+      throw SALOME_Exception(oss.str().c_str()); // execvp failed
+    }
+  else if ( pid < 0 )
+    {
+      throw SALOME_Exception("fork() failed");
+    }
+  else // I'm a parent
+    {
+      return pid;
+    }
+}
+
 #ifdef WITH_PACO_PARALLEL
 
 //=============================================================================
@@ -1508,7 +1516,7 @@ SALOME_ContainerManager::StartPaCOPPContainer(const Engines::ContainerParameters
     }
     catch (...)
     {
-      INFOS("[StarPaCOPPContainer] Exception catched from proxy Shutdown...");
+      INFOS("[StarPaCOPPContainer] Exception caught from proxy Shutdown...");
     }
     return ret;
   }
@@ -1624,7 +1632,7 @@ SALOME_ContainerManager::BuildCommandToLaunchPaCOProxyContainer(const Engines::C
     remote_execution = true;
   }
 
-  // Log environnement
+  // Log environment
   std::string log_type("");
   char * get_val = GetenvThreadSafe("PARALLEL_LOG");
   if (get_val)
@@ -1690,7 +1698,7 @@ SALOME_ContainerManager::BuildCommandToLaunchPaCONodeContainer(const Engines::Co
   ParserResourcesType resource_definition =
       _resManager->GetResourceDefinition(params.resource_params.name.in());
 
-  // Log environnement
+  // Log environment
   std::string log_type("");
   char * get_val = GetenvThreadSafe("PARALLEL_LOG");
   if (get_val)
@@ -1939,7 +1947,7 @@ SALOME_ContainerManager::LaunchPaCOProxyContainer(const std::string& command,
 
 //=============================================================================
 /*! This method launches the parallel container.
- *  It will may be placed on the ressources manager.
+ *  It will may be placed on the resources manager.
  *
  * \param command to launch
  * \param container's parameters
@@ -1996,8 +2004,8 @@ SALOME_ContainerManager::LaunchPaCONodeContainer(const std::string& command,
 #else
 
 Engines::Container_ptr
-SALOME_ContainerManager::StartPaCOPPContainer(const Engines::ContainerParameters& params,
-                                              std::string resource_selected)
+SALOME_ContainerManager::StartPaCOPPContainer(const Engines::ContainerParameters& /*params*/,
+                                              std::string /*resource_selected*/)
 {
   Engines::Container_ptr ret = Engines::Container::_nil();
   INFOS("[StarPaCOPPContainer] is disabled !");
@@ -2006,47 +2014,46 @@ SALOME_ContainerManager::StartPaCOPPContainer(const Engines::ContainerParameters
 }
 
 std::string
-SALOME_ContainerManager::BuildCommandToLaunchPaCOProxyContainer(const Engines::ContainerParameters& params,
-                                                                std::string machine_file_name,
-                                                                std::string & proxy_hostname)
+SALOME_ContainerManager::BuildCommandToLaunchPaCOProxyContainer(const Engines::ContainerParameters& /*params*/,
+                                                                std::string /*machine_file_name*/,
+                                                                std::string & /*proxy_hostname*/)
 {
   return "";
 }
 
 std::string
-SALOME_ContainerManager::BuildCommandToLaunchPaCONodeContainer(const Engines::ContainerParameters& params,
-                                                               const std::string & machine_file_name,
-                                                               SALOME_ContainerManager::actual_launch_machine_t & vect_machine,
-                                                               const std::string & proxy_hostname)
+SALOME_ContainerManager::BuildCommandToLaunchPaCONodeContainer(const Engines::ContainerParameters& /*params*/,
+                                                               const std::string & /*machine_file_name*/,
+                                                               SALOME_ContainerManager::actual_launch_machine_t & /*vect_machine*/,
+                                                               const std::string & /*proxy_hostname*/)
 {
   return "";
 }
 void
-SALOME_ContainerManager::LogConfiguration(const std::string & log_type,
-                                          const std::string & exe_type,
-                                          const std::string & container_name,
-                                          const std::string & hostname,
-                                          std::string & begin,
-                                          std::string & end)
+SALOME_ContainerManager::LogConfiguration(const std::string & /*log_type*/,
+                                          const std::string & /*exe_type*/,
+                                          const std::string & /*container_name*/,
+                                          const std::string & /*hostname*/,
+                                          std::string & /*begin*/,
+                                          std::string & /*end*/)
 {
 }
 
 CORBA::Object_ptr
-SALOME_ContainerManager::LaunchPaCOProxyContainer(const std::string& command,
-                                                  const Engines::ContainerParameters& params,
-                                                  const std::string& hostname)
+SALOME_ContainerManager::LaunchPaCOProxyContainer(const std::string& /*command*/,
+                                                  const Engines::ContainerParameters& /*params*/,
+                                                  const std::string& /*hostname*/)
 {
   CORBA::Object_ptr ret = CORBA::Object::_nil();
   return ret;
 }
 
 bool
-SALOME_ContainerManager::LaunchPaCONodeContainer(const std::string& command,
-                        const Engines::ContainerParameters& params,
-                        const std::string& name,
-                        SALOME_ContainerManager::actual_launch_machine_t & vect_machine)
+SALOME_ContainerManager::LaunchPaCONodeContainer(const std::string& /*command*/,
+                        const Engines::ContainerParameters& /*params*/,
+                        const std::string& /*name*/,
+                        SALOME_ContainerManager::actual_launch_machine_t & /*vect_machine*/)
 {
   return false;
 }
 #endif
-