1 // Copyright (C) 2007-2012 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"
41 #define getpid _getpid
44 #ifdef WITH_PACO_PARALLEL
48 #define TIME_OUT_TO_LAUNCH_CONT 60
50 const char *SALOME_ContainerManager::_ContainerManagerNameInNS =
53 omni_mutex SALOME_ContainerManager::_numInstanceMutex;
56 //=============================================================================
60 * Define a CORBA single thread policy for the server, which avoid to deal
61 * with non thread-safe usage like Change_Directory in SALOME naming service
63 //=============================================================================
65 SALOME_ContainerManager::SALOME_ContainerManager(CORBA::ORB_ptr orb, PortableServer::POA_var poa, SALOME_ResourcesManager *rm, SALOME_NamingService *ns):_nbprocUsed(1)
67 MESSAGE("constructor");
71 PortableServer::POAManager_var pman = poa->the_POAManager();
72 _orb = CORBA::ORB::_duplicate(orb) ;
73 CORBA::PolicyList policies;
75 PortableServer::ThreadPolicy_var threadPol =
76 poa->create_thread_policy(PortableServer::SINGLE_THREAD_MODEL);
77 policies[0] = PortableServer::ThreadPolicy::_duplicate(threadPol);
79 _poa = poa->create_POA("SThreadPOA",pman,policies);
81 PortableServer::ObjectId_var id = _poa->activate_object(this);
82 CORBA::Object_var obj = _poa->id_to_reference(id);
83 Engines::ContainerManager_var refContMan =
84 Engines::ContainerManager::_narrow(obj);
86 _NS->Register(refContMan,_ContainerManagerNameInNS);
87 _isAppliSalomeDefined = (getenv("APPLI") != 0);
92 // the urifile name depends on pid of the process
93 std::stringstream urifile;
94 urifile << getenv("HOME") << "/.urifile_" << getpid();
95 setenv("OMPI_URI_FILE",urifile.str().c_str(),1);
96 if( getenv("OMPI_URI_FILE") != NULL ){
97 // get the pid of all ompi-server
98 std::set<pid_t> thepids1 = getpidofprogram("ompi-server");
99 // launch a new ompi-server
101 command = "ompi-server -r ";
102 command += getenv("OMPI_URI_FILE");
103 int status=system(command.c_str());
105 throw SALOME_Exception("Error when launching ompi-server");
106 // get the pid of all ompi-server
107 std::set<pid_t> thepids2 = getpidofprogram("ompi-server");
108 // my ompi-server is the new one
109 std::set<pid_t>::const_iterator it;
110 for(it=thepids2.begin();it!=thepids2.end();it++)
111 if(thepids1.find(*it) == thepids1.end())
112 _pid_mpiServer = *it;
113 if(_pid_mpiServer < 0)
114 throw SALOME_Exception("Error when getting ompi-server id");
116 #elif defined(WITHMPICH)
118 // get the pid of all hydra_nameserver
119 std::set<pid_t> thepids1 = getpidofprogram("hydra_nameserver");
120 // launch a new hydra_nameserver
122 command = "hydra_nameserver &";
123 system(command.c_str());
124 // get the pid of all hydra_nameserver
125 std::set<pid_t> thepids2 = getpidofprogram("hydra_nameserver");
126 // my hydra_nameserver is the new one
127 std::set<pid_t>::const_iterator it;
128 for(it=thepids2.begin();it!=thepids2.end();it++)
129 if(thepids1.find(*it) == thepids1.end())
130 _pid_mpiServer = *it;
134 MESSAGE("constructor end");
137 //=============================================================================
141 //=============================================================================
143 SALOME_ContainerManager::~SALOME_ContainerManager()
145 MESSAGE("destructor");
148 if( getenv("OMPI_URI_FILE") != NULL ){
149 // kill my ompi-server
150 if( kill(_pid_mpiServer,SIGTERM) != 0 )
151 throw SALOME_Exception("Error when killing ompi-server");
153 int status=system("rm -f ${OMPI_URI_FILE}");
155 throw SALOME_Exception("Error when removing urifile");
157 #elif defined(WITHMPICH)
158 // kill my hydra_nameserver
159 if(_pid_mpiServer > -1)
160 if( kill(_pid_mpiServer,SIGTERM) != 0 )
161 throw SALOME_Exception("Error when killing hydra_nameserver");
166 //=============================================================================
167 //! shutdown all the containers, then the ContainerManager servant
170 //=============================================================================
172 void SALOME_ContainerManager::Shutdown()
175 ShutdownContainers();
176 _NS->Destroy_Name(_ContainerManagerNameInNS);
177 PortableServer::ObjectId_var oid = _poa->servant_to_id(this);
178 _poa->deactivate_object(oid);
181 //=============================================================================
182 //! Loop on all the containers listed in naming service, ask shutdown on each
185 //=============================================================================
187 void SALOME_ContainerManager::ShutdownContainers()
189 MESSAGE("ShutdownContainers");
191 isOK = _NS->Change_Directory("/Containers");
193 std::vector<std::string> vec = _NS->list_directory_recurs();
194 std::list<std::string> lstCont;
195 for(std::vector<std::string>::iterator iter = vec.begin();iter!=vec.end();iter++)
198 CORBA::Object_var obj=_NS->Resolve((*iter).c_str());
201 Engines::Container_var cont=Engines::Container::_narrow(obj);
202 if(!CORBA::is_nil(cont))
203 lstCont.push_back((*iter));
205 catch(const CORBA::Exception& e)
207 // ignore this entry and continue
210 MESSAGE("Container list: ");
211 for(std::list<std::string>::iterator iter=lstCont.begin();iter!=lstCont.end();iter++){
214 for(std::list<std::string>::iterator iter=lstCont.begin();iter!=lstCont.end();iter++)
219 CORBA::Object_var obj=_NS->Resolve((*iter).c_str());
220 Engines::Container_var cont=Engines::Container::_narrow(obj);
221 if(!CORBA::is_nil(cont))
223 MESSAGE("ShutdownContainers: " << (*iter));
227 MESSAGE("ShutdownContainers: no container ref for " << (*iter));
229 catch(CORBA::SystemException& e)
231 INFOS("CORBA::SystemException ignored : " << e);
233 catch(CORBA::Exception&)
235 INFOS("CORBA::Exception ignored.");
239 INFOS("Unknown exception ignored.");
245 //=============================================================================
246 //! Give a suitable Container given constraints
248 * \param params Container Parameters required for the container
249 * \return the container or nil
251 //=============================================================================
252 Engines::Container_ptr
253 SALOME_ContainerManager::GiveContainer(const Engines::ContainerParameters& params)
255 std::string machFile;
256 Engines::Container_ptr ret = Engines::Container::_nil();
258 // Step 0: Default mode is start
259 Engines::ContainerParameters local_params(params);
260 if (std::string(local_params.mode.in()) == "")
261 local_params.mode = CORBA::string_dup("start");
262 std::string mode = local_params.mode.in();
263 MESSAGE("[GiveContainer] starting with mode: " << mode);
265 // Step 1: Find Container for find and findorstart mode
266 if (mode == "find" || mode == "findorstart")
268 ret = FindContainer(params, params.resource_params.resList);
269 if(!CORBA::is_nil(ret))
275 MESSAGE("[GiveContainer] no container found");
285 // Step 2: Get all possibleResources from the parameters
286 Engines::ResourceList_var possibleResources = _ResManager->GetFittingResources(local_params.resource_params);
287 MESSAGE("[GiveContainer] - length of possible resources " << possibleResources->length());
288 std::vector<std::string> local_resources;
290 // Step 3: if mode is "get" keep only machines with existing containers
293 for(unsigned int i=0; i < possibleResources->length(); i++)
295 Engines::Container_ptr cont = FindContainer(params, possibleResources[i].in());
298 if(!cont->_non_existent())
299 local_resources.push_back(std::string(possibleResources[i]));
301 catch(CORBA::Exception&) {}
304 // if local_resources is empty, we cannot give a container
305 if (local_resources.size() == 0)
307 MESSAGE("[GiveContainer] cannot find a container for mode get");
312 for(unsigned int i=0; i < possibleResources->length(); i++)
313 local_resources.push_back(std::string(possibleResources[i]));
315 // Step 4: select the resource where to get/start the container
316 bool resource_available = true;
317 std::string resource_selected;
318 std::vector<std::string> resources = local_resources;
319 while (resource_available)
321 if (resources.size() == 0)
322 resource_available = false;
327 resource_selected = _ResManager->GetImpl()->Find(params.resource_params.policy.in(), resources);
328 // Remove resource_selected from vector
329 std::vector<std::string>::iterator it;
330 for (it=resources.begin() ; it < resources.end(); it++ )
331 if (*it == resource_selected)
337 catch(const SALOME_Exception &ex)
339 MESSAGE("[GiveContainer] Exception in ResourceManager find !: " << ex.what());
342 MESSAGE("[GiveContainer] Resource selected is: " << resource_selected);
344 // Step 5: Create container name
345 Engines::ResourceDefinition_var resource_definition = _ResManager->GetResourceDefinition(resource_selected.c_str());
346 std::string hostname(resource_definition->hostname.in());
347 std::string containerNameInNS;
350 if ( params.nb_proc <= 0 )
353 nbproc = params.nb_proc;
356 if( getenv("LIBBATCH_NODEFILE") != NULL )
357 machFile = machinesFile(nbproc);
359 catch(const SALOME_Exception & ex)
361 std::string err_msg = ex.what();
362 err_msg += params.container_name;
363 INFOS(err_msg.c_str());
366 // A mpi parallel container register on zero node in NS
367 containerNameInNS = _NS->BuildContainerNameForNS(params, GetMPIZeroNode(hostname,machFile).c_str());
370 containerNameInNS = _NS->BuildContainerNameForNS(params, hostname.c_str());
371 MESSAGE("[GiveContainer] Container name in the naming service: " << containerNameInNS);
373 // Step 6: check if the name exists in naming service
374 //if params.mode == "getorstart" or "get" use the existing container
375 //if params.mode == "start" shutdown the existing container before launching a new one with that name
376 CORBA::Object_var obj = _NS->Resolve(containerNameInNS.c_str());
377 if (!CORBA::is_nil(obj))
381 Engines::Container_var cont=Engines::Container::_narrow(obj);
382 if(!cont->_non_existent())
384 if(std::string(params.mode.in())=="getorstart" || std::string(params.mode.in())=="get"){
385 return cont._retn(); /* the container exists and params.mode is getorstart or get use it*/
389 INFOS("[GiveContainer] A container is already registered with the name: " << containerNameInNS << ", shutdown the existing container");
390 cont->Shutdown(); // shutdown the registered container if it exists
394 catch(CORBA::Exception&)
396 INFOS("[GiveContainer] CORBA::Exception ignored when trying to get the container - we start a new one");
399 Engines::Container_var cont = LaunchContainer(params, resource_selected, hostname, machFile, containerNameInNS);
400 if (!CORBA::is_nil(cont))
402 INFOS("[GiveContainer] container " << containerNameInNS << " launched");
407 INFOS("[GiveContainer] Failed to launch container on resource " << resource_selected);
412 // We were not able to launch the container
413 INFOS("[GiveContainer] Cannot launch the container on the following selected resources:")
414 std::vector<std::string>::iterator it;
415 for (it=local_resources.begin() ; it < local_resources.end(); it++ )
416 INFOS("[GiveContainer] " << *it)
420 Engines::Container_ptr
421 SALOME_ContainerManager::LaunchContainer(const Engines::ContainerParameters& params,
422 const std::string & resource_selected,
423 const std::string & hostname,
424 const std::string & machFile,
425 const std::string & containerNameInNS)
428 // Step 1: type of container: PaCO, Exe, Mpi or Classic
429 // Mpi already tested in step 5, specific code on BuildCommandToLaunch Local/Remote Container methods
430 // TODO -> separates Mpi from Classic/Exe
432 std::string container_exe = "SALOME_Container"; // Classic container
433 Engines::ContainerParameters local_params(params);
434 Engines::Container_ptr ret = Engines::Container::_nil();
438 CORBA::String_var container_exe_tmp;
439 CORBA::Object_var obj = _NS->Resolve("/Kernel/ModulCatalog");
440 SALOME_ModuleCatalog::ModuleCatalog_var Catalog = SALOME_ModuleCatalog::ModuleCatalog::_narrow(obj) ;
441 if (CORBA::is_nil (Catalog))
443 INFOS("[GiveContainer] Module Catalog is not found -> cannot launch a container");
446 // Loop through component list
447 for(unsigned int i=0; i < local_params.resource_params.componentList.length(); i++)
449 const char* compoi = local_params.resource_params.componentList[i];
450 SALOME_ModuleCatalog::Acomponent_var compoInfo = Catalog->GetComponent(compoi);
451 if (CORBA::is_nil (compoInfo))
455 SALOME_ModuleCatalog::ImplType impl=compoInfo->implementation_type();
456 container_exe_tmp=compoInfo->implementation_name();
457 if(impl==SALOME_ModuleCatalog::CEXE)
461 INFOS("ContainerManager Error: you can't have 2 CEXE component in the same container" );
462 return Engines::Container::_nil();
464 MESSAGE("[GiveContainer] Exe container found !: " << container_exe_tmp);
465 container_exe = container_exe_tmp.in();
470 catch (ServiceUnreachable&)
472 INFOS("Caught exception: Naming Service Unreachable");
477 INFOS("Caught unknown exception.");
481 // Step 2: test resource
482 // Only if an application directory is set
483 if(hostname != Kernel_Utils::GetHostname() && _isAppliSalomeDefined)
485 // Preparing remote command
486 std::string command = "";
487 const ParserResourcesType& resInfo = _ResManager->GetImpl()->GetResourcesDescr(resource_selected);
488 command = getCommandToRunRemoteProcess(resInfo.Protocol, resInfo.HostName, resInfo.UserName);
489 if (resInfo.AppliPath != "")
490 command += resInfo.AppliPath;
493 ASSERT(getenv("APPLI"));
494 command += getenv("APPLI");
496 command += "/runRemote.sh ";
497 ASSERT(getenv("NSHOST"));
498 command += getenv("NSHOST"); // hostname of CORBA name server
500 ASSERT(getenv("NSPORT"));
501 command += getenv("NSPORT"); // port of CORBA name server
502 command += " ls /tmp";
504 // Launch remote command
505 int status = system(command.c_str());
508 // Error on resource - cannot launch commands
509 INFOS("[LaunchContainer] Cannot launch commands on machine " << hostname);
510 INFOS("[LaunchContainer] Command was " << command);
512 INFOS("[LaunchContainer] Command status is " << WEXITSTATUS(status));
514 return Engines::Container::_nil();
518 // Step 3: start a new container
519 // Check if a PaCO container
521 if (std::string(local_params.parallelLib.in()) != "")
523 ret = StartPaCOPPContainer(params, resource_selected);
526 // Other type of containers...
527 MESSAGE("[GiveContainer] Try to launch a new container on " << resource_selected);
529 // if a parallel container is launched in batch job, command is: "mpirun -np nbproc -machinefile nodesfile SALOME_MPIContainer"
530 if( getenv("LIBBATCH_NODEFILE") != NULL && params.isMPI )
531 command = BuildCommandToLaunchLocalContainer(params, machFile, container_exe);
532 // if a container is launched on localhost, command is "SALOME_Container" or "mpirun -np nbproc SALOME_MPIContainer"
533 else if(hostname == Kernel_Utils::GetHostname())
534 command = BuildCommandToLaunchLocalContainer(params, machFile, container_exe);
535 // if a container is launched in remote mode, command is "ssh resource_selected SALOME_Container" or "ssh resource_selected mpirun -np nbproc SALOME_MPIContainer"
537 command = BuildCommandToLaunchRemoteContainer(resource_selected, params, container_exe);
539 //redirect stdout and stderr in a file
541 std::string logFilename=getenv("TEMP");
543 std::string user = getenv( "USERNAME" );
545 std::string user = getenv( "USER" );
546 std::string logFilename="/tmp";
547 char* val = getenv("SALOME_TMP_DIR");
550 struct stat file_info;
551 stat(val, &file_info);
552 bool is_dir = S_ISDIR(file_info.st_mode);
553 if (is_dir)logFilename=val;
554 else std::cerr << "SALOME_TMP_DIR environment variable is not a directory use /tmp instead" << std::endl;
558 logFilename += _NS->ContainerName(params)+"_"+ resource_selected +"_"+user;
559 std::ostringstream tmp;
560 tmp << "_" << getpid();
561 logFilename += tmp.str();
562 logFilename += ".log" ;
563 command += " > " + logFilename + " 2>&1";
565 command = "%PYTHONBIN% -c \"import win32pm ; win32pm.spawnpid(r'" + command + "', '')\"";
570 // launch container with a system call
571 int status=system(command.c_str());
574 INFOS("[LaunchContainer] command failed (system command status -1): " << command);
575 RmTmpFile(_TmpFileName); // command file can be removed here
577 return Engines::Container::_nil();
579 else if (status == 217){
580 INFOS("[LaunchContainer] command failed (system command status 217): " << command);
581 RmTmpFile(_TmpFileName); // command file can be removed here
583 return Engines::Container::_nil();
587 // Step 4: Wait for the container
588 int count = TIME_OUT_TO_LAUNCH_CONT;
589 if (getenv("TIMEOUT_TO_LAUNCH_CONTAINER") != 0)
591 std::string new_count_str = getenv("TIMEOUT_TO_LAUNCH_CONTAINER");
593 std::istringstream ss(new_count_str);
594 if (!(ss >> new_count))
596 INFOS("[LaunchContainer] TIMEOUT_TO_LAUNCH_CONTAINER should be an int");
601 INFOS("[GiveContainer] waiting " << count << " second steps container " << containerNameInNS);
602 while (CORBA::is_nil(ret) && count)
610 MESSAGE("[GiveContainer] step " << count << " Waiting for container on " << resource_selected);
611 CORBA::Object_var obj = _NS->Resolve(containerNameInNS.c_str());
612 ret=Engines::Container::_narrow(obj);
614 if (CORBA::is_nil(ret))
616 INFOS("[GiveContainer] was not able to launch container " << containerNameInNS);
620 // Setting log file name
621 logFilename=":"+logFilename;
622 logFilename="@"+Kernel_Utils::GetHostname()+logFilename;
623 logFilename=user+logFilename;
624 ret->logfilename(logFilename.c_str());
625 RmTmpFile(_TmpFileName); // command file can be removed here
632 //=============================================================================
633 //! Find a container given constraints (params) on a list of machines (possibleComputers)
637 //=============================================================================
639 Engines::Container_ptr
640 SALOME_ContainerManager::FindContainer(const Engines::ContainerParameters& params,
641 const Engines::ResourceList& possibleResources)
643 MESSAGE("[FindContainer] FindContainer on " << possibleResources.length() << " resources");
644 for(unsigned int i=0; i < possibleResources.length();i++)
646 Engines::Container_ptr cont = FindContainer(params, possibleResources[i].in());
647 if(!CORBA::is_nil(cont))
650 MESSAGE("[FindContainer] no container found");
651 return Engines::Container::_nil();
654 //=============================================================================
655 //! Find a container given constraints (params) on a machine (theMachine)
659 //=============================================================================
661 Engines::Container_ptr
662 SALOME_ContainerManager::FindContainer(const Engines::ContainerParameters& params,
663 const std::string& resource)
665 Engines::ResourceDefinition_var resource_definition = _ResManager->GetResourceDefinition(resource.c_str());
666 std::string hostname(resource_definition->hostname.in());
667 std::string containerNameInNS(_NS->BuildContainerNameForNS(params, hostname.c_str()));
668 MESSAGE("[FindContainer] Try to find a container " << containerNameInNS << " on resource " << resource);
669 CORBA::Object_var obj = _NS->Resolve(containerNameInNS.c_str());
672 if(obj->_non_existent())
673 return Engines::Container::_nil();
675 return Engines::Container::_narrow(obj);
677 catch(const CORBA::Exception& e)
679 return Engines::Container::_nil();
684 bool isPythonContainer(const char* ContainerName);
686 //=============================================================================
688 * This is no longer valid (C++ container are also python containers)
690 //=============================================================================
691 bool isPythonContainer(const char* ContainerName)
694 int len = strlen(ContainerName);
697 if (strcmp(ContainerName + len - 2, "Py") == 0)
703 //=============================================================================
705 * Builds the script to be launched
707 * If SALOME Application not defined ($APPLI),
708 * see BuildTempFileToLaunchRemoteContainer()
710 * Else rely on distant configuration. Command is under the form (example):
711 * ssh user@machine distantPath/runRemote.sh hostNS portNS WORKINGDIR workingdir \
712 * SALOME_Container containerName &"
714 * - where user is ommited if not specified in CatalogResources,
715 * - where distant path is always relative to user@machine $HOME, and
716 * equal to $APPLI if not specified in CatalogResources,
717 * - where hostNS is the hostname of CORBA naming server (set by scripts to
718 * use to launch SALOME and servers in $APPLI: runAppli.sh, runRemote.sh)
719 * - where portNS is the port used by CORBA naming server (set by scripts to
720 * use to launch SALOME and servers in $APPLI: runAppli.sh, runRemote.sh)
721 * - where workingdir is the requested working directory for the container.
722 * If WORKINGDIR (and workingdir) is not present the working dir will be $HOME
724 //=============================================================================
727 SALOME_ContainerManager::BuildCommandToLaunchRemoteContainer
728 (const std::string& resource_name,
729 const Engines::ContainerParameters& params, const std::string& container_exe)
733 if (!_isAppliSalomeDefined)
734 command = BuildTempFileToLaunchRemoteContainer(resource_name, params);
738 Engines::ResourceDefinition_var resource_definition = _ResManager->GetResourceDefinition(resource_name.c_str());
739 std::string hostname(resource_definition->hostname.in());
740 const ParserResourcesType& resInfo = _ResManager->GetImpl()->GetResourcesDescr(resource_name);
744 if ( params.nb_proc <= 0 )
747 nbproc = params.nb_proc;
750 // "ssh -l user machine distantPath/runRemote.sh hostNS portNS WORKINGDIR workingdir \
751 // SALOME_Container containerName &"
752 command = getCommandToRunRemoteProcess(resInfo.Protocol, resInfo.HostName, resInfo.UserName);
754 if (resInfo.AppliPath != "")
755 command += resInfo.AppliPath; // path relative to user@machine $HOME
758 ASSERT(getenv("APPLI"));
759 command += getenv("APPLI"); // path relative to user@machine $HOME
762 command += "/runRemote.sh ";
764 ASSERT(getenv("NSHOST"));
765 command += getenv("NSHOST"); // hostname of CORBA name server
768 ASSERT(getenv("NSPORT"));
769 command += getenv("NSPORT"); // port of CORBA name server
771 std::string wdir = params.workingdir.in();
774 command += " WORKINGDIR ";
776 if(wdir == "$TEMPDIR")
778 command += wdir; // requested working directory
784 command += " mpirun -np ";
785 std::ostringstream o;
789 command += "-x PATH,LD_LIBRARY_PATH,OMNIORB_CONFIG,SALOME_trace ";
790 #elif defined(WITHOPENMPI)
791 if( getenv("OMPI_URI_FILE") == NULL )
792 command += "-x PATH -x LD_LIBRARY_PATH -x OMNIORB_CONFIG -x SALOME_trace";
794 command += "-x PATH -x LD_LIBRARY_PATH -x OMNIORB_CONFIG -x SALOME_trace -ompi-server file:";
795 command += getenv("OMPI_URI_FILE");
797 #elif defined(WITHMPICH)
798 command += "-nameserver " + Kernel_Utils::GetHostname();
800 command += " SALOME_MPIContainer ";
803 command += " " +container_exe+ " ";
805 command += _NS->ContainerName(params);
807 AddOmninamesParams(command);
809 MESSAGE("command =" << command);
815 //=============================================================================
817 * builds the command to be launched.
819 //=============================================================================
821 SALOME_ContainerManager::BuildCommandToLaunchLocalContainer
822 (const Engines::ContainerParameters& params, const std::string& machinesFile, const std::string& container_exe)
824 _TmpFileName = BuildTemporaryFileName();
828 std::ostringstream o;
834 if ( params.nb_proc <= 0 )
837 nbproc = params.nb_proc;
841 if( getenv("LIBBATCH_NODEFILE") != NULL )
842 o << "-machinefile " << machinesFile << " ";
845 o << "-x PATH,LD_LIBRARY_PATH,OMNIORB_CONFIG,SALOME_trace ";
846 #elif defined(WITHOPENMPI)
847 if( getenv("OMPI_URI_FILE") == NULL )
848 o << "-x PATH -x LD_LIBRARY_PATH -x OMNIORB_CONFIG -x SALOME_trace";
851 o << "-x PATH -x LD_LIBRARY_PATH -x OMNIORB_CONFIG -x SALOME_trace -ompi-server file:";
852 o << getenv("OMPI_URI_FILE");
854 #elif defined(WITHMPICH)
855 o << "-nameserver " + Kernel_Utils::GetHostname();
858 if (isPythonContainer(params.container_name))
859 o << " pyMPI SALOME_ContainerPy.py ";
861 o << " SALOME_MPIContainer ";
866 std::string wdir=params.workingdir.in();
869 // a working directory is requested
870 if(wdir == "$TEMPDIR")
872 // a new temporary directory is requested
873 std::string dir = Kernel_Utils::GetTmpDir();
875 o << "cd /d " << dir << std::endl;
877 o << "cd " << dir << ";";
883 // a permanent directory is requested use it or create it
885 o << "mkdir " + wdir << std::endl;
886 o << "cd /D " + wdir << std::endl;
888 o << "mkdir -p " << wdir << " && cd " << wdir + ";";
893 if (isPythonContainer(params.container_name))
894 o << "SALOME_ContainerPy.py ";
896 o << container_exe + " ";
900 o << _NS->ContainerName(params);
902 AddOmninamesParams(o);
904 std::ofstream command_file( _TmpFileName.c_str() );
905 command_file << o.str();
906 command_file.close();
909 chmod(_TmpFileName.c_str(), 0x1ED);
911 command = _TmpFileName;
913 MESSAGE("Command is file ... " << command);
914 MESSAGE("Command is ... " << o.str());
919 //=============================================================================
921 * removes the generated temporary file in case of a remote launch.
923 //=============================================================================
925 void SALOME_ContainerManager::RmTmpFile(std::string& tmpFileName)
927 int lenght = tmpFileName.size();
931 std::string command = "del /F ";
933 std::string command = "rm ";
936 command += tmpFileName.substr(0, lenght - 3 );
938 command += tmpFileName;
940 system(command.c_str());
941 //if dir is empty - remove it
942 std::string tmp_dir = Kernel_Utils::GetDirByPath( tmpFileName );
943 if ( Kernel_Utils::IsEmptyDir( tmp_dir ) )
946 command = "del /F " + tmp_dir;
948 command = "rmdir " + tmp_dir;
950 system(command.c_str());
955 //=============================================================================
957 * add to command all options relative to naming service.
959 //=============================================================================
961 void SALOME_ContainerManager::AddOmninamesParams(std::string& command) const
963 CORBA::String_var iorstr = _NS->getIORaddr();
964 command += "ORBInitRef NameService=";
968 //=============================================================================
970 * add to command all options relative to naming service.
972 //=============================================================================
974 void SALOME_ContainerManager::AddOmninamesParams(std::ofstream& fileStream) const
976 CORBA::String_var iorstr = _NS->getIORaddr();
977 fileStream << "ORBInitRef NameService=";
978 fileStream << iorstr;
981 //=============================================================================
983 * add to command all options relative to naming service.
985 //=============================================================================
987 void SALOME_ContainerManager::AddOmninamesParams(std::ostringstream& oss) const
989 CORBA::String_var iorstr = _NS->getIORaddr();
990 oss << "ORBInitRef NameService=";
994 //=============================================================================
996 * generate a file name in /tmp directory
998 //=============================================================================
1000 std::string SALOME_ContainerManager::BuildTemporaryFileName() const
1002 //build more complex file name to support multiple salome session
1003 std::string aFileName = Kernel_Utils::GetTmpFileName();
1007 aFileName += ".bat";
1012 //=============================================================================
1014 * Builds in a temporary file the script to be launched.
1016 * Used if SALOME Application ($APPLI) is not defined.
1017 * The command is build with data from CatalogResources, in which every path
1018 * used on remote computer must be defined.
1020 //=============================================================================
1023 SALOME_ContainerManager::BuildTempFileToLaunchRemoteContainer
1024 (const std::string& resource_name,
1025 const Engines::ContainerParameters& params) throw(SALOME_Exception)
1029 _TmpFileName = BuildTemporaryFileName();
1030 std::ofstream tempOutputFile;
1031 tempOutputFile.open(_TmpFileName.c_str(), std::ofstream::out );
1032 const ParserResourcesType& resInfo = _ResManager->GetImpl()->GetResourcesDescr(resource_name);
1033 tempOutputFile << "#! /bin/sh" << std::endl;
1037 tempOutputFile << "export SALOME_trace=local" << std::endl; // mkr : 27.11.2006 : PAL13967 - Distributed supervision graphs - Problem with "SALOME_trace"
1038 //tempOutputFile << "source " << resInfo.PreReqFilePath << endl;
1044 tempOutputFile << "mpirun -np ";
1047 if ( params.nb_proc <= 0 )
1050 nbproc = params.nb_proc;
1052 std::ostringstream o;
1054 tempOutputFile << nbproc << " ";
1056 tempOutputFile << "-x PATH,LD_LIBRARY_PATH,OMNIORB_CONFIG,SALOME_trace ";
1057 #elif defined(WITHOPENMPI)
1058 if( getenv("OMPI_URI_FILE") == NULL )
1059 tempOutputFile << "-x PATH -x LD_LIBRARY_PATH -x OMNIORB_CONFIG -x SALOME_trace";
1061 tempOutputFile << "-x PATH -x LD_LIBRARY_PATH -x OMNIORB_CONFIG -x SALOME_trace -ompi-server file:";
1062 tempOutputFile << getenv("OMPI_URI_FILE");
1064 #elif defined(WITHMPICH)
1065 tempOutputFile << "-nameserver " + Kernel_Utils::GetHostname();
1069 tempOutputFile << getenv("KERNEL_ROOT_DIR") << "/bin/salome/";
1073 if (isPythonContainer(params.container_name))
1074 tempOutputFile << " pyMPI SALOME_ContainerPy.py ";
1076 tempOutputFile << " SALOME_MPIContainer ";
1081 if (isPythonContainer(params.container_name))
1082 tempOutputFile << "SALOME_ContainerPy.py ";
1084 tempOutputFile << "SALOME_Container ";
1087 tempOutputFile << _NS->ContainerName(params) << " -";
1088 AddOmninamesParams(tempOutputFile);
1089 tempOutputFile << " &" << std::endl;
1090 tempOutputFile.flush();
1091 tempOutputFile.close();
1093 chmod(_TmpFileName.c_str(), 0x1ED);
1096 // --- Build command
1098 std::string command;
1100 if (resInfo.Protocol == rsh)
1103 std::string commandRcp = "rcp ";
1104 commandRcp += _TmpFileName;
1106 commandRcp += resInfo.HostName;
1108 commandRcp += _TmpFileName;
1109 status = system(commandRcp.c_str());
1112 else if (resInfo.Protocol == ssh)
1115 std::string commandRcp = "scp ";
1116 commandRcp += _TmpFileName;
1118 commandRcp += resInfo.HostName;
1120 commandRcp += _TmpFileName;
1121 status = system(commandRcp.c_str());
1124 else if (resInfo.Protocol == srun)
1126 command = "srun -n 1 -N 1 --share --nodelist=";
1127 std::string commandRcp = "rcp ";
1128 commandRcp += _TmpFileName;
1130 commandRcp += resInfo.HostName;
1132 commandRcp += _TmpFileName;
1133 status = system(commandRcp.c_str());
1136 throw SALOME_Exception("Unknown protocol");
1139 throw SALOME_Exception("Error of connection on remote host");
1141 command += resInfo.HostName;
1142 _CommandForRemAccess = command;
1144 command += _TmpFileName;
1152 std::string SALOME_ContainerManager::GetMPIZeroNode(const std::string machine, const std::string machinesFile)
1155 std::string zeronode;
1156 std::string command;
1157 std::string tmpFile = BuildTemporaryFileName();
1159 if( getenv("LIBBATCH_NODEFILE") == NULL )
1161 if (_isAppliSalomeDefined)
1163 const ParserResourcesType& resInfo = _ResManager->GetImpl()->GetResourcesDescr(machine);
1165 if (resInfo.Protocol == rsh)
1167 else if (resInfo.Protocol == ssh)
1169 else if (resInfo.Protocol == srun)
1170 command = "srun -n 1 -N 1 --share --nodelist=";
1172 throw SALOME_Exception("Unknown protocol");
1174 if (resInfo.UserName != "")
1177 command += resInfo.UserName;
1181 command += resInfo.HostName;
1184 if (resInfo.AppliPath != "")
1185 command += resInfo.AppliPath; // path relative to user@machine $HOME
1188 ASSERT(getenv("APPLI"));
1189 command += getenv("APPLI"); // path relative to user@machine $HOME
1192 command += "/runRemote.sh ";
1194 ASSERT(getenv("NSHOST"));
1195 command += getenv("NSHOST"); // hostname of CORBA name server
1198 ASSERT(getenv("NSPORT"));
1199 command += getenv("NSPORT"); // port of CORBA name server
1201 command += " mpirun -np 1 hostname -s > " + tmpFile;
1204 command = "mpirun -np 1 hostname -s > " + tmpFile;
1207 command = "mpirun -np 1 -machinefile " + machinesFile + " hostname -s > " + tmpFile;
1209 status = system(command.c_str());
1211 std::ifstream fp(tmpFile.c_str(),std::ios::in);
1212 while(fp >> zeronode);
1220 std::string SALOME_ContainerManager::machinesFile(const int nbproc)
1223 std::string nodesFile = getenv("LIBBATCH_NODEFILE");
1224 std::string machinesFile = Kernel_Utils::GetTmpFileName();
1225 std::ifstream fpi(nodesFile.c_str(),std::ios::in);
1226 std::ofstream fpo(machinesFile.c_str(),std::ios::out);
1228 _numInstanceMutex.lock();
1230 for(int i=0;i<_nbprocUsed;i++)
1233 for(int i=0;i<nbproc;i++)
1235 fpo << tmp << std::endl;
1237 throw SALOME_Exception("You need more processors than batch session have allocated for you! Unable to launch the mpi container: ");
1239 _nbprocUsed += nbproc;
1243 _numInstanceMutex.unlock();
1245 return machinesFile;
1249 std::set<pid_t> SALOME_ContainerManager::getpidofprogram(const std::string program)
1251 std::set<pid_t> thepids;
1252 std::string tmpFile = Kernel_Utils::GetTmpFileName();
1255 cmd = "pidof " + program + " > " + tmpFile;
1256 system(cmd.c_str());
1257 std::ifstream fpi(tmpFile.c_str(),std::ios::in);
1258 while(fpi >> thepid){
1259 thepids.insert(atoi(thepid.c_str()));
1264 std::string SALOME_ContainerManager::getCommandToRunRemoteProcess(AccessProtocolType protocol,
1265 const std::string & hostname,
1266 const std::string & username)
1268 std::ostringstream command;
1275 command << "-l " << username << " ";
1277 command << hostname << " ";
1283 command << "-l " << username << " ";
1285 command << hostname << " ";
1288 // no need to redefine the user with srun, the job user is taken by default
1289 // (note: for srun, user id can be specified with " --uid=<user>")
1290 command << "srun -n 1 -N 1 --share --nodelist=" << hostname << " ";
1293 command << "pbsdsh -o -h " << hostname << " ";
1296 command << "blaunch " << hostname << " ";
1299 throw SALOME_Exception("Unknown protocol");
1302 return command.str();
1306 SALOME_ContainerManager::checkPaCOParameters(Engines::ContainerParameters & params, std::string resource_selected)
1310 // Step 1 : check ContainerParameters
1311 // Check container_name, has to be defined
1312 if (std::string(params.container_name.in()) == "")
1314 INFOS("[checkPaCOParameters] You must define a container_name to launch a PaCO++ container");
1317 // Check parallelLib
1318 std::string parallelLib = params.parallelLib.in();
1319 if (parallelLib != "Mpi" && parallelLib != "Dummy")
1321 INFOS("[checkPaCOParameters] parallelLib is not correctly defined");
1322 INFOS("[checkPaCOParameters] you can chosse between: Mpi and Dummy");
1323 INFOS("[checkPaCOParameters] you entered: " << parallelLib);
1327 if (params.nb_proc <= 0)
1329 INFOS("[checkPaCOParameters] You must define a nb_proc > 0");
1333 // Step 2 : check resource_selected
1334 Engines::ResourceDefinition_var resource_definition = _ResManager->GetResourceDefinition(resource_selected.c_str());
1335 std::string protocol = resource_definition->protocol.in();
1336 std::string username = resource_definition->username.in();
1337 std::string applipath = resource_definition->applipath.in();
1339 if (protocol == "" || username == "" || applipath == "")
1341 INFOS("[checkPaCOParameters] resource selected is not well defined");
1342 INFOS("[checkPaCOParameters] resource name: " << resource_definition->name.in());
1343 INFOS("[checkPaCOParameters] resource hostname: " << resource_definition->hostname.in());
1344 INFOS("[checkPaCOParameters] resource protocol: " << protocol);
1345 INFOS("[checkPaCOParameters] resource username: " << username);
1346 INFOS("[checkPaCOParameters] resource applipath: " << applipath);
1352 #ifdef WITH_PACO_PARALLEL
1354 //=============================================================================
1356 * Start a suitable PaCO++ Parallel Container in a list of machines.
1357 * \param params Container Parameters required for the container
1358 * \return CORBA container reference.
1360 //=============================================================================
1361 Engines::Container_ptr
1362 SALOME_ContainerManager::StartPaCOPPContainer(const Engines::ContainerParameters& params_const,
1363 std::string resource_selected)
1365 CORBA::Object_var obj;
1366 PaCO::InterfaceManager_var container_proxy;
1367 Engines::Container_ptr ret = Engines::Container::_nil();
1368 Engines::ContainerParameters params(params_const);
1369 params.resource_params.name = CORBA::string_dup(resource_selected.c_str());
1371 // Step 0 : Check parameters
1372 if (!checkPaCOParameters(params, resource_selected))
1374 INFOS("[StartPaCOPPContainer] check parameters failed ! see logs...");
1378 // Step 1 : Starting a new parallel container !
1379 INFOS("[StartPaCOPPContainer] Starting a PaCO++ parallel container");
1380 INFOS("[StartPaCOPPContainer] on resource : " << resource_selected);
1382 // Step 2 : Get a MachineFile for the parallel container
1383 std::string machine_file_name = _ResManager->getMachineFile(resource_selected,
1385 params.parallelLib.in());
1387 if (machine_file_name == "")
1389 INFOS("[StartPaCOPPContainer] Machine file generation failed");
1393 // Step 3 : starting parallel container proxy
1394 std::string command_proxy("");
1395 std::string proxy_machine;
1398 command_proxy = BuildCommandToLaunchPaCOProxyContainer(params, machine_file_name, proxy_machine);
1400 catch(const SALOME_Exception & ex)
1402 INFOS("[StartPaCOPPContainer] Exception in BuildCommandToLaunchPaCOContainer");
1406 obj = LaunchPaCOProxyContainer(command_proxy, params, proxy_machine);
1407 if (CORBA::is_nil(obj))
1409 INFOS("[StartPaCOPPContainer] LaunchPaCOContainer for proxy returns NIL !");
1412 container_proxy = PaCO::InterfaceManager::_narrow(obj);
1413 MESSAGE("[StartPaCOPPContainer] PaCO container proxy is launched");
1415 // Step 4 : starting parallel container nodes
1416 std::string command_nodes("");
1417 SALOME_ContainerManager::actual_launch_machine_t nodes_machines;
1420 command_nodes = BuildCommandToLaunchPaCONodeContainer(params, machine_file_name, nodes_machines, proxy_machine);
1422 catch(const SALOME_Exception & ex)
1424 INFOS("[StarPaCOPPContainer] Exception in BuildCommandToLaunchPaCONodeContainer");
1429 std::string container_generic_node_name = std::string(params.container_name.in()) + std::string("Node");
1430 bool result = LaunchPaCONodeContainer(command_nodes, params, container_generic_node_name, nodes_machines);
1433 INFOS("[StarPaCOPPContainer] LaunchPaCONodeContainer failed !");
1434 // Il faut tuer le proxy
1437 Engines::Container_var proxy = Engines::Container::_narrow(container_proxy);
1442 INFOS("[StarPaCOPPContainer] Exception catched from proxy Shutdown...");
1447 // Step 4 : connecting nodes and the proxy to actually create a parallel container
1448 for (int i = 0; i < params.nb_proc; i++)
1450 std::ostringstream tmp;
1452 std::string proc_number = tmp.str();
1453 std::string container_node_name = container_generic_node_name + proc_number;
1455 std::string theNodeMachine(nodes_machines[i]);
1456 std::string containerNameInNS = _NS->BuildContainerNameForNS(container_node_name.c_str(), theNodeMachine.c_str());
1457 obj = _NS->Resolve(containerNameInNS.c_str());
1458 if (CORBA::is_nil(obj))
1460 INFOS("[StarPaCOPPContainer] CONNECTION FAILED From Naming Service !");
1461 INFOS("[StarPaCOPPContainer] Container name is " << containerNameInNS);
1466 MESSAGE("[StarPaCOPPContainer] Deploying node : " << container_node_name);
1467 PaCO::InterfaceParallel_var node = PaCO::InterfaceParallel::_narrow(obj);
1469 MESSAGE("[StarPaCOPPContainer] node " << container_node_name << " is deployed");
1471 catch(CORBA::SystemException& e)
1473 INFOS("[StarPaCOPPContainer] Exception in deploying node : " << containerNameInNS);
1474 INFOS("CORBA::SystemException : " << e);
1477 catch(CORBA::Exception& e)
1479 INFOS("[StarPaCOPPContainer] Exception in deploying node : " << containerNameInNS);
1480 INFOS("CORBA::Exception" << e);
1485 INFOS("[StarPaCOPPContainer] Exception in deploying node : " << containerNameInNS);
1486 INFOS("Unknown exception !");
1491 // Step 5 : starting parallel container
1494 MESSAGE ("[StarPaCOPPContainer] Starting parallel object");
1495 container_proxy->start();
1496 MESSAGE ("[StarPaCOPPContainer] Parallel object is started");
1497 ret = Engines::Container::_narrow(container_proxy);
1499 catch(CORBA::SystemException& e)
1501 INFOS("Caught CORBA::SystemException. : " << e);
1503 catch(PortableServer::POA::ServantAlreadyActive&)
1505 INFOS("Caught CORBA::ServantAlreadyActiveException");
1507 catch(CORBA::Exception&)
1509 INFOS("Caught CORBA::Exception.");
1511 catch(std::exception& exc)
1513 INFOS("Caught std::exception - "<<exc.what());
1517 INFOS("Caught unknown exception.");
1523 SALOME_ContainerManager::BuildCommandToLaunchPaCOProxyContainer(const Engines::ContainerParameters& params,
1524 std::string machine_file_name,
1525 std::string & proxy_hostname)
1527 // In the proxy case, we always launch a Dummy Proxy
1528 std::string exe_name = "SALOME_ParallelContainerProxyDummy";
1529 std::string container_name = params.container_name.in();
1531 // Convert nb_proc in string
1532 std::ostringstream tmp_string;
1533 tmp_string << params.nb_proc;
1534 std::string nb_proc_str = tmp_string.str();
1536 // Get resource definition
1537 Engines::ResourceDefinition_var resource_definition =
1538 _ResManager->GetResourceDefinition(params.resource_params.name);
1541 std::string hostname;
1542 std::ifstream machine_file(machine_file_name.c_str());
1543 std::getline(machine_file, hostname, ' ');
1544 size_t found = hostname.find('\n');
1545 if (found!=std::string::npos)
1546 hostname.erase(found, 1); // Remove \n
1547 proxy_hostname = hostname;
1548 MESSAGE("[BuildCommandToLaunchPaCOProxyContainer] machine file name extracted is " << hostname);
1551 bool remote_execution = false;
1552 if (hostname != std::string(Kernel_Utils::GetHostname()))
1554 MESSAGE("[BuildCommandToLaunchPaCOProxyContainer] remote machine case detected !");
1555 remote_execution = true;
1558 // Log environnement
1559 std::string log_type("");
1560 char * get_val = getenv("PARALLEL_LOG");
1564 // Generating the command
1565 std::string command_begin("");
1566 std::string command_end("");
1567 std::ostringstream command;
1569 LogConfiguration(log_type, "proxy", container_name, hostname, command_begin, command_end);
1570 command << command_begin;
1572 // Adding connection command
1573 // We can only have a remote execution with
1574 // a SALOME application
1575 if (remote_execution)
1577 ASSERT(getenv("NSHOST"));
1578 ASSERT(getenv("NSPORT"));
1580 command << resource_definition->protocol.in();
1582 command << resource_definition->username.in();
1583 command << " " << hostname;
1584 command << " " << resource_definition->applipath.in();
1585 command << "/runRemote.sh ";
1586 command << getenv("NSHOST") << " "; // hostname of CORBA name server
1587 command << getenv("NSPORT") << " "; // port of CORBA name server
1590 command << exe_name;
1591 command << " " << container_name;
1592 command << " Dummy";
1593 command << " " << hostname;
1594 command << " " << nb_proc_str;
1596 AddOmninamesParams(command);
1599 command << command_end;
1600 MESSAGE("[BuildCommandToLaunchPaCOProxyContainer] Command is: " << command.str());
1602 return command.str();
1606 SALOME_ContainerManager::BuildCommandToLaunchPaCONodeContainer(const Engines::ContainerParameters& params,
1607 const std::string & machine_file_name,
1608 SALOME_ContainerManager::actual_launch_machine_t & vect_machine,
1609 const std::string & proxy_hostname)
1612 std::string exe_name = "SALOME_ParallelContainerNode";
1613 exe_name += params.parallelLib.in();
1614 std::string container_name = params.container_name.in();
1616 // Convert nb_proc in string
1617 std::ostringstream nb_proc_stream;
1618 nb_proc_stream << params.nb_proc;
1620 // Get resource definition
1621 Engines::ResourceDefinition_var resource_definition =
1622 _ResManager->GetResourceDefinition(params.resource_params.name);
1624 // Log environnement
1625 std::string log_type("");
1626 char * get_val = getenv("PARALLEL_LOG");
1630 // Now the command is different according to paralleLib
1631 std::ostringstream command_nodes;
1632 std::ifstream machine_file(machine_file_name.c_str());
1633 if (std::string(params.parallelLib.in()) == "Dummy")
1635 for (int i= 0; i < params.nb_proc; i++)
1638 std::string hostname;
1639 std::getline(machine_file, hostname);
1640 MESSAGE("[BuildCommandToLaunchPaCONodeContainer] machine file name extracted is " << hostname);
1643 bool remote_execution = false;
1644 if (hostname != std::string(Kernel_Utils::GetHostname()))
1646 MESSAGE("[BuildCommandToLaunchPaCONodeContainer] remote machine case detected !");
1647 remote_execution = true;
1650 // For each node we have a new command
1651 // Generating the command
1652 std::ostringstream command_node_stream;
1653 std::string command_node_begin("");
1654 std::string command_node_end("");
1655 std::ostringstream node_number;
1657 std::string container_node_name = container_name + node_number.str();
1658 LogConfiguration(log_type, "node", container_node_name, hostname, command_node_begin, command_node_end);
1660 // Adding connection command
1661 // We can only have a remote execution with
1662 // a SALOME application
1663 if (remote_execution)
1665 ASSERT(getenv("NSHOST"));
1666 ASSERT(getenv("NSPORT"));
1668 command_node_stream << resource_definition->protocol.in();
1669 command_node_stream << " -l ";
1670 command_node_stream << resource_definition->username.in();
1671 command_node_stream << " " << hostname;
1672 command_node_stream << " " << resource_definition->applipath.in();
1673 command_node_stream << "/runRemote.sh ";
1674 command_node_stream << getenv("NSHOST") << " "; // hostname of CORBA name server
1675 command_node_stream << getenv("NSPORT") << " "; // port of CORBA name server
1678 command_node_stream << exe_name;
1679 command_node_stream << " " << container_name;
1680 command_node_stream << " " << params.parallelLib.in();
1681 command_node_stream << " " << proxy_hostname;
1682 command_node_stream << " " << node_number.str();
1683 command_node_stream << " -";
1684 AddOmninamesParams(command_node_stream);
1686 command_nodes << command_node_begin << command_node_stream.str() << command_node_end;
1687 vect_machine.push_back(hostname);
1691 else if (std::string(params.parallelLib.in()) == "Mpi")
1694 std::string hostname;
1695 std::getline(machine_file, hostname, ' ');
1696 MESSAGE("[BuildCommandToLaunchPaCONodeContainer] machine file name extracted is " << hostname);
1699 bool remote_execution = false;
1700 if (hostname != std::string(Kernel_Utils::GetHostname()))
1702 MESSAGE("[BuildCommandToLaunchPaCONodeContainer] remote machine case detected !");
1703 remote_execution = true;
1706 // In case of Mpi and Remote, we copy machine_file in the applipath
1707 // scp mpi_machine_file user@machine:Path
1708 std::ostringstream command_remote_stream;
1709 std::string::size_type last = machine_file_name.find_last_of("/");
1710 if (last == std::string::npos)
1713 std::string protocol = resource_definition->protocol.in();
1714 if (protocol == "rsh")
1715 command_remote_stream << "rcp ";
1717 command_remote_stream << "scp ";
1718 command_remote_stream << machine_file_name << " ";
1719 command_remote_stream << resource_definition->username.in() << "@";
1720 command_remote_stream << hostname << ":" << resource_definition->applipath.in();
1721 command_remote_stream << "/" << machine_file_name.substr(last+1);
1723 int status = system(command_remote_stream.str().c_str());
1726 INFOS("copy of the MPI machine file failed ! - sorry !");
1730 // Generating the command
1731 std::string command_begin("");
1732 std::string command_end("");
1734 LogConfiguration(log_type, "nodes", container_name, hostname, command_begin, command_end);
1735 command_nodes << command_begin;
1737 // Adding connection command
1738 // We can only have a remote execution with
1739 // a SALOME application
1740 if (remote_execution)
1742 ASSERT(getenv("NSHOST"));
1743 ASSERT(getenv("NSPORT"));
1745 command_nodes << resource_definition->protocol.in();
1746 command_nodes << " -l ";
1747 command_nodes << resource_definition->username.in();
1748 command_nodes << " " << hostname;
1749 command_nodes << " " << resource_definition->applipath.in();
1750 command_nodes << "/runRemote.sh ";
1751 command_nodes << getenv("NSHOST") << " "; // hostname of CORBA name server
1752 command_nodes << getenv("NSPORT") << " "; // port of CORBA name server
1755 if (std::string(resource_definition->mpiImpl.in()) == "lam")
1757 command_nodes << "mpiexec -ssi boot ";
1758 command_nodes << "-machinefile " << machine_file_name << " ";
1759 command_nodes << "-n " << params.nb_proc;
1763 command_nodes << "mpirun -np " << params.nb_proc;
1765 command_nodes << " " << exe_name;
1766 command_nodes << " " << container_name;
1767 command_nodes << " " << params.parallelLib.in();
1768 command_nodes << " " << proxy_hostname;
1769 command_nodes << " -";
1770 AddOmninamesParams(command_nodes);
1772 // We don't put hostname, because nodes are registered in the resource of the proxy
1773 for (int i= 0; i < params.nb_proc; i++)
1774 vect_machine.push_back(proxy_hostname);
1776 command_nodes << command_end;
1778 return command_nodes.str();
1782 SALOME_ContainerManager::LogConfiguration(const std::string & log_type,
1783 const std::string & exe_type,
1784 const std::string & container_name,
1785 const std::string & hostname,
1786 std::string & begin,
1789 if(log_type == "xterm")
1791 begin = "xterm -e \"export LD_LIBRARY_PATH=$LD_LIBRARY_PATH; export PATH=$PATH;";
1794 else if(log_type == "xterm_debug")
1796 begin = "xterm -e \"export LD_LIBRARY_PATH=$LD_LIBRARY_PATH; export PATH=$PATH;";
1801 // default into a file...
1802 std::string logFilename = "/tmp/" + container_name + "_" + hostname + "_" + exe_type + "_";
1803 logFilename += std::string(getenv("USER")) + ".log";
1804 end = " > " + logFilename + " 2>&1 & ";
1809 SALOME_ContainerManager::LaunchPaCOProxyContainer(const std::string& command,
1810 const Engines::ContainerParameters& params,
1811 const std::string & hostname)
1813 PaCO::InterfaceManager_ptr container_proxy = PaCO::InterfaceManager::_nil();
1815 MESSAGE("[LaunchPaCOProxyContainer] Launch command");
1816 int status = system(command.c_str());
1818 INFOS("[LaunchPaCOProxyContainer] failed : system command status -1");
1819 return container_proxy;
1821 else if (status == 217) {
1822 INFOS("[LaunchPaCOProxyContainer] failed : system command status 217");
1823 return container_proxy;
1826 int count = TIME_OUT_TO_LAUNCH_CONT;
1827 CORBA::Object_var obj = CORBA::Object::_nil();
1828 std::string containerNameInNS = _NS->BuildContainerNameForNS(params.container_name.in(),
1830 MESSAGE("[LaunchParallelContainer] Waiting for Parallel Container proxy : " << containerNameInNS);
1832 while (CORBA::is_nil(obj) && count)
1836 obj = _NS->Resolve(containerNameInNS.c_str());
1841 container_proxy = PaCO::InterfaceManager::_narrow(obj);
1843 catch(CORBA::SystemException& e)
1845 INFOS("[StarPaCOPPContainer] Exception in _narrow after LaunchParallelContainer for proxy !");
1846 INFOS("CORBA::SystemException : " << e);
1847 return container_proxy;
1849 catch(CORBA::Exception& e)
1851 INFOS("[StarPaCOPPContainer] Exception in _narrow after LaunchParallelContainer for proxy !");
1852 INFOS("CORBA::Exception" << e);
1853 return container_proxy;
1857 INFOS("[StarPaCOPPContainer] Exception in _narrow after LaunchParallelContainer for proxy !");
1858 INFOS("Unknown exception !");
1859 return container_proxy;
1861 if (CORBA::is_nil(container_proxy))
1863 INFOS("[StarPaCOPPContainer] PaCO::InterfaceManager::_narrow returns NIL !");
1864 return container_proxy;
1869 //=============================================================================
1870 /*! This method launches the parallel container.
1871 * It will may be placed on the ressources manager.
1873 * \param command to launch
1874 * \param container's parameters
1875 * \param name of the container
1877 * \return CORBA container reference
1879 //=============================================================================
1881 SALOME_ContainerManager::LaunchPaCONodeContainer(const std::string& command,
1882 const Engines::ContainerParameters& params,
1883 const std::string& name,
1884 SALOME_ContainerManager::actual_launch_machine_t & vect_machine)
1886 INFOS("[LaunchPaCONodeContainer] Launch command");
1887 int status = system(command.c_str());
1889 INFOS("[LaunchPaCONodeContainer] failed : system command status -1");
1892 else if (status == 217) {
1893 INFOS("[LaunchPaCONodeContainer] failed : system command status 217");
1897 INFOS("[LaunchPaCONodeContainer] Waiting for the nodes of the parallel container");
1898 // We are waiting all the nodes
1899 for (int i = 0; i < params.nb_proc; i++)
1901 CORBA::Object_var obj = CORBA::Object::_nil();
1902 std::string theMachine(vect_machine[i]);
1904 std::ostringstream tmp;
1906 std::string proc_number = tmp.str();
1907 std::string container_node_name = name + proc_number;
1908 std::string containerNameInNS = _NS->BuildContainerNameForNS((char*) container_node_name.c_str(), theMachine.c_str());
1909 INFOS("[LaunchPaCONodeContainer] Waiting for Parallel Container node " << containerNameInNS << " on " << theMachine);
1910 int count = TIME_OUT_TO_LAUNCH_CONT;
1911 while (CORBA::is_nil(obj) && count) {
1914 obj = _NS->Resolve(containerNameInNS.c_str());
1916 if (CORBA::is_nil(obj))
1918 INFOS("[LaunchPaCONodeContainer] Launch of node failed (or not found) !");
1927 Engines::Container_ptr
1928 SALOME_ContainerManager::StartPaCOPPContainer(const Engines::ContainerParameters& params,
1929 std::string resource_selected)
1931 Engines::Container_ptr ret = Engines::Container::_nil();
1932 INFOS("[StarPaCOPPContainer] is disabled !");
1933 INFOS("[StarPaCOPPContainer] recompile SALOME Kernel to enable PaCO++ parallel extension");
1938 SALOME_ContainerManager::BuildCommandToLaunchPaCOProxyContainer(const Engines::ContainerParameters& params,
1939 std::string machine_file_name,
1940 std::string & proxy_hostname)
1946 SALOME_ContainerManager::BuildCommandToLaunchPaCONodeContainer(const Engines::ContainerParameters& params,
1947 const std::string & machine_file_name,
1948 SALOME_ContainerManager::actual_launch_machine_t & vect_machine,
1949 const std::string & proxy_hostname)
1954 SALOME_ContainerManager::LogConfiguration(const std::string & log_type,
1955 const std::string & exe_type,
1956 const std::string & container_name,
1957 const std::string & hostname,
1958 std::string & begin,
1964 SALOME_ContainerManager::LaunchPaCOProxyContainer(const std::string& command,
1965 const Engines::ContainerParameters& params,
1966 const std::string& hostname)
1968 CORBA::Object_ptr ret = CORBA::Object::_nil();
1973 SALOME_ContainerManager::LaunchPaCONodeContainer(const std::string& command,
1974 const Engines::ContainerParameters& params,
1975 const std::string& name,
1976 SALOME_ContainerManager::actual_launch_machine_t & vect_machine)