1 // Copyright (C) 2007-2010 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 #include "SALOME_ContainerManager.hxx"
24 #include "SALOME_NamingService.hxx"
25 #include "SALOME_ModuleCatalog.hh"
26 #include "Basics_Utils.hxx"
27 #include "Basics_DirUtils.hxx"
28 #include <sys/types.h>
35 #include "Utils_CorbaException.hxx"
40 #define getpid _getpid
43 #ifdef WITH_PACO_PARALLEL
47 #define TIME_OUT_TO_LAUNCH_CONT 61
49 const char *SALOME_ContainerManager::_ContainerManagerNameInNS =
52 omni_mutex SALOME_ContainerManager::_numInstanceMutex;
55 //=============================================================================
59 * Define a CORBA single thread policy for the server, which avoid to deal
60 * with non thread-safe usage like Change_Directory in SALOME naming service
62 //=============================================================================
64 SALOME_ContainerManager::SALOME_ContainerManager(CORBA::ORB_ptr orb, PortableServer::POA_var poa, SALOME_ResourcesManager *rm, SALOME_NamingService *ns):_nbprocUsed(0)
66 MESSAGE("constructor");
70 PortableServer::POAManager_var pman = poa->the_POAManager();
71 _orb = CORBA::ORB::_duplicate(orb) ;
72 CORBA::PolicyList policies;
74 PortableServer::ThreadPolicy_var threadPol =
75 poa->create_thread_policy(PortableServer::SINGLE_THREAD_MODEL);
76 policies[0] = PortableServer::ThreadPolicy::_duplicate(threadPol);
78 _poa = poa->create_POA("SThreadPOA",pman,policies);
80 PortableServer::ObjectId_var id = _poa->activate_object(this);
81 CORBA::Object_var obj = _poa->id_to_reference(id);
82 Engines::ContainerManager_var refContMan =
83 Engines::ContainerManager::_narrow(obj);
85 _NS->Register(refContMan,_ContainerManagerNameInNS);
86 _isAppliSalomeDefined = (getenv("APPLI") != 0);
91 // the urifile name depends on pid of the process
92 std::stringstream urifile;
93 urifile << getenv("HOME") << "/.urifile_" << getpid();
94 setenv("OMPI_URI_FILE",urifile.str().c_str(),1);
95 if( getenv("OMPI_URI_FILE") != NULL ){
96 // get the pid of all ompi-server
97 std::set<pid_t> thepids1 = getpidofprogram("ompi-server");
98 // launch a new ompi-server
100 command = "ompi-server -r ";
101 command += getenv("OMPI_URI_FILE");
102 int status=system(command.c_str());
104 throw SALOME_Exception("Error when launching ompi-server");
105 // get the pid of all ompi-server
106 std::set<pid_t> thepids2 = getpidofprogram("ompi-server");
107 // my ompi-server is the new one
108 std::set<pid_t>::const_iterator it;
109 for(it=thepids2.begin();it!=thepids2.end();it++)
110 if(thepids1.find(*it) == thepids1.end())
111 _pid_ompiServer = *it;
112 if(_pid_ompiServer < 0)
113 throw SALOME_Exception("Error when getting ompi-server id");
118 MESSAGE("constructor end");
121 //=============================================================================
125 //=============================================================================
127 SALOME_ContainerManager::~SALOME_ContainerManager()
129 MESSAGE("destructor");
132 if( getenv("OMPI_URI_FILE") != NULL ){
133 // kill my ompi-server
134 if( kill(_pid_ompiServer,SIGTERM) != 0 )
135 throw SALOME_Exception("Error when killing ompi-server");
137 int status=system("rm -f ${OMPI_URI_FILE}");
139 throw SALOME_Exception("Error when removing urifile");
145 //=============================================================================
146 //! shutdown all the containers, then the ContainerManager servant
149 //=============================================================================
151 void SALOME_ContainerManager::Shutdown()
154 ShutdownContainers();
155 _NS->Destroy_Name(_ContainerManagerNameInNS);
156 PortableServer::ObjectId_var oid = _poa->servant_to_id(this);
157 _poa->deactivate_object(oid);
160 //=============================================================================
161 //! Loop on all the containers listed in naming service, ask shutdown on each
164 //=============================================================================
166 void SALOME_ContainerManager::ShutdownContainers()
168 MESSAGE("ShutdownContainers");
170 isOK = _NS->Change_Directory("/Containers");
172 std::vector<std::string> vec = _NS->list_directory_recurs();
173 std::list<std::string> lstCont;
174 for(std::vector<std::string>::iterator iter = vec.begin();iter!=vec.end();iter++)
177 CORBA::Object_var obj=_NS->Resolve((*iter).c_str());
180 Engines::Container_var cont=Engines::Container::_narrow(obj);
181 if(!CORBA::is_nil(cont))
182 lstCont.push_back((*iter));
184 catch(const CORBA::Exception& e)
186 // ignore this entry and continue
189 MESSAGE("Container list: ");
190 for(std::list<std::string>::iterator iter=lstCont.begin();iter!=lstCont.end();iter++){
193 for(std::list<std::string>::iterator iter=lstCont.begin();iter!=lstCont.end();iter++)
198 CORBA::Object_var obj=_NS->Resolve((*iter).c_str());
199 Engines::Container_var cont=Engines::Container::_narrow(obj);
200 if(!CORBA::is_nil(cont))
202 MESSAGE("ShutdownContainers: " << (*iter));
206 MESSAGE("ShutdownContainers: no container ref for " << (*iter));
208 catch(CORBA::SystemException& e)
210 INFOS("CORBA::SystemException ignored : " << e);
212 catch(CORBA::Exception&)
214 INFOS("CORBA::Exception ignored.");
218 INFOS("Unknown exception ignored.");
224 //=============================================================================
225 //! Give a suitable Container given constraints
227 * \param params Container Parameters required for the container
228 * \return the container or nil
230 //=============================================================================
231 Engines::Container_ptr
232 SALOME_ContainerManager::GiveContainer(const Engines::ContainerParameters& params)
234 std::string machFile;
235 Engines::Container_ptr ret = Engines::Container::_nil();
237 // Step 0: Default mode is start
238 Engines::ContainerParameters local_params(params);
239 if (std::string(local_params.mode.in()) == "")
240 local_params.mode = CORBA::string_dup("start");
241 std::string mode = local_params.mode.in();
242 MESSAGE("[GiveContainer] starting with mode: " << mode);
244 // Step 1: Find Container for find and findorstart mode
245 if (mode == "find" || mode == "findorstart")
247 ret = FindContainer(params, params.resource_params.resList);
248 if(!CORBA::is_nil(ret))
254 MESSAGE("[GiveContainer] no container found");
264 // Step 2: Get all possibleResources from the parameters
265 Engines::ResourceList_var possibleResources = _ResManager->GetFittingResources(local_params.resource_params);
266 MESSAGE("[GiveContainer] - length of possible resources " << possibleResources->length());
267 std::vector<std::string> local_resources;
269 // Step 3: if mode is "get" keep only machines with existing containers
272 for(unsigned int i=0; i < possibleResources->length(); i++)
274 Engines::Container_ptr cont = FindContainer(params, possibleResources[i].in());
277 if(!cont->_non_existent())
278 local_resources.push_back(std::string(possibleResources[i]));
280 catch(CORBA::Exception&) {}
283 // if local_resources is empty, we cannot give a container
284 if (local_resources.size() == 0)
286 MESSAGE("[GiveContainer] cannot find a container for mode get");
291 for(unsigned int i=0; i < possibleResources->length(); i++)
292 local_resources.push_back(std::string(possibleResources[i]));
294 // Step 4: select the resource where to get/start the container
295 std::string resource_selected;
298 resource_selected = _ResManager->GetImpl()->Find(params.resource_params.policy.in(), local_resources);
300 catch(const SALOME_Exception &ex)
302 MESSAGE("[GiveContainer] Exception in ResourceManager find !: " << ex.what());
305 MESSAGE("[GiveContainer] Resource selected is: " << resource_selected);
307 // Step 5: get container in the naming service
308 Engines::ResourceDefinition_var resource_definition = _ResManager->GetResourceDefinition(resource_selected.c_str());
309 std::string hostname(resource_definition->hostname.in());
310 std::string containerNameInNS;
313 if ( params.nb_proc <= 0 )
316 nbproc = params.nb_proc;
317 if( getenv("LIBBATCH_NODEFILE") != NULL )
318 machFile = machinesFile(nbproc);
319 // A mpi parallel container register on zero node in NS
320 containerNameInNS = _NS->BuildContainerNameForNS(params, GetMPIZeroNode(hostname,machFile).c_str());
323 containerNameInNS = _NS->BuildContainerNameForNS(params, hostname.c_str());
324 MESSAGE("[GiveContainer] Container name in the naming service: " << containerNameInNS);
326 // Step 6: check if the name exists in naming service
327 //if params.mode == "getorstart" or "get" use the existing container
328 //if params.mode == "start" shutdown the existing container before launching a new one with that name
329 CORBA::Object_var obj = _NS->Resolve(containerNameInNS.c_str());
330 if (!CORBA::is_nil(obj))
334 Engines::Container_var cont=Engines::Container::_narrow(obj);
335 if(!cont->_non_existent())
337 if(std::string(params.mode.in())=="getorstart" || std::string(params.mode.in())=="get"){
338 return cont._retn(); /* the container exists and params.mode is getorstart or get use it*/
342 INFOS("[GiveContainer] A container is already registered with the name: " << containerNameInNS << ", shutdown the existing container");
343 cont->Shutdown(); // shutdown the registered container if it exists
347 catch(CORBA::Exception&)
349 INFOS("[GiveContainer] CORBA::Exception ignored when trying to get the container - we start a new one");
353 // Step 7: type of container: PaCO, Exe, Mpi or Classic
354 // Mpi already tested in step 5, specific code on BuildCommandToLaunch Local/Remote Container methods
355 // TODO -> separates Mpi from Classic/Exe
357 std::string container_exe = "SALOME_Container"; // Classic container
361 CORBA::String_var container_exe_tmp;
362 CORBA::Object_var obj = _NS->Resolve("/Kernel/ModulCatalog");
363 SALOME_ModuleCatalog::ModuleCatalog_var Catalog = SALOME_ModuleCatalog::ModuleCatalog::_narrow(obj) ;
364 if (CORBA::is_nil (Catalog))
366 INFOS("[GiveContainer] Module Catalog is not found -> cannot launch a container");
369 // Loop through component list
370 for(unsigned int i=0; i < local_params.resource_params.componentList.length(); i++)
372 const char* compoi = local_params.resource_params.componentList[i];
373 SALOME_ModuleCatalog::Acomponent_var compoInfo = Catalog->GetComponent(compoi);
374 if (CORBA::is_nil (compoInfo))
378 SALOME_ModuleCatalog::ImplType impl=compoInfo->implementation_type();
379 container_exe_tmp=compoInfo->implementation_name();
380 if(impl==SALOME_ModuleCatalog::CEXE)
384 INFOS("ContainerManager Error: you can't have 2 CEXE component in the same container" );
385 return Engines::Container::_nil();
387 MESSAGE("[GiveContainer] Exe container found !: " << container_exe_tmp);
388 container_exe = container_exe_tmp.in();
393 catch (ServiceUnreachable&)
395 INFOS("Caught exception: Naming Service Unreachable");
400 INFOS("Caught unknown exception.");
404 // Step 8: start a new container
405 // Check if a PaCO container
407 if (std::string(local_params.parallelLib.in()) != "")
409 ret = StartPaCOPPContainer(params, resource_selected);
412 // Other type of containers...
413 MESSAGE("[GiveContainer] Try to launch a new container on " << resource_selected);
415 // if a parallel container is launched in batch job, command is: "mpirun -np nbproc -machinefile nodesfile SALOME_MPIContainer"
416 if( getenv("LIBBATCH_NODEFILE") != NULL && params.isMPI )
417 command = BuildCommandToLaunchLocalContainer(params, machFile, container_exe);
418 // if a container is launched on localhost, command is "SALOME_Container" or "mpirun -np nbproc SALOME_MPIContainer"
419 else if(hostname == Kernel_Utils::GetHostname())
420 command = BuildCommandToLaunchLocalContainer(params, machFile, container_exe);
421 // if a container is launched in remote mode, command is "ssh resource_selected SALOME_Container" or "ssh resource_selected mpirun -np nbproc SALOME_MPIContainer"
423 command = BuildCommandToLaunchRemoteContainer(resource_selected, params, container_exe);
425 //redirect stdout and stderr in a file
427 std::string logFilename=getenv("TEMP");
429 std::string user = getenv( "USERNAME" );
431 std::string user = getenv( "USER" );
432 std::string logFilename="/tmp";
433 char* val = getenv("SALOME_TMP_DIR");
436 struct stat file_info;
437 stat(val, &file_info);
438 bool is_dir = S_ISDIR(file_info.st_mode);
439 if (is_dir)logFilename=val;
440 else std::cerr << "SALOME_TMP_DIR environment variable is not a directory use /tmp instead" << std::endl;
444 logFilename += _NS->ContainerName(params)+"_"+ resource_selected +"_"+user;
445 std::ostringstream tmp;
446 tmp << "_" << getpid();
447 logFilename += tmp.str();
448 logFilename += ".log" ;
449 command += " > " + logFilename + " 2>&1";
451 command = "%PYTHONBIN% -c \"import win32pm ; win32pm.spawnpid(r'" + command + "', '')\"";
456 // launch container with a system call
457 int status=system(command.c_str());
460 MESSAGE("SALOME_ContainerManager::StartContainer rsh failed (system command status -1)");
461 RmTmpFile(_TmpFileName); // command file can be removed here
463 return Engines::Container::_nil();
465 else if (status == 217){
466 MESSAGE("SALOME_ContainerManager::StartContainer rsh failed (system command status 217)");
467 RmTmpFile(_TmpFileName); // command file can be removed here
469 return Engines::Container::_nil();
473 int count = TIME_OUT_TO_LAUNCH_CONT;
474 MESSAGE("[GiveContainer] waiting " << count << " second steps");
475 while (CORBA::is_nil(ret) && count)
483 MESSAGE("[GiveContainer] step " << count << " Waiting for container on " << resource_selected);
484 CORBA::Object_var obj = _NS->Resolve(containerNameInNS.c_str());
485 ret=Engines::Container::_narrow(obj);
487 if (CORBA::is_nil(ret))
489 INFOS("[GiveContainer] was not able to launch container " << containerNameInNS);
493 // Setting log file name
494 logFilename=":"+logFilename;
495 logFilename="@"+Kernel_Utils::GetHostname()+logFilename;
496 logFilename=user+logFilename;
497 ret->logfilename(logFilename.c_str());
498 RmTmpFile(_TmpFileName); // command file can be removed here
505 //=============================================================================
506 //! Find a container given constraints (params) on a list of machines (possibleComputers)
510 //=============================================================================
512 Engines::Container_ptr
513 SALOME_ContainerManager::FindContainer(const Engines::ContainerParameters& params,
514 const Engines::ResourceList& possibleResources)
516 MESSAGE("[FindContainer] FindContainer on " << possibleResources.length() << " resources");
517 for(unsigned int i=0; i < possibleResources.length();i++)
519 Engines::Container_ptr cont = FindContainer(params, possibleResources[i].in());
520 if(!CORBA::is_nil(cont))
523 MESSAGE("[FindContainer] no container found");
524 return Engines::Container::_nil();
527 //=============================================================================
528 //! Find a container given constraints (params) on a machine (theMachine)
532 //=============================================================================
534 Engines::Container_ptr
535 SALOME_ContainerManager::FindContainer(const Engines::ContainerParameters& params,
536 const std::string& resource)
538 Engines::ResourceDefinition_var resource_definition = _ResManager->GetResourceDefinition(resource.c_str());
539 std::string hostname(resource_definition->hostname.in());
540 std::string containerNameInNS(_NS->BuildContainerNameForNS(params, hostname.c_str()));
541 MESSAGE("[FindContainer] Try to find a container " << containerNameInNS << " on resource " << resource);
542 CORBA::Object_var obj = _NS->Resolve(containerNameInNS.c_str());
545 if(obj->_non_existent())
546 return Engines::Container::_nil();
548 return Engines::Container::_narrow(obj);
550 catch(const CORBA::Exception& e)
552 return Engines::Container::_nil();
557 bool isPythonContainer(const char* ContainerName);
559 //=============================================================================
561 * This is no longer valid (C++ container are also python containers)
563 //=============================================================================
564 bool isPythonContainer(const char* ContainerName)
567 int len = strlen(ContainerName);
570 if (strcmp(ContainerName + len - 2, "Py") == 0)
576 //=============================================================================
578 * Builds the script to be launched
580 * If SALOME Application not defined ($APPLI),
581 * see BuildTempFileToLaunchRemoteContainer()
583 * Else rely on distant configuration. Command is under the form (example):
584 * ssh user@machine distantPath/runRemote.sh hostNS portNS WORKINGDIR workingdir \
585 * SALOME_Container containerName &"
587 * - where user is ommited if not specified in CatalogResources,
588 * - where distant path is always relative to user@machine $HOME, and
589 * equal to $APPLI if not specified in CatalogResources,
590 * - where hostNS is the hostname of CORBA naming server (set by scripts to
591 * use to launch SALOME and servers in $APPLI: runAppli.sh, runRemote.sh)
592 * - where portNS is the port used by CORBA naming server (set by scripts to
593 * use to launch SALOME and servers in $APPLI: runAppli.sh, runRemote.sh)
594 * - where workingdir is the requested working directory for the container.
595 * If WORKINGDIR (and workingdir) is not present the working dir will be $HOME
597 //=============================================================================
600 SALOME_ContainerManager::BuildCommandToLaunchRemoteContainer
601 (const std::string& resource_name,
602 const Engines::ContainerParameters& params, const std::string& container_exe)
606 if (!_isAppliSalomeDefined)
607 command = BuildTempFileToLaunchRemoteContainer(resource_name, params);
611 Engines::ResourceDefinition_var resource_definition = _ResManager->GetResourceDefinition(resource_name.c_str());
612 std::string hostname(resource_definition->hostname.in());
613 const ParserResourcesType& resInfo = _ResManager->GetImpl()->GetResourcesDescr(resource_name);
617 if ( params.nb_proc <= 0 )
620 nbproc = params.nb_proc;
623 // "ssh -l user machine distantPath/runRemote.sh hostNS portNS WORKINGDIR workingdir \
624 // SALOME_Container containerName &"
625 if (resInfo.Protocol == rsh)
627 else if (resInfo.Protocol == ssh)
630 throw SALOME_Exception("Unknown protocol");
632 if (resInfo.UserName != "")
635 command += resInfo.UserName;
639 command += resInfo.HostName;
642 if (resInfo.AppliPath != "")
643 command += resInfo.AppliPath; // path relative to user@machine $HOME
646 ASSERT(getenv("APPLI"));
647 command += getenv("APPLI"); // path relative to user@machine $HOME
650 command += "/runRemote.sh ";
652 ASSERT(getenv("NSHOST"));
653 command += getenv("NSHOST"); // hostname of CORBA name server
656 ASSERT(getenv("NSPORT"));
657 command += getenv("NSPORT"); // port of CORBA name server
659 std::string wdir = params.workingdir.in();
662 command += " WORKINGDIR ";
664 if(wdir == "$TEMPDIR")
666 command += wdir; // requested working directory
672 command += " mpirun -np ";
673 std::ostringstream o;
677 command += "-x PATH,LD_LIBRARY_PATH,OMNIORB_CONFIG,SALOME_trace ";
678 #elif defined(WITHOPENMPI)
679 if( getenv("OMPI_URI_FILE") == NULL )
680 command += "-x PATH -x LD_LIBRARY_PATH -x OMNIORB_CONFIG -x SALOME_trace";
682 command += "-x PATH -x LD_LIBRARY_PATH -x OMNIORB_CONFIG -x SALOME_trace -ompi-server file:";
683 command += getenv("OMPI_URI_FILE");
686 command += " SALOME_MPIContainer ";
689 command += " " +container_exe+ " ";
691 command += _NS->ContainerName(params);
693 AddOmninamesParams(command);
695 MESSAGE("command =" << command);
701 //=============================================================================
703 * builds the command to be launched.
705 //=============================================================================
707 SALOME_ContainerManager::BuildCommandToLaunchLocalContainer
708 (const Engines::ContainerParameters& params, const std::string& machinesFile, const std::string& container_exe)
710 _TmpFileName = BuildTemporaryFileName();
714 std::ostringstream o;
720 if ( params.nb_proc <= 0 )
723 nbproc = params.nb_proc;
727 if( getenv("LIBBATCH_NODEFILE") != NULL )
728 o << "-machinefile " << machinesFile << " ";
731 o << "-x PATH,LD_LIBRARY_PATH,OMNIORB_CONFIG,SALOME_trace ";
732 #elif defined(WITHOPENMPI)
733 if( getenv("OMPI_URI_FILE") == NULL )
734 o << "-x PATH -x LD_LIBRARY_PATH -x OMNIORB_CONFIG -x SALOME_trace";
737 o << "-x PATH -x LD_LIBRARY_PATH -x OMNIORB_CONFIG -x SALOME_trace -ompi-server file:";
738 o << getenv("OMPI_URI_FILE");
742 if (isPythonContainer(params.container_name))
743 o << " pyMPI SALOME_ContainerPy.py ";
745 o << " SALOME_MPIContainer ";
750 std::string wdir=params.workingdir.in();
753 // a working directory is requested
754 if(wdir == "$TEMPDIR")
756 // a new temporary directory is requested
757 std::string dir = Kernel_Utils::GetTmpDir();
759 o << "cd /d " << dir << std::endl;
761 o << "cd " << dir << ";";
767 // a permanent directory is requested use it or create it
769 o << "mkdir " + wdir << std::endl;
770 o << "cd /D " + wdir << std::endl;
772 o << "mkdir -p " << wdir << " && cd " << wdir + ";";
776 if (isPythonContainer(params.container_name))
777 o << "SALOME_ContainerPy.py ";
779 o << container_exe + " ";
783 o << _NS->ContainerName(params);
785 AddOmninamesParams(o);
787 std::ofstream command_file( _TmpFileName.c_str() );
788 command_file << o.str();
789 command_file.close();
792 chmod(_TmpFileName.c_str(), 0x1ED);
794 command = _TmpFileName;
796 MESSAGE("Command is file ... " << command);
797 MESSAGE("Command is ... " << o.str());
802 //=============================================================================
804 * removes the generated temporary file in case of a remote launch.
806 //=============================================================================
808 void SALOME_ContainerManager::RmTmpFile(std::string& tmpFileName)
810 int lenght = tmpFileName.size();
814 std::string command = "del /F ";
816 std::string command = "rm ";
819 command += tmpFileName.substr(0, lenght - 3 );
821 command += tmpFileName;
823 system(command.c_str());
824 //if dir is empty - remove it
825 std::string tmp_dir = Kernel_Utils::GetDirByPath( tmpFileName );
826 if ( Kernel_Utils::IsEmptyDir( tmp_dir ) )
829 command = "del /F " + tmp_dir;
831 command = "rmdir " + tmp_dir;
833 system(command.c_str());
838 //=============================================================================
840 * add to command all options relative to naming service.
842 //=============================================================================
844 void SALOME_ContainerManager::AddOmninamesParams(std::string& command) const
846 CORBA::String_var iorstr = _NS->getIORaddr();
847 command += "ORBInitRef NameService=";
851 //=============================================================================
853 * add to command all options relative to naming service.
855 //=============================================================================
857 void SALOME_ContainerManager::AddOmninamesParams(std::ofstream& fileStream) const
859 CORBA::String_var iorstr = _NS->getIORaddr();
860 fileStream << "ORBInitRef NameService=";
861 fileStream << iorstr;
864 //=============================================================================
866 * add to command all options relative to naming service.
868 //=============================================================================
870 void SALOME_ContainerManager::AddOmninamesParams(std::ostringstream& oss) const
872 CORBA::String_var iorstr = _NS->getIORaddr();
873 oss << "ORBInitRef NameService=";
877 //=============================================================================
879 * generate a file name in /tmp directory
881 //=============================================================================
883 std::string SALOME_ContainerManager::BuildTemporaryFileName() const
885 //build more complex file name to support multiple salome session
886 std::string aFileName = Kernel_Utils::GetTmpFileName();
895 //=============================================================================
897 * Builds in a temporary file the script to be launched.
899 * Used if SALOME Application ($APPLI) is not defined.
900 * The command is build with data from CatalogResources, in which every path
901 * used on remote computer must be defined.
903 //=============================================================================
906 SALOME_ContainerManager::BuildTempFileToLaunchRemoteContainer
907 (const std::string& resource_name,
908 const Engines::ContainerParameters& params) throw(SALOME_Exception)
912 _TmpFileName = BuildTemporaryFileName();
913 std::ofstream tempOutputFile;
914 tempOutputFile.open(_TmpFileName.c_str(), std::ofstream::out );
915 const ParserResourcesType& resInfo = _ResManager->GetImpl()->GetResourcesDescr(resource_name);
916 tempOutputFile << "#! /bin/sh" << std::endl;
920 tempOutputFile << "export SALOME_trace=local" << std::endl; // mkr : 27.11.2006 : PAL13967 - Distributed supervision graphs - Problem with "SALOME_trace"
921 //tempOutputFile << "source " << resInfo.PreReqFilePath << endl;
927 tempOutputFile << "mpirun -np ";
930 if ( params.nb_proc <= 0 )
933 nbproc = params.nb_proc;
935 std::ostringstream o;
937 tempOutputFile << nbproc << " ";
939 tempOutputFile << "-x PATH,LD_LIBRARY_PATH,OMNIORB_CONFIG,SALOME_trace ";
940 #elif defined(WITHOPENMPI)
941 if( getenv("OMPI_URI_FILE") == NULL )
942 tempOutputFile << "-x PATH -x LD_LIBRARY_PATH -x OMNIORB_CONFIG -x SALOME_trace";
944 tempOutputFile << "-x PATH -x LD_LIBRARY_PATH -x OMNIORB_CONFIG -x SALOME_trace -ompi-server file:";
945 tempOutputFile << getenv("OMPI_URI_FILE");
950 tempOutputFile << getenv("KERNEL_ROOT_DIR") << "/bin/salome/";
954 if (isPythonContainer(params.container_name))
955 tempOutputFile << " pyMPI SALOME_ContainerPy.py ";
957 tempOutputFile << " SALOME_MPIContainer ";
962 if (isPythonContainer(params.container_name))
963 tempOutputFile << "SALOME_ContainerPy.py ";
965 tempOutputFile << "SALOME_Container ";
968 tempOutputFile << _NS->ContainerName(params) << " -";
969 AddOmninamesParams(tempOutputFile);
970 tempOutputFile << " &" << std::endl;
971 tempOutputFile.flush();
972 tempOutputFile.close();
974 chmod(_TmpFileName.c_str(), 0x1ED);
981 if (resInfo.Protocol == rsh)
984 std::string commandRcp = "rcp ";
985 commandRcp += _TmpFileName;
987 commandRcp += resInfo.HostName;
989 commandRcp += _TmpFileName;
990 status = system(commandRcp.c_str());
993 else if (resInfo.Protocol == ssh)
996 std::string commandRcp = "scp ";
997 commandRcp += _TmpFileName;
999 commandRcp += resInfo.HostName;
1001 commandRcp += _TmpFileName;
1002 status = system(commandRcp.c_str());
1005 throw SALOME_Exception("Unknown protocol");
1008 throw SALOME_Exception("Error of connection on remote host");
1010 command += resInfo.HostName;
1011 _CommandForRemAccess = command;
1013 command += _TmpFileName;
1021 std::string SALOME_ContainerManager::GetMPIZeroNode(const std::string machine, const std::string machinesFile)
1024 std::string zeronode;
1025 std::string command;
1026 std::string tmpFile = BuildTemporaryFileName();
1028 if( getenv("LIBBATCH_NODEFILE") == NULL )
1030 if (_isAppliSalomeDefined)
1032 const ParserResourcesType& resInfo = _ResManager->GetImpl()->GetResourcesDescr(machine);
1034 if (resInfo.Protocol == rsh)
1036 else if (resInfo.Protocol == ssh)
1039 throw SALOME_Exception("Unknown protocol");
1041 if (resInfo.UserName != "")
1044 command += resInfo.UserName;
1048 command += resInfo.HostName;
1051 if (resInfo.AppliPath != "")
1052 command += resInfo.AppliPath; // path relative to user@machine $HOME
1055 ASSERT(getenv("APPLI"));
1056 command += getenv("APPLI"); // path relative to user@machine $HOME
1059 command += "/runRemote.sh ";
1061 ASSERT(getenv("NSHOST"));
1062 command += getenv("NSHOST"); // hostname of CORBA name server
1065 ASSERT(getenv("NSPORT"));
1066 command += getenv("NSPORT"); // port of CORBA name server
1068 command += " mpirun -np 1 hostname > " + tmpFile;
1071 command = "mpirun -np 1 hostname > " + tmpFile;
1074 command = "mpirun -np 1 -machinefile " + machinesFile + " hostname > " + tmpFile;
1076 status = system(command.c_str());
1078 std::ifstream fp(tmpFile.c_str(),std::ios::in);
1079 while(fp >> zeronode);
1087 std::string SALOME_ContainerManager::machinesFile(const int nbproc)
1090 std::string nodesFile = getenv("LIBBATCH_NODEFILE");
1091 std::string machinesFile = Kernel_Utils::GetTmpFileName();
1092 std::ifstream fpi(nodesFile.c_str(),std::ios::in);
1093 std::ofstream fpo(machinesFile.c_str(),std::ios::out);
1095 _numInstanceMutex.lock();
1097 for(int i=0;i<_nbprocUsed;i++)
1100 for(int i=0;i<nbproc;i++)
1102 fpo << tmp << std::endl;
1104 throw SALOME_Exception("You ask more processes than batch session have allocated!");
1106 _nbprocUsed += nbproc;
1110 _numInstanceMutex.unlock();
1112 return machinesFile;
1116 std::set<pid_t> SALOME_ContainerManager::getpidofprogram(const std::string program)
1118 std::set<pid_t> thepids;
1119 std::string tmpFile = Kernel_Utils::GetTmpFileName();
1122 cmd = "pidof " + program + " > " + tmpFile;
1123 system(cmd.c_str());
1124 std::ifstream fpi(tmpFile.c_str(),std::ios::in);
1125 while(fpi >> thepid){
1126 thepids.insert(atoi(thepid.c_str()));
1132 SALOME_ContainerManager::checkPaCOParameters(Engines::ContainerParameters & params, std::string resource_selected)
1136 // Step 1 : check ContainerParameters
1137 // Check container_name, has to be defined
1138 if (std::string(params.container_name.in()) == "")
1140 INFOS("[checkPaCOParameters] You must define a container_name to launch a PaCO++ container");
1143 // Check parallelLib
1144 std::string parallelLib = params.parallelLib.in();
1145 if (parallelLib != "Mpi" && parallelLib != "Dummy")
1147 INFOS("[checkPaCOParameters] parallelLib is not correctly defined");
1148 INFOS("[checkPaCOParameters] you can chosse between: Mpi and Dummy");
1149 INFOS("[checkPaCOParameters] you entered: " << parallelLib);
1153 if (params.nb_proc <= 0)
1155 INFOS("[checkPaCOParameters] You must define a nb_proc > 0");
1159 // Step 2 : check resource_selected
1160 Engines::ResourceDefinition_var resource_definition = _ResManager->GetResourceDefinition(resource_selected.c_str());
1161 std::string protocol = resource_definition->protocol.in();
1162 std::string username = resource_definition->username.in();
1163 std::string applipath = resource_definition->applipath.in();
1165 if (protocol == "" || username == "" || applipath == "")
1167 INFOS("[checkPaCOParameters] resource selected is not well defined");
1168 INFOS("[checkPaCOParameters] resource name: " << resource_definition->name.in());
1169 INFOS("[checkPaCOParameters] resource hostname: " << resource_definition->hostname.in());
1170 INFOS("[checkPaCOParameters] resource protocol: " << protocol);
1171 INFOS("[checkPaCOParameters] resource username: " << username);
1172 INFOS("[checkPaCOParameters] resource applipath: " << applipath);
1178 #ifdef WITH_PACO_PARALLEL
1180 //=============================================================================
1182 * Start a suitable PaCO++ Parallel Container in a list of machines.
1183 * \param params Container Parameters required for the container
1184 * \return CORBA container reference.
1186 //=============================================================================
1187 Engines::Container_ptr
1188 SALOME_ContainerManager::StartPaCOPPContainer(const Engines::ContainerParameters& params_const,
1189 std::string resource_selected)
1191 CORBA::Object_var obj;
1192 PaCO::InterfaceManager_var container_proxy;
1193 Engines::Container_ptr ret = Engines::Container::_nil();
1194 Engines::ContainerParameters params(params_const);
1195 params.resource_params.name = CORBA::string_dup(resource_selected.c_str());
1197 // Step 0 : Check parameters
1198 if (!checkPaCOParameters(params, resource_selected))
1200 INFOS("[StartPaCOPPContainer] check parameters failed ! see logs...");
1204 // Step 1 : Starting a new parallel container !
1205 INFOS("[StartPaCOPPContainer] Starting a PaCO++ parallel container");
1206 INFOS("[StartPaCOPPContainer] on resource : " << resource_selected);
1208 // Step 2 : Get a MachineFile for the parallel container
1209 std::string machine_file_name = _ResManager->getMachineFile(resource_selected,
1211 params.parallelLib.in());
1213 if (machine_file_name == "")
1215 INFOS("[StartPaCOPPContainer] Machine file generation failed");
1219 // Step 3 : starting parallel container proxy
1220 std::string command_proxy("");
1221 std::string proxy_machine;
1224 command_proxy = BuildCommandToLaunchPaCOProxyContainer(params, machine_file_name, proxy_machine);
1226 catch(const SALOME_Exception & ex)
1228 INFOS("[StartPaCOPPContainer] Exception in BuildCommandToLaunchPaCOContainer");
1232 obj = LaunchPaCOProxyContainer(command_proxy, params, proxy_machine);
1233 if (CORBA::is_nil(obj))
1235 INFOS("[StartPaCOPPContainer] LaunchPaCOContainer for proxy returns NIL !");
1238 container_proxy = PaCO::InterfaceManager::_narrow(obj);
1239 MESSAGE("[StartPaCOPPContainer] PaCO container proxy is launched");
1241 // Step 4 : starting parallel container nodes
1242 std::string command_nodes("");
1243 SALOME_ContainerManager::actual_launch_machine_t nodes_machines;
1246 command_nodes = BuildCommandToLaunchPaCONodeContainer(params, machine_file_name, nodes_machines, proxy_machine);
1248 catch(const SALOME_Exception & ex)
1250 INFOS("[StarPaCOPPContainer] Exception in BuildCommandToLaunchPaCONodeContainer");
1255 std::string container_generic_node_name = std::string(params.container_name.in()) + std::string("Node");
1256 bool result = LaunchPaCONodeContainer(command_nodes, params, container_generic_node_name, nodes_machines);
1259 INFOS("[StarPaCOPPContainer] LaunchPaCONodeContainer failed !");
1260 // Il faut tuer le proxy
1263 Engines::Container_var proxy = Engines::Container::_narrow(container_proxy);
1268 INFOS("[StarPaCOPPContainer] Exception catched from proxy Shutdown...");
1273 // Step 4 : connecting nodes and the proxy to actually create a parallel container
1274 for (int i = 0; i < params.nb_proc; i++)
1276 std::ostringstream tmp;
1278 std::string proc_number = tmp.str();
1279 std::string container_node_name = container_generic_node_name + proc_number;
1281 std::string theNodeMachine(nodes_machines[i]);
1282 std::string containerNameInNS = _NS->BuildContainerNameForNS(container_node_name.c_str(), theNodeMachine.c_str());
1283 obj = _NS->Resolve(containerNameInNS.c_str());
1284 if (CORBA::is_nil(obj))
1286 INFOS("[StarPaCOPPContainer] CONNECTION FAILED From Naming Service !");
1287 INFOS("[StarPaCOPPContainer] Container name is " << containerNameInNS);
1292 MESSAGE("[StarPaCOPPContainer] Deploying node : " << container_node_name);
1293 PaCO::InterfaceParallel_var node = PaCO::InterfaceParallel::_narrow(obj);
1295 MESSAGE("[StarPaCOPPContainer] node " << container_node_name << " is deployed");
1297 catch(CORBA::SystemException& e)
1299 INFOS("[StarPaCOPPContainer] Exception in deploying node : " << containerNameInNS);
1300 INFOS("CORBA::SystemException : " << e);
1303 catch(CORBA::Exception& e)
1305 INFOS("[StarPaCOPPContainer] Exception in deploying node : " << containerNameInNS);
1306 INFOS("CORBA::Exception" << e);
1311 INFOS("[StarPaCOPPContainer] Exception in deploying node : " << containerNameInNS);
1312 INFOS("Unknown exception !");
1317 // Step 5 : starting parallel container
1320 MESSAGE ("[StarPaCOPPContainer] Starting parallel object");
1321 container_proxy->start();
1322 MESSAGE ("[StarPaCOPPContainer] Parallel object is started");
1323 ret = Engines::Container::_narrow(container_proxy);
1325 catch(CORBA::SystemException& e)
1327 INFOS("Caught CORBA::SystemException. : " << e);
1329 catch(PortableServer::POA::ServantAlreadyActive&)
1331 INFOS("Caught CORBA::ServantAlreadyActiveException");
1333 catch(CORBA::Exception&)
1335 INFOS("Caught CORBA::Exception.");
1337 catch(std::exception& exc)
1339 INFOS("Caught std::exception - "<<exc.what());
1343 INFOS("Caught unknown exception.");
1349 SALOME_ContainerManager::BuildCommandToLaunchPaCOProxyContainer(const Engines::ContainerParameters& params,
1350 std::string machine_file_name,
1351 std::string & proxy_hostname)
1353 // In the proxy case, we always launch a Dummy Proxy
1354 std::string exe_name = "SALOME_ParallelContainerProxyDummy";
1355 std::string container_name = params.container_name.in();
1357 // Convert nb_proc in string
1358 std::ostringstream tmp_string;
1359 tmp_string << params.nb_proc;
1360 std::string nb_proc_str = tmp_string.str();
1362 // Get resource definition
1363 Engines::ResourceDefinition_var resource_definition =
1364 _ResManager->GetResourceDefinition(params.resource_params.name);
1367 std::string hostname;
1368 std::ifstream machine_file(machine_file_name.c_str());
1369 std::getline(machine_file, hostname, ' ');
1370 size_t found = hostname.find('\n');
1371 if (found!=std::string::npos)
1372 hostname.erase(found, 1); // Remove \n
1373 proxy_hostname = hostname;
1374 MESSAGE("[BuildCommandToLaunchPaCOProxyContainer] machine file name extracted is " << hostname);
1377 bool remote_execution = false;
1378 if (hostname != std::string(Kernel_Utils::GetHostname()))
1380 MESSAGE("[BuildCommandToLaunchPaCOProxyContainer] remote machine case detected !");
1381 remote_execution = true;
1384 // Log environnement
1385 std::string log_type("");
1386 char * get_val = getenv("PARALLEL_LOG");
1390 // Generating the command
1391 std::string command_begin("");
1392 std::string command_end("");
1393 std::ostringstream command;
1395 LogConfiguration(log_type, "proxy", container_name, hostname, command_begin, command_end);
1396 command << command_begin;
1398 // Adding connection command
1399 // We can only have a remote execution with
1400 // a SALOME application
1401 if (remote_execution)
1403 ASSERT(getenv("NSHOST"));
1404 ASSERT(getenv("NSPORT"));
1406 command << resource_definition->protocol.in();
1408 command << resource_definition->username.in();
1409 command << " " << hostname;
1410 command << " " << resource_definition->applipath.in();
1411 command << "/runRemote.sh ";
1412 command << getenv("NSHOST") << " "; // hostname of CORBA name server
1413 command << getenv("NSPORT") << " "; // port of CORBA name server
1416 command << exe_name;
1417 command << " " << container_name;
1418 command << " Dummy";
1419 command << " " << hostname;
1420 command << " " << nb_proc_str;
1422 AddOmninamesParams(command);
1425 command << command_end;
1426 MESSAGE("[BuildCommandToLaunchPaCOProxyContainer] Command is: " << command.str());
1428 return command.str();
1432 SALOME_ContainerManager::BuildCommandToLaunchPaCONodeContainer(const Engines::ContainerParameters& params,
1433 const std::string & machine_file_name,
1434 SALOME_ContainerManager::actual_launch_machine_t & vect_machine,
1435 const std::string & proxy_hostname)
1438 std::string exe_name = "SALOME_ParallelContainerNode";
1439 exe_name += params.parallelLib.in();
1440 std::string container_name = params.container_name.in();
1442 // Convert nb_proc in string
1443 std::ostringstream nb_proc_stream;
1444 nb_proc_stream << params.nb_proc;
1446 // Get resource definition
1447 Engines::ResourceDefinition_var resource_definition =
1448 _ResManager->GetResourceDefinition(params.resource_params.name);
1450 // Log environnement
1451 std::string log_type("");
1452 char * get_val = getenv("PARALLEL_LOG");
1456 // Now the command is different according to paralleLib
1457 std::ostringstream command_nodes;
1458 std::ifstream machine_file(machine_file_name.c_str());
1459 if (std::string(params.parallelLib.in()) == "Dummy")
1461 for (int i= 0; i < params.nb_proc; i++)
1464 std::string hostname;
1465 std::getline(machine_file, hostname);
1466 MESSAGE("[BuildCommandToLaunchPaCONodeContainer] machine file name extracted is " << hostname);
1469 bool remote_execution = false;
1470 if (hostname != std::string(Kernel_Utils::GetHostname()))
1472 MESSAGE("[BuildCommandToLaunchPaCONodeContainer] remote machine case detected !");
1473 remote_execution = true;
1476 // For each node we have a new command
1477 // Generating the command
1478 std::ostringstream command_node_stream;
1479 std::string command_node_begin("");
1480 std::string command_node_end("");
1481 std::ostringstream node_number;
1483 std::string container_node_name = container_name + node_number.str();
1484 LogConfiguration(log_type, "node", container_node_name, hostname, command_node_begin, command_node_end);
1486 // Adding connection command
1487 // We can only have a remote execution with
1488 // a SALOME application
1489 if (remote_execution)
1491 ASSERT(getenv("NSHOST"));
1492 ASSERT(getenv("NSPORT"));
1494 command_node_stream << resource_definition->protocol.in();
1495 command_node_stream << " -l ";
1496 command_node_stream << resource_definition->username.in();
1497 command_node_stream << " " << hostname;
1498 command_node_stream << " " << resource_definition->applipath.in();
1499 command_node_stream << "/runRemote.sh ";
1500 command_node_stream << getenv("NSHOST") << " "; // hostname of CORBA name server
1501 command_node_stream << getenv("NSPORT") << " "; // port of CORBA name server
1504 command_node_stream << exe_name;
1505 command_node_stream << " " << container_name;
1506 command_node_stream << " " << params.parallelLib.in();
1507 command_node_stream << " " << proxy_hostname;
1508 command_node_stream << " " << node_number.str();
1509 command_node_stream << " -";
1510 AddOmninamesParams(command_node_stream);
1512 command_nodes << command_node_begin << command_node_stream.str() << command_node_end;
1513 vect_machine.push_back(hostname);
1517 else if (std::string(params.parallelLib.in()) == "Mpi")
1520 std::string hostname;
1521 std::getline(machine_file, hostname, ' ');
1522 MESSAGE("[BuildCommandToLaunchPaCONodeContainer] machine file name extracted is " << hostname);
1525 bool remote_execution = false;
1526 if (hostname != std::string(Kernel_Utils::GetHostname()))
1528 MESSAGE("[BuildCommandToLaunchPaCONodeContainer] remote machine case detected !");
1529 remote_execution = true;
1532 // In case of Mpi and Remote, we copy machine_file in the applipath
1533 // scp mpi_machine_file user@machine:Path
1534 std::ostringstream command_remote_stream;
1535 std::string::size_type last = machine_file_name.find_last_of("/");
1536 if (last == std::string::npos)
1539 std::string protocol = resource_definition->protocol.in();
1540 if (protocol == "rsh")
1541 command_remote_stream << "rcp ";
1543 command_remote_stream << "scp ";
1544 command_remote_stream << machine_file_name << " ";
1545 command_remote_stream << resource_definition->username.in() << "@";
1546 command_remote_stream << hostname << ":" << resource_definition->applipath.in();
1547 command_remote_stream << "/" << machine_file_name.substr(last+1);
1549 int status = system(command_remote_stream.str().c_str());
1552 INFOS("copy of the MPI machine file failed ! - sorry !");
1556 // Generating the command
1557 std::string command_begin("");
1558 std::string command_end("");
1560 LogConfiguration(log_type, "nodes", container_name, hostname, command_begin, command_end);
1561 command_nodes << command_begin;
1563 // Adding connection command
1564 // We can only have a remote execution with
1565 // a SALOME application
1566 if (remote_execution)
1568 ASSERT(getenv("NSHOST"));
1569 ASSERT(getenv("NSPORT"));
1571 command_nodes << resource_definition->protocol.in();
1572 command_nodes << " -l ";
1573 command_nodes << resource_definition->username.in();
1574 command_nodes << " " << hostname;
1575 command_nodes << " " << resource_definition->applipath.in();
1576 command_nodes << "/runRemote.sh ";
1577 command_nodes << getenv("NSHOST") << " "; // hostname of CORBA name server
1578 command_nodes << getenv("NSPORT") << " "; // port of CORBA name server
1581 if (std::string(resource_definition->mpiImpl.in()) == "lam")
1583 command_nodes << "mpiexec -ssi boot ";
1584 command_nodes << "-machinefile " << machine_file_name << " ";
1585 command_nodes << "-n " << params.nb_proc;
1589 command_nodes << "mpirun -np " << params.nb_proc;
1591 command_nodes << " " << exe_name;
1592 command_nodes << " " << container_name;
1593 command_nodes << " " << params.parallelLib.in();
1594 command_nodes << " " << proxy_hostname;
1595 command_nodes << " -";
1596 AddOmninamesParams(command_nodes);
1598 // We don't put hostname, because nodes are registered in the resource of the proxy
1599 for (int i= 0; i < params.nb_proc; i++)
1600 vect_machine.push_back(proxy_hostname);
1602 command_nodes << command_end;
1604 return command_nodes.str();
1608 SALOME_ContainerManager::LogConfiguration(const std::string & log_type,
1609 const std::string & exe_type,
1610 const std::string & container_name,
1611 const std::string & hostname,
1612 std::string & begin,
1615 if(log_type == "xterm")
1617 begin = "xterm -e \"export LD_LIBRARY_PATH=$LD_LIBRARY_PATH; export PATH=$PATH;";
1620 else if(log_type == "xterm_debug")
1622 begin = "xterm -e \"export LD_LIBRARY_PATH=$LD_LIBRARY_PATH; export PATH=$PATH;";
1627 // default into a file...
1628 std::string logFilename = "/tmp/" + container_name + "_" + hostname + "_" + exe_type + "_";
1629 logFilename += std::string(getenv("USER")) + ".log";
1630 end = " > " + logFilename + " 2>&1 & ";
1635 SALOME_ContainerManager::LaunchPaCOProxyContainer(const std::string& command,
1636 const Engines::ContainerParameters& params,
1637 const std::string & hostname)
1639 PaCO::InterfaceManager_ptr container_proxy = PaCO::InterfaceManager::_nil();
1641 MESSAGE("[LaunchPaCOProxyContainer] Launch command");
1642 int status = system(command.c_str());
1644 INFOS("[LaunchPaCOProxyContainer] failed : system command status -1");
1645 return container_proxy;
1647 else if (status == 217) {
1648 INFOS("[LaunchPaCOProxyContainer] failed : system command status 217");
1649 return container_proxy;
1652 int count = TIME_OUT_TO_LAUNCH_CONT;
1653 CORBA::Object_var obj = CORBA::Object::_nil();
1654 std::string containerNameInNS = _NS->BuildContainerNameForNS(params.container_name.in(),
1656 MESSAGE("[LaunchParallelContainer] Waiting for Parallel Container proxy : " << containerNameInNS);
1658 while (CORBA::is_nil(obj) && count)
1662 obj = _NS->Resolve(containerNameInNS.c_str());
1667 container_proxy = PaCO::InterfaceManager::_narrow(obj);
1669 catch(CORBA::SystemException& e)
1671 INFOS("[StarPaCOPPContainer] Exception in _narrow after LaunchParallelContainer for proxy !");
1672 INFOS("CORBA::SystemException : " << e);
1673 return container_proxy;
1675 catch(CORBA::Exception& e)
1677 INFOS("[StarPaCOPPContainer] Exception in _narrow after LaunchParallelContainer for proxy !");
1678 INFOS("CORBA::Exception" << e);
1679 return container_proxy;
1683 INFOS("[StarPaCOPPContainer] Exception in _narrow after LaunchParallelContainer for proxy !");
1684 INFOS("Unknown exception !");
1685 return container_proxy;
1687 if (CORBA::is_nil(container_proxy))
1689 INFOS("[StarPaCOPPContainer] PaCO::InterfaceManager::_narrow returns NIL !");
1690 return container_proxy;
1695 //=============================================================================
1696 /*! This method launches the parallel container.
1697 * It will may be placed on the ressources manager.
1699 * \param command to launch
1700 * \param container's parameters
1701 * \param name of the container
1703 * \return CORBA container reference
1705 //=============================================================================
1707 SALOME_ContainerManager::LaunchPaCONodeContainer(const std::string& command,
1708 const Engines::ContainerParameters& params,
1709 const std::string& name,
1710 SALOME_ContainerManager::actual_launch_machine_t & vect_machine)
1712 INFOS("[LaunchPaCONodeContainer] Launch command");
1713 int status = system(command.c_str());
1715 INFOS("[LaunchPaCONodeContainer] failed : system command status -1");
1718 else if (status == 217) {
1719 INFOS("[LaunchPaCONodeContainer] failed : system command status 217");
1723 INFOS("[LaunchPaCONodeContainer] Waiting for the nodes of the parallel container");
1724 // We are waiting all the nodes
1725 for (int i = 0; i < params.nb_proc; i++)
1727 CORBA::Object_var obj = CORBA::Object::_nil();
1728 std::string theMachine(vect_machine[i]);
1730 std::ostringstream tmp;
1732 std::string proc_number = tmp.str();
1733 std::string container_node_name = name + proc_number;
1734 std::string containerNameInNS = _NS->BuildContainerNameForNS((char*) container_node_name.c_str(), theMachine.c_str());
1735 INFOS("[LaunchPaCONodeContainer] Waiting for Parallel Container node " << containerNameInNS << " on " << theMachine);
1736 int count = TIME_OUT_TO_LAUNCH_CONT;
1737 while (CORBA::is_nil(obj) && count) {
1740 obj = _NS->Resolve(containerNameInNS.c_str());
1742 if (CORBA::is_nil(obj))
1744 INFOS("[LaunchPaCONodeContainer] Launch of node failed (or not found) !");
1753 Engines::Container_ptr
1754 SALOME_ContainerManager::StartPaCOPPContainer(const Engines::ContainerParameters& params,
1755 std::string resource_selected)
1757 Engines::Container_ptr ret = Engines::Container::_nil();
1758 INFOS("[StarPaCOPPContainer] is disabled !");
1759 INFOS("[StarPaCOPPContainer] recompile SALOME Kernel to enable PaCO++ parallel extension");
1764 SALOME_ContainerManager::BuildCommandToLaunchPaCOProxyContainer(const Engines::ContainerParameters& params,
1765 std::string machine_file_name,
1766 std::string & proxy_hostname)
1772 SALOME_ContainerManager::BuildCommandToLaunchPaCONodeContainer(const Engines::ContainerParameters& params,
1773 const std::string & machine_file_name,
1774 SALOME_ContainerManager::actual_launch_machine_t & vect_machine,
1775 const std::string & proxy_hostname)
1780 SALOME_ContainerManager::LogConfiguration(const std::string & log_type,
1781 const std::string & exe_type,
1782 const std::string & container_name,
1783 const std::string & hostname,
1784 std::string & begin,
1790 SALOME_ContainerManager::LaunchPaCOProxyContainer(const std::string& command,
1791 const Engines::ContainerParameters& params,
1792 const std::string& hostname)
1794 CORBA::Object_ptr ret = CORBA::Object::_nil();
1799 SALOME_ContainerManager::LaunchPaCONodeContainer(const std::string& command,
1800 const Engines::ContainerParameters& params,
1801 const std::string& name,
1802 SALOME_ContainerManager::actual_launch_machine_t & vect_machine)