1 // Copyright (C) 2007-2013 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"
39 #include <SALOMEconfig.h>
40 #include CORBA_CLIENT_HEADER(SALOME_Session)
44 #define getpid _getpid
47 #ifdef WITH_PACO_PARALLEL
51 #define TIME_OUT_TO_LAUNCH_CONT 60
53 const char *SALOME_ContainerManager::_ContainerManagerNameInNS =
56 omni_mutex SALOME_ContainerManager::_numInstanceMutex;
59 //=============================================================================
63 * Define a CORBA single thread policy for the server, which avoid to deal
64 * with non thread-safe usage like Change_Directory in SALOME naming service
66 //=============================================================================
68 SALOME_ContainerManager::SALOME_ContainerManager(CORBA::ORB_ptr orb, PortableServer::POA_var poa, SALOME_ResourcesManager *rm, SALOME_NamingService *ns):_nbprocUsed(1)
70 MESSAGE("constructor");
74 PortableServer::POAManager_var pman = poa->the_POAManager();
75 _orb = CORBA::ORB::_duplicate(orb) ;
76 CORBA::PolicyList policies;
78 PortableServer::ThreadPolicy_var threadPol =
79 poa->create_thread_policy(PortableServer::SINGLE_THREAD_MODEL);
80 policies[0] = PortableServer::ThreadPolicy::_duplicate(threadPol);
82 _poa = poa->create_POA("SThreadPOA",pman,policies);
84 PortableServer::ObjectId_var id = _poa->activate_object(this);
85 CORBA::Object_var obj = _poa->id_to_reference(id);
86 Engines::ContainerManager_var refContMan =
87 Engines::ContainerManager::_narrow(obj);
89 _NS->Register(refContMan,_ContainerManagerNameInNS);
90 _isAppliSalomeDefined = (getenv("APPLI") != 0);
95 // the urifile name depends on pid of the process
96 std::stringstream urifile;
97 urifile << getenv("HOME") << "/.urifile_" << getpid();
98 setenv("OMPI_URI_FILE",urifile.str().c_str(),1);
99 if( getenv("OMPI_URI_FILE") != NULL ){
100 // get the pid of all ompi-server
101 std::set<pid_t> thepids1 = getpidofprogram("ompi-server");
102 // launch a new ompi-server
104 command = "ompi-server -r ";
105 command += getenv("OMPI_URI_FILE");
106 int status=system(command.c_str());
108 throw SALOME_Exception("Error when launching ompi-server");
109 // get the pid of all ompi-server
110 std::set<pid_t> thepids2 = getpidofprogram("ompi-server");
111 // my ompi-server is the new one
112 std::set<pid_t>::const_iterator it;
113 for(it=thepids2.begin();it!=thepids2.end();it++)
114 if(thepids1.find(*it) == thepids1.end())
115 _pid_mpiServer = *it;
116 if(_pid_mpiServer < 0)
117 throw SALOME_Exception("Error when getting ompi-server id");
119 #elif defined(WITHMPICH)
121 // get the pid of all hydra_nameserver
122 std::set<pid_t> thepids1 = getpidofprogram("hydra_nameserver");
123 // launch a new hydra_nameserver
125 command = "hydra_nameserver &";
126 system(command.c_str());
127 // get the pid of all hydra_nameserver
128 std::set<pid_t> thepids2 = getpidofprogram("hydra_nameserver");
129 // my hydra_nameserver is the new one
130 std::set<pid_t>::const_iterator it;
131 for(it=thepids2.begin();it!=thepids2.end();it++)
132 if(thepids1.find(*it) == thepids1.end())
133 _pid_mpiServer = *it;
137 MESSAGE("constructor end");
140 //=============================================================================
144 //=============================================================================
146 SALOME_ContainerManager::~SALOME_ContainerManager()
148 MESSAGE("destructor");
151 if( getenv("OMPI_URI_FILE") != NULL ){
152 // kill my ompi-server
153 if( kill(_pid_mpiServer,SIGTERM) != 0 )
154 throw SALOME_Exception("Error when killing ompi-server");
156 int status=system("rm -f ${OMPI_URI_FILE}");
158 throw SALOME_Exception("Error when removing urifile");
160 #elif defined(WITHMPICH)
161 // kill my hydra_nameserver
162 if(_pid_mpiServer > -1)
163 if( kill(_pid_mpiServer,SIGTERM) != 0 )
164 throw SALOME_Exception("Error when killing hydra_nameserver");
169 //=============================================================================
170 //! shutdown all the containers, then the ContainerManager servant
173 //=============================================================================
175 void SALOME_ContainerManager::Shutdown()
178 ShutdownContainers();
179 _NS->Destroy_Name(_ContainerManagerNameInNS);
180 PortableServer::ObjectId_var oid = _poa->servant_to_id(this);
181 _poa->deactivate_object(oid);
184 //=============================================================================
185 //! Loop on all the containers listed in naming service, ask shutdown on each
188 //=============================================================================
190 void SALOME_ContainerManager::ShutdownContainers()
192 MESSAGE("ShutdownContainers");
194 SALOME::Session_var session = SALOME::Session::_nil();
196 CORBA::Object_var objS = _NS->Resolve("/Kernel/Session");
197 if (!CORBA::is_nil(objS))
199 session = SALOME::Session::_narrow(objS);
200 if (!CORBA::is_nil(session))
201 pid = session->getPID();
205 isOK = _NS->Change_Directory("/Containers");
207 std::vector<std::string> vec = _NS->list_directory_recurs();
208 std::list<std::string> lstCont;
209 for(std::vector<std::string>::iterator iter = vec.begin();iter!=vec.end();iter++)
212 CORBA::Object_var obj=_NS->Resolve((*iter).c_str());
215 Engines::Container_var cont=Engines::Container::_narrow(obj);
216 if(!CORBA::is_nil(cont) && pid != cont->getPID())
217 lstCont.push_back((*iter));
219 catch(const CORBA::Exception& e)
221 // ignore this entry and continue
224 MESSAGE("Container list: ");
225 for(std::list<std::string>::iterator iter=lstCont.begin();iter!=lstCont.end();iter++){
228 for(std::list<std::string>::iterator iter=lstCont.begin();iter!=lstCont.end();iter++)
233 CORBA::Object_var obj=_NS->Resolve((*iter).c_str());
234 Engines::Container_var cont=Engines::Container::_narrow(obj);
235 if(!CORBA::is_nil(cont))
237 MESSAGE("ShutdownContainers: " << (*iter));
241 MESSAGE("ShutdownContainers: no container ref for " << (*iter));
243 catch(CORBA::SystemException& e)
245 INFOS("CORBA::SystemException ignored : " << e);
247 catch(CORBA::Exception&)
249 INFOS("CORBA::Exception ignored.");
253 INFOS("Unknown exception ignored.");
259 //=============================================================================
260 //! Give a suitable Container given constraints
262 * \param params Container Parameters required for the container
263 * \return the container or nil
265 //=============================================================================
266 Engines::Container_ptr
267 SALOME_ContainerManager::GiveContainer(const Engines::ContainerParameters& params)
269 std::string machFile;
270 Engines::Container_ptr ret = Engines::Container::_nil();
272 // Step 0: Default mode is start
273 Engines::ContainerParameters local_params(params);
274 if (std::string(local_params.mode.in()) == "")
275 local_params.mode = CORBA::string_dup("start");
276 std::string mode = local_params.mode.in();
277 MESSAGE("[GiveContainer] starting with mode: " << mode);
279 // Step 1: Find Container for find and findorstart mode
280 if (mode == "find" || mode == "findorstart")
282 ret = FindContainer(params, params.resource_params.resList);
283 if(!CORBA::is_nil(ret))
289 MESSAGE("[GiveContainer] no container found");
299 // Step 2: Get all possibleResources from the parameters
300 // Consider only resources that can run containers
301 local_params.resource_params.can_run_containers = true;
302 Engines::ResourceList_var possibleResources = _ResManager->GetFittingResources(local_params.resource_params);
303 MESSAGE("[GiveContainer] - length of possible resources " << possibleResources->length());
304 std::vector<std::string> local_resources;
306 // Step 3: if mode is "get" keep only machines with existing containers
309 for(unsigned int i=0; i < possibleResources->length(); i++)
311 Engines::Container_ptr cont = FindContainer(params, possibleResources[i].in());
314 if(!cont->_non_existent())
315 local_resources.push_back(std::string(possibleResources[i]));
317 catch(CORBA::Exception&) {}
320 // if local_resources is empty, we cannot give a container
321 if (local_resources.size() == 0)
323 MESSAGE("[GiveContainer] cannot find a container for mode get");
328 for(unsigned int i=0; i < possibleResources->length(); i++)
329 local_resources.push_back(std::string(possibleResources[i]));
331 // Step 4: select the resource where to get/start the container
332 bool resource_available = true;
333 std::string resource_selected;
334 std::vector<std::string> resources = local_resources;
335 while (resource_available)
337 if (resources.size() == 0)
338 resource_available = false;
343 resource_selected = _ResManager->GetImpl()->Find(params.resource_params.policy.in(), resources);
344 // Remove resource_selected from vector
345 std::vector<std::string>::iterator it;
346 for (it=resources.begin() ; it < resources.end(); it++ )
347 if (*it == resource_selected)
353 catch(const SALOME_Exception &ex)
355 MESSAGE("[GiveContainer] Exception in ResourceManager find !: " << ex.what());
358 MESSAGE("[GiveContainer] Resource selected is: " << resource_selected);
360 // Step 5: Create container name
361 Engines::ResourceDefinition_var resource_definition = _ResManager->GetResourceDefinition(resource_selected.c_str());
362 std::string hostname(resource_definition->hostname.in());
363 std::string containerNameInNS;
366 if ( params.nb_proc <= 0 )
369 nbproc = params.nb_proc;
372 if( getenv("LIBBATCH_NODEFILE") != NULL )
373 machFile = machinesFile(nbproc);
375 catch(const SALOME_Exception & ex)
377 std::string err_msg = ex.what();
378 err_msg += params.container_name;
379 INFOS(err_msg.c_str());
382 // A mpi parallel container register on zero node in NS
383 containerNameInNS = _NS->BuildContainerNameForNS(params, GetMPIZeroNode(hostname,machFile).c_str());
386 containerNameInNS = _NS->BuildContainerNameForNS(params, hostname.c_str());
387 MESSAGE("[GiveContainer] Container name in the naming service: " << containerNameInNS);
389 // Step 6: check if the name exists in naming service
390 //if params.mode == "getorstart" or "get" use the existing container
391 //if params.mode == "start" shutdown the existing container before launching a new one with that name
392 CORBA::Object_var obj = _NS->Resolve(containerNameInNS.c_str());
393 if (!CORBA::is_nil(obj))
397 Engines::Container_var cont=Engines::Container::_narrow(obj);
398 if(!cont->_non_existent())
400 if(std::string(params.mode.in())=="getorstart" || std::string(params.mode.in())=="get"){
401 return cont._retn(); /* the container exists and params.mode is getorstart or get use it*/
405 INFOS("[GiveContainer] A container is already registered with the name: " << containerNameInNS << ", shutdown the existing container");
406 cont->Shutdown(); // shutdown the registered container if it exists
410 catch(CORBA::Exception&)
412 INFOS("[GiveContainer] CORBA::Exception ignored when trying to get the container - we start a new one");
415 Engines::Container_var cont = LaunchContainer(params, resource_selected, hostname, machFile, containerNameInNS);
416 if (!CORBA::is_nil(cont))
418 INFOS("[GiveContainer] container " << containerNameInNS << " launched");
423 INFOS("[GiveContainer] Failed to launch container on resource " << resource_selected);
428 // We were not able to launch the container
429 INFOS("[GiveContainer] Cannot launch the container on the following selected resources:")
430 std::vector<std::string>::iterator it;
431 for (it=local_resources.begin() ; it < local_resources.end(); it++ )
432 INFOS("[GiveContainer] " << *it)
436 Engines::Container_ptr
437 SALOME_ContainerManager::LaunchContainer(const Engines::ContainerParameters& params,
438 const std::string & resource_selected,
439 const std::string & hostname,
440 const std::string & machFile,
441 const std::string & containerNameInNS)
444 // Step 1: type of container: PaCO, Exe, Mpi or Classic
445 // Mpi already tested in step 5, specific code on BuildCommandToLaunch Local/Remote Container methods
446 // TODO -> separates Mpi from Classic/Exe
448 std::string container_exe = "SALOME_Container"; // Classic container
449 Engines::ContainerParameters local_params(params);
450 Engines::Container_ptr ret = Engines::Container::_nil();
454 CORBA::String_var container_exe_tmp;
455 CORBA::Object_var obj = _NS->Resolve("/Kernel/ModulCatalog");
456 SALOME_ModuleCatalog::ModuleCatalog_var Catalog = SALOME_ModuleCatalog::ModuleCatalog::_narrow(obj) ;
457 if (CORBA::is_nil (Catalog))
459 INFOS("[GiveContainer] Module Catalog is not found -> cannot launch a container");
462 // Loop through component list
463 for(unsigned int i=0; i < local_params.resource_params.componentList.length(); i++)
465 const char* compoi = local_params.resource_params.componentList[i];
466 SALOME_ModuleCatalog::Acomponent_var compoInfo = Catalog->GetComponent(compoi);
467 if (CORBA::is_nil (compoInfo))
471 SALOME_ModuleCatalog::ImplType impl=compoInfo->implementation_type();
472 container_exe_tmp=compoInfo->implementation_name();
473 if(impl==SALOME_ModuleCatalog::CEXE)
477 INFOS("ContainerManager Error: you can't have 2 CEXE component in the same container" );
478 return Engines::Container::_nil();
480 MESSAGE("[GiveContainer] Exe container found !: " << container_exe_tmp);
481 container_exe = container_exe_tmp.in();
486 catch (ServiceUnreachable&)
488 INFOS("Caught exception: Naming Service Unreachable");
493 INFOS("Caught unknown exception.");
497 // Step 2: test resource
498 // Only if an application directory is set
499 if(hostname != Kernel_Utils::GetHostname() && _isAppliSalomeDefined)
501 // Preparing remote command
502 std::string command = "";
503 const ParserResourcesType& resInfo = _ResManager->GetImpl()->GetResourcesDescr(resource_selected);
504 command = getCommandToRunRemoteProcess(resInfo.Protocol, resInfo.HostName, resInfo.UserName);
505 if (resInfo.AppliPath != "")
506 command += resInfo.AppliPath;
509 ASSERT(getenv("APPLI"));
510 command += getenv("APPLI");
512 command += "/runRemote.sh ";
513 ASSERT(getenv("NSHOST"));
514 command += getenv("NSHOST"); // hostname of CORBA name server
516 ASSERT(getenv("NSPORT"));
517 command += getenv("NSPORT"); // port of CORBA name server
518 command += " \"ls /tmp >/dev/null 2>&1\"";
520 // Launch remote command
521 int status = system(command.c_str());
524 // Error on resource - cannot launch commands
525 INFOS("[LaunchContainer] Cannot launch commands on machine " << hostname);
526 INFOS("[LaunchContainer] Command was " << command);
528 INFOS("[LaunchContainer] Command status is " << WEXITSTATUS(status));
530 return Engines::Container::_nil();
534 // Step 3: start a new container
535 // Check if a PaCO container
537 if (std::string(local_params.parallelLib.in()) != "")
539 ret = StartPaCOPPContainer(params, resource_selected);
542 // Other type of containers...
543 MESSAGE("[GiveContainer] Try to launch a new container on " << resource_selected);
545 // if a parallel container is launched in batch job, command is: "mpirun -np nbproc -machinefile nodesfile SALOME_MPIContainer"
546 if( getenv("LIBBATCH_NODEFILE") != NULL && params.isMPI )
547 command = BuildCommandToLaunchLocalContainer(params, machFile, container_exe);
548 // if a container is launched on localhost, command is "SALOME_Container" or "mpirun -np nbproc SALOME_MPIContainer"
549 else if(hostname == Kernel_Utils::GetHostname())
550 command = BuildCommandToLaunchLocalContainer(params, machFile, container_exe);
551 // if a container is launched in remote mode, command is "ssh resource_selected SALOME_Container" or "ssh resource_selected mpirun -np nbproc SALOME_MPIContainer"
553 command = BuildCommandToLaunchRemoteContainer(resource_selected, params, container_exe);
555 //redirect stdout and stderr in a file
557 std::string logFilename=getenv("TEMP");
559 std::string user = getenv( "USERNAME" );
561 std::string user = getenv( "USER" );
562 std::string logFilename="/tmp";
563 char* val = getenv("SALOME_TMP_DIR");
566 struct stat file_info;
567 stat(val, &file_info);
568 bool is_dir = S_ISDIR(file_info.st_mode);
569 if (is_dir)logFilename=val;
570 else std::cerr << "SALOME_TMP_DIR environment variable is not a directory use /tmp instead" << std::endl;
574 logFilename += _NS->ContainerName(params)+"_"+ resource_selected +"_"+user;
575 std::ostringstream tmp;
576 tmp << "_" << getpid();
577 logFilename += tmp.str();
578 logFilename += ".log" ;
579 command += " > " + logFilename + " 2>&1";
581 command = "%PYTHONBIN% -c \"import win32pm ; win32pm.spawnpid(r'" + command + "', '')\"";
586 // launch container with a system call
587 int status=system(command.c_str());
590 INFOS("[LaunchContainer] command failed (system command status -1): " << command);
591 RmTmpFile(_TmpFileName); // command file can be removed here
593 return Engines::Container::_nil();
595 else if (status == 217){
596 INFOS("[LaunchContainer] command failed (system command status 217): " << command);
597 RmTmpFile(_TmpFileName); // command file can be removed here
599 return Engines::Container::_nil();
603 // Step 4: Wait for the container
604 int count = TIME_OUT_TO_LAUNCH_CONT;
605 if (getenv("TIMEOUT_TO_LAUNCH_CONTAINER") != 0)
607 std::string new_count_str = getenv("TIMEOUT_TO_LAUNCH_CONTAINER");
609 std::istringstream ss(new_count_str);
610 if (!(ss >> new_count))
612 INFOS("[LaunchContainer] TIMEOUT_TO_LAUNCH_CONTAINER should be an int");
617 INFOS("[GiveContainer] waiting " << count << " second steps container " << containerNameInNS);
618 while (CORBA::is_nil(ret) && count)
626 MESSAGE("[GiveContainer] step " << count << " Waiting for container on " << resource_selected);
627 CORBA::Object_var obj = _NS->Resolve(containerNameInNS.c_str());
628 ret=Engines::Container::_narrow(obj);
630 if (CORBA::is_nil(ret))
632 INFOS("[GiveContainer] was not able to launch container " << containerNameInNS);
636 // Setting log file name
637 logFilename=":"+logFilename;
638 logFilename="@"+Kernel_Utils::GetHostname()+logFilename;
639 logFilename=user+logFilename;
640 ret->logfilename(logFilename.c_str());
641 RmTmpFile(_TmpFileName); // command file can be removed here
648 //=============================================================================
649 //! Find a container given constraints (params) on a list of machines (possibleComputers)
653 //=============================================================================
655 Engines::Container_ptr
656 SALOME_ContainerManager::FindContainer(const Engines::ContainerParameters& params,
657 const Engines::ResourceList& possibleResources)
659 MESSAGE("[FindContainer] FindContainer on " << possibleResources.length() << " resources");
660 for(unsigned int i=0; i < possibleResources.length();i++)
662 Engines::Container_ptr cont = FindContainer(params, possibleResources[i].in());
663 if(!CORBA::is_nil(cont))
666 MESSAGE("[FindContainer] no container found");
667 return Engines::Container::_nil();
670 //=============================================================================
671 //! Find a container given constraints (params) on a machine (theMachine)
675 //=============================================================================
677 Engines::Container_ptr
678 SALOME_ContainerManager::FindContainer(const Engines::ContainerParameters& params,
679 const std::string& resource)
681 Engines::ResourceDefinition_var resource_definition = _ResManager->GetResourceDefinition(resource.c_str());
682 std::string hostname(resource_definition->hostname.in());
683 std::string containerNameInNS(_NS->BuildContainerNameForNS(params, hostname.c_str()));
684 MESSAGE("[FindContainer] Try to find a container " << containerNameInNS << " on resource " << resource);
685 CORBA::Object_var obj = _NS->Resolve(containerNameInNS.c_str());
688 if(obj->_non_existent())
689 return Engines::Container::_nil();
691 return Engines::Container::_narrow(obj);
693 catch(const CORBA::Exception& e)
695 return Engines::Container::_nil();
700 bool isPythonContainer(const char* ContainerName);
702 //=============================================================================
704 * This is no longer valid (C++ container are also python containers)
706 //=============================================================================
707 bool isPythonContainer(const char* ContainerName)
709 return false; // VSR 02/08/2013: Python containers are no more supported
711 int len = strlen(ContainerName);
714 if (strcmp(ContainerName + len - 2, "Py") == 0)
720 //=============================================================================
722 * Builds the script to be launched
724 * If SALOME Application not defined ($APPLI),
725 * see BuildTempFileToLaunchRemoteContainer()
727 * Else rely on distant configuration. Command is under the form (example):
728 * ssh user@machine distantPath/runRemote.sh hostNS portNS WORKINGDIR workingdir \
729 * SALOME_Container containerName &"
731 * - where user is ommited if not specified in CatalogResources,
732 * - where distant path is always relative to user@machine $HOME, and
733 * equal to $APPLI if not specified in CatalogResources,
734 * - where hostNS is the hostname of CORBA naming server (set by scripts to
735 * use to launch SALOME and servers in $APPLI: runAppli.sh, runRemote.sh)
736 * - where portNS is the port used by CORBA naming server (set by scripts to
737 * use to launch SALOME and servers in $APPLI: runAppli.sh, runRemote.sh)
738 * - where workingdir is the requested working directory for the container.
739 * If WORKINGDIR (and workingdir) is not present the working dir will be $HOME
741 //=============================================================================
744 SALOME_ContainerManager::BuildCommandToLaunchRemoteContainer
745 (const std::string& resource_name,
746 const Engines::ContainerParameters& params, const std::string& container_exe)
750 if (!_isAppliSalomeDefined)
751 command = BuildTempFileToLaunchRemoteContainer(resource_name, params);
755 Engines::ResourceDefinition_var resource_definition = _ResManager->GetResourceDefinition(resource_name.c_str());
756 std::string hostname(resource_definition->hostname.in());
757 const ParserResourcesType& resInfo = _ResManager->GetImpl()->GetResourcesDescr(resource_name);
761 if ( params.nb_proc <= 0 )
764 nbproc = params.nb_proc;
767 // "ssh -l user machine distantPath/runRemote.sh hostNS portNS WORKINGDIR workingdir \
768 // SALOME_Container containerName &"
769 command = getCommandToRunRemoteProcess(resInfo.Protocol, resInfo.HostName, resInfo.UserName);
771 if (resInfo.AppliPath != "")
772 command += resInfo.AppliPath; // path relative to user@machine $HOME
775 ASSERT(getenv("APPLI"));
776 command += getenv("APPLI"); // path relative to user@machine $HOME
779 command += "/runRemote.sh ";
781 ASSERT(getenv("NSHOST"));
782 command += getenv("NSHOST"); // hostname of CORBA name server
785 ASSERT(getenv("NSPORT"));
786 command += getenv("NSPORT"); // port of CORBA name server
788 std::string wdir = params.workingdir.in();
791 command += " WORKINGDIR ";
793 if(wdir == "$TEMPDIR")
795 command += wdir; // requested working directory
801 command += " mpirun -np ";
802 std::ostringstream o;
806 command += "-x PATH,LD_LIBRARY_PATH,OMNIORB_CONFIG,SALOME_trace ";
807 #elif defined(WITHOPENMPI)
808 if( getenv("OMPI_URI_FILE") == NULL )
809 command += "-x PATH -x LD_LIBRARY_PATH -x OMNIORB_CONFIG -x SALOME_trace";
811 command += "-x PATH -x LD_LIBRARY_PATH -x OMNIORB_CONFIG -x SALOME_trace -ompi-server file:";
812 command += getenv("OMPI_URI_FILE");
814 #elif defined(WITHMPICH)
815 command += "-nameserver " + Kernel_Utils::GetHostname();
817 command += " SALOME_MPIContainer ";
820 command += " " +container_exe+ " ";
822 command += _NS->ContainerName(params);
824 AddOmninamesParams(command);
826 MESSAGE("command =" << command);
832 //=============================================================================
834 * builds the command to be launched.
836 //=============================================================================
838 SALOME_ContainerManager::BuildCommandToLaunchLocalContainer
839 (const Engines::ContainerParameters& params, const std::string& machinesFile, const std::string& container_exe)
841 _TmpFileName = BuildTemporaryFileName();
845 std::ostringstream o;
851 if ( params.nb_proc <= 0 )
854 nbproc = params.nb_proc;
858 if( getenv("LIBBATCH_NODEFILE") != NULL )
859 o << "-machinefile " << machinesFile << " ";
862 o << "-x PATH,LD_LIBRARY_PATH,OMNIORB_CONFIG,SALOME_trace ";
863 #elif defined(WITHOPENMPI)
864 if( getenv("OMPI_URI_FILE") == NULL )
865 o << "-x PATH -x LD_LIBRARY_PATH -x OMNIORB_CONFIG -x SALOME_trace";
868 o << "-x PATH -x LD_LIBRARY_PATH -x OMNIORB_CONFIG -x SALOME_trace -ompi-server file:";
869 o << getenv("OMPI_URI_FILE");
871 #elif defined(WITHMPICH)
872 o << "-nameserver " + Kernel_Utils::GetHostname();
875 if (isPythonContainer(params.container_name))
876 o << " pyMPI SALOME_ContainerPy.py ";
878 o << " SALOME_MPIContainer ";
883 std::string wdir=params.workingdir.in();
886 // a working directory is requested
887 if(wdir == "$TEMPDIR")
889 // a new temporary directory is requested
890 std::string dir = Kernel_Utils::GetTmpDir();
892 o << "cd /d " << dir << std::endl;
894 o << "cd " << dir << ";";
900 // a permanent directory is requested use it or create it
902 o << "mkdir " + wdir << std::endl;
903 o << "cd /D " + wdir << std::endl;
905 o << "mkdir -p " << wdir << " && cd " << wdir + ";";
910 if (isPythonContainer(params.container_name))
911 o << "SALOME_ContainerPy.py ";
913 o << container_exe + " ";
917 o << _NS->ContainerName(params);
919 AddOmninamesParams(o);
921 std::ofstream command_file( _TmpFileName.c_str() );
922 command_file << o.str();
923 command_file.close();
926 chmod(_TmpFileName.c_str(), 0x1ED);
928 command = _TmpFileName;
930 MESSAGE("Command is file ... " << command);
931 MESSAGE("Command is ... " << o.str());
936 //=============================================================================
938 * removes the generated temporary file in case of a remote launch.
940 //=============================================================================
942 void SALOME_ContainerManager::RmTmpFile(std::string& tmpFileName)
944 int lenght = tmpFileName.size();
948 std::string command = "del /F ";
950 std::string command = "rm ";
953 command += tmpFileName.substr(0, lenght - 3 );
955 command += tmpFileName;
957 system(command.c_str());
958 //if dir is empty - remove it
959 std::string tmp_dir = Kernel_Utils::GetDirByPath( tmpFileName );
960 if ( Kernel_Utils::IsEmptyDir( tmp_dir ) )
963 command = "del /F " + tmp_dir;
965 command = "rmdir " + tmp_dir;
967 system(command.c_str());
972 //=============================================================================
974 * add to command all options relative to naming service.
976 //=============================================================================
978 void SALOME_ContainerManager::AddOmninamesParams(std::string& command) const
980 CORBA::String_var iorstr = _NS->getIORaddr();
981 command += "ORBInitRef NameService=";
985 //=============================================================================
987 * add to command all options relative to naming service.
989 //=============================================================================
991 void SALOME_ContainerManager::AddOmninamesParams(std::ofstream& fileStream) const
993 CORBA::String_var iorstr = _NS->getIORaddr();
994 fileStream << "ORBInitRef NameService=";
995 fileStream << iorstr;
998 //=============================================================================
1000 * add to command all options relative to naming service.
1002 //=============================================================================
1004 void SALOME_ContainerManager::AddOmninamesParams(std::ostringstream& oss) const
1006 CORBA::String_var iorstr = _NS->getIORaddr();
1007 oss << "ORBInitRef NameService=";
1011 //=============================================================================
1013 * generate a file name in /tmp directory
1015 //=============================================================================
1017 std::string SALOME_ContainerManager::BuildTemporaryFileName() const
1019 //build more complex file name to support multiple salome session
1020 std::string aFileName = Kernel_Utils::GetTmpFileName();
1024 aFileName += ".bat";
1029 //=============================================================================
1031 * Builds in a temporary file the script to be launched.
1033 * Used if SALOME Application ($APPLI) is not defined.
1034 * The command is build with data from CatalogResources, in which every path
1035 * used on remote computer must be defined.
1037 //=============================================================================
1040 SALOME_ContainerManager::BuildTempFileToLaunchRemoteContainer
1041 (const std::string& resource_name,
1042 const Engines::ContainerParameters& params) throw(SALOME_Exception)
1046 _TmpFileName = BuildTemporaryFileName();
1047 std::ofstream tempOutputFile;
1048 tempOutputFile.open(_TmpFileName.c_str(), std::ofstream::out );
1049 const ParserResourcesType& resInfo = _ResManager->GetImpl()->GetResourcesDescr(resource_name);
1050 tempOutputFile << "#! /bin/sh" << std::endl;
1054 tempOutputFile << "export SALOME_trace=local" << std::endl; // mkr : 27.11.2006 : PAL13967 - Distributed supervision graphs - Problem with "SALOME_trace"
1055 //tempOutputFile << "source " << resInfo.PreReqFilePath << endl;
1061 tempOutputFile << "mpirun -np ";
1064 if ( params.nb_proc <= 0 )
1067 nbproc = params.nb_proc;
1069 std::ostringstream o;
1071 tempOutputFile << nbproc << " ";
1073 tempOutputFile << "-x PATH,LD_LIBRARY_PATH,OMNIORB_CONFIG,SALOME_trace ";
1074 #elif defined(WITHOPENMPI)
1075 if( getenv("OMPI_URI_FILE") == NULL )
1076 tempOutputFile << "-x PATH -x LD_LIBRARY_PATH -x OMNIORB_CONFIG -x SALOME_trace";
1078 tempOutputFile << "-x PATH -x LD_LIBRARY_PATH -x OMNIORB_CONFIG -x SALOME_trace -ompi-server file:";
1079 tempOutputFile << getenv("OMPI_URI_FILE");
1081 #elif defined(WITHMPICH)
1082 tempOutputFile << "-nameserver " + Kernel_Utils::GetHostname();
1086 tempOutputFile << getenv("KERNEL_ROOT_DIR") << "/bin/salome/";
1090 if (isPythonContainer(params.container_name))
1091 tempOutputFile << " pyMPI SALOME_ContainerPy.py ";
1093 tempOutputFile << " SALOME_MPIContainer ";
1098 if (isPythonContainer(params.container_name))
1099 tempOutputFile << "SALOME_ContainerPy.py ";
1101 tempOutputFile << "SALOME_Container ";
1104 tempOutputFile << _NS->ContainerName(params) << " -";
1105 AddOmninamesParams(tempOutputFile);
1106 tempOutputFile << " &" << std::endl;
1107 tempOutputFile.flush();
1108 tempOutputFile.close();
1110 chmod(_TmpFileName.c_str(), 0x1ED);
1113 // --- Build command
1115 std::string command;
1117 if (resInfo.Protocol == rsh)
1120 std::string commandRcp = "rcp ";
1121 commandRcp += _TmpFileName;
1123 commandRcp += resInfo.HostName;
1125 commandRcp += _TmpFileName;
1126 status = system(commandRcp.c_str());
1129 else if (resInfo.Protocol == ssh)
1132 std::string commandRcp = "scp ";
1133 commandRcp += _TmpFileName;
1135 commandRcp += resInfo.HostName;
1137 commandRcp += _TmpFileName;
1138 status = system(commandRcp.c_str());
1141 else if (resInfo.Protocol == srun)
1143 command = "srun -n 1 -N 1 --share --nodelist=";
1144 std::string commandRcp = "rcp ";
1145 commandRcp += _TmpFileName;
1147 commandRcp += resInfo.HostName;
1149 commandRcp += _TmpFileName;
1150 status = system(commandRcp.c_str());
1153 throw SALOME_Exception("Unknown protocol");
1156 throw SALOME_Exception("Error of connection on remote host");
1158 command += resInfo.HostName;
1159 _CommandForRemAccess = command;
1161 command += _TmpFileName;
1169 std::string SALOME_ContainerManager::GetMPIZeroNode(const std::string machine, const std::string machinesFile)
1172 std::string zeronode;
1173 std::string command;
1174 std::string tmpFile = BuildTemporaryFileName();
1176 if( getenv("LIBBATCH_NODEFILE") == NULL )
1178 if (_isAppliSalomeDefined)
1180 const ParserResourcesType& resInfo = _ResManager->GetImpl()->GetResourcesDescr(machine);
1182 if (resInfo.Protocol == rsh)
1184 else if (resInfo.Protocol == ssh)
1186 else if (resInfo.Protocol == srun)
1187 command = "srun -n 1 -N 1 --share --nodelist=";
1189 throw SALOME_Exception("Unknown protocol");
1191 if (resInfo.UserName != "")
1194 command += resInfo.UserName;
1198 command += resInfo.HostName;
1201 if (resInfo.AppliPath != "")
1202 command += resInfo.AppliPath; // path relative to user@machine $HOME
1205 ASSERT(getenv("APPLI"));
1206 command += getenv("APPLI"); // path relative to user@machine $HOME
1209 command += "/runRemote.sh ";
1211 ASSERT(getenv("NSHOST"));
1212 command += getenv("NSHOST"); // hostname of CORBA name server
1215 ASSERT(getenv("NSPORT"));
1216 command += getenv("NSPORT"); // port of CORBA name server
1218 command += " mpirun -np 1 hostname -s > " + tmpFile;
1221 command = "mpirun -np 1 hostname -s > " + tmpFile;
1224 command = "mpirun -np 1 -machinefile " + machinesFile + " hostname -s > " + tmpFile;
1226 status = system(command.c_str());
1228 std::ifstream fp(tmpFile.c_str(),std::ios::in);
1229 while(fp >> zeronode);
1237 std::string SALOME_ContainerManager::machinesFile(const int nbproc)
1240 std::string nodesFile = getenv("LIBBATCH_NODEFILE");
1241 std::string machinesFile = Kernel_Utils::GetTmpFileName();
1242 std::ifstream fpi(nodesFile.c_str(),std::ios::in);
1243 std::ofstream fpo(machinesFile.c_str(),std::ios::out);
1245 _numInstanceMutex.lock();
1247 for(int i=0;i<_nbprocUsed;i++)
1250 for(int i=0;i<nbproc;i++)
1252 fpo << tmp << std::endl;
1254 throw SALOME_Exception("You need more processors than batch session have allocated for you! Unable to launch the mpi container: ");
1256 _nbprocUsed += nbproc;
1260 _numInstanceMutex.unlock();
1262 return machinesFile;
1266 std::set<pid_t> SALOME_ContainerManager::getpidofprogram(const std::string program)
1268 std::set<pid_t> thepids;
1269 std::string tmpFile = Kernel_Utils::GetTmpFileName();
1272 cmd = "pidof " + program + " > " + tmpFile;
1273 system(cmd.c_str());
1274 std::ifstream fpi(tmpFile.c_str(),std::ios::in);
1275 while(fpi >> thepid){
1276 thepids.insert(atoi(thepid.c_str()));
1281 std::string SALOME_ContainerManager::getCommandToRunRemoteProcess(AccessProtocolType protocol,
1282 const std::string & hostname,
1283 const std::string & username)
1285 std::ostringstream command;
1292 command << "-l " << username << " ";
1294 command << hostname << " ";
1300 command << "-l " << username << " ";
1302 command << hostname << " ";
1305 // no need to redefine the user with srun, the job user is taken by default
1306 // (note: for srun, user id can be specified with " --uid=<user>")
1307 command << "srun -n 1 -N 1 --share --nodelist=" << hostname << " ";
1310 command << "pbsdsh -o -h " << hostname << " ";
1313 command << "blaunch -no-shell " << hostname << " ";
1316 throw SALOME_Exception("Unknown protocol");
1319 return command.str();
1323 SALOME_ContainerManager::checkPaCOParameters(Engines::ContainerParameters & params, std::string resource_selected)
1327 // Step 1 : check ContainerParameters
1328 // Check container_name, has to be defined
1329 if (std::string(params.container_name.in()) == "")
1331 INFOS("[checkPaCOParameters] You must define a container_name to launch a PaCO++ container");
1334 // Check parallelLib
1335 std::string parallelLib = params.parallelLib.in();
1336 if (parallelLib != "Mpi" && parallelLib != "Dummy")
1338 INFOS("[checkPaCOParameters] parallelLib is not correctly defined");
1339 INFOS("[checkPaCOParameters] you can chosse between: Mpi and Dummy");
1340 INFOS("[checkPaCOParameters] you entered: " << parallelLib);
1344 if (params.nb_proc <= 0)
1346 INFOS("[checkPaCOParameters] You must define a nb_proc > 0");
1350 // Step 2 : check resource_selected
1351 Engines::ResourceDefinition_var resource_definition = _ResManager->GetResourceDefinition(resource_selected.c_str());
1352 std::string protocol = resource_definition->protocol.in();
1353 std::string username = resource_definition->username.in();
1354 std::string applipath = resource_definition->applipath.in();
1356 if (protocol == "" || username == "" || applipath == "")
1358 INFOS("[checkPaCOParameters] resource selected is not well defined");
1359 INFOS("[checkPaCOParameters] resource name: " << resource_definition->name.in());
1360 INFOS("[checkPaCOParameters] resource hostname: " << resource_definition->hostname.in());
1361 INFOS("[checkPaCOParameters] resource protocol: " << protocol);
1362 INFOS("[checkPaCOParameters] resource username: " << username);
1363 INFOS("[checkPaCOParameters] resource applipath: " << applipath);
1369 #ifdef WITH_PACO_PARALLEL
1371 //=============================================================================
1373 * Start a suitable PaCO++ Parallel Container in a list of machines.
1374 * \param params Container Parameters required for the container
1375 * \return CORBA container reference.
1377 //=============================================================================
1378 Engines::Container_ptr
1379 SALOME_ContainerManager::StartPaCOPPContainer(const Engines::ContainerParameters& params_const,
1380 std::string resource_selected)
1382 CORBA::Object_var obj;
1383 PaCO::InterfaceManager_var container_proxy;
1384 Engines::Container_ptr ret = Engines::Container::_nil();
1385 Engines::ContainerParameters params(params_const);
1386 params.resource_params.name = CORBA::string_dup(resource_selected.c_str());
1388 // Step 0 : Check parameters
1389 if (!checkPaCOParameters(params, resource_selected))
1391 INFOS("[StartPaCOPPContainer] check parameters failed ! see logs...");
1395 // Step 1 : Starting a new parallel container !
1396 INFOS("[StartPaCOPPContainer] Starting a PaCO++ parallel container");
1397 INFOS("[StartPaCOPPContainer] on resource : " << resource_selected);
1399 // Step 2 : Get a MachineFile for the parallel container
1400 std::string machine_file_name = _ResManager->getMachineFile(resource_selected,
1402 params.parallelLib.in());
1404 if (machine_file_name == "")
1406 INFOS("[StartPaCOPPContainer] Machine file generation failed");
1410 // Step 3 : starting parallel container proxy
1411 std::string command_proxy("");
1412 std::string proxy_machine;
1415 command_proxy = BuildCommandToLaunchPaCOProxyContainer(params, machine_file_name, proxy_machine);
1417 catch(const SALOME_Exception & ex)
1419 INFOS("[StartPaCOPPContainer] Exception in BuildCommandToLaunchPaCOContainer");
1423 obj = LaunchPaCOProxyContainer(command_proxy, params, proxy_machine);
1424 if (CORBA::is_nil(obj))
1426 INFOS("[StartPaCOPPContainer] LaunchPaCOContainer for proxy returns NIL !");
1429 container_proxy = PaCO::InterfaceManager::_narrow(obj);
1430 MESSAGE("[StartPaCOPPContainer] PaCO container proxy is launched");
1432 // Step 4 : starting parallel container nodes
1433 std::string command_nodes("");
1434 SALOME_ContainerManager::actual_launch_machine_t nodes_machines;
1437 command_nodes = BuildCommandToLaunchPaCONodeContainer(params, machine_file_name, nodes_machines, proxy_machine);
1439 catch(const SALOME_Exception & ex)
1441 INFOS("[StarPaCOPPContainer] Exception in BuildCommandToLaunchPaCONodeContainer");
1446 std::string container_generic_node_name = std::string(params.container_name.in()) + std::string("Node");
1447 bool result = LaunchPaCONodeContainer(command_nodes, params, container_generic_node_name, nodes_machines);
1450 INFOS("[StarPaCOPPContainer] LaunchPaCONodeContainer failed !");
1451 // Il faut tuer le proxy
1454 Engines::Container_var proxy = Engines::Container::_narrow(container_proxy);
1459 INFOS("[StarPaCOPPContainer] Exception catched from proxy Shutdown...");
1464 // Step 4 : connecting nodes and the proxy to actually create a parallel container
1465 for (int i = 0; i < params.nb_proc; i++)
1467 std::ostringstream tmp;
1469 std::string proc_number = tmp.str();
1470 std::string container_node_name = container_generic_node_name + proc_number;
1472 std::string theNodeMachine(nodes_machines[i]);
1473 std::string containerNameInNS = _NS->BuildContainerNameForNS(container_node_name.c_str(), theNodeMachine.c_str());
1474 obj = _NS->Resolve(containerNameInNS.c_str());
1475 if (CORBA::is_nil(obj))
1477 INFOS("[StarPaCOPPContainer] CONNECTION FAILED From Naming Service !");
1478 INFOS("[StarPaCOPPContainer] Container name is " << containerNameInNS);
1483 MESSAGE("[StarPaCOPPContainer] Deploying node : " << container_node_name);
1484 PaCO::InterfaceParallel_var node = PaCO::InterfaceParallel::_narrow(obj);
1486 MESSAGE("[StarPaCOPPContainer] node " << container_node_name << " is deployed");
1488 catch(CORBA::SystemException& e)
1490 INFOS("[StarPaCOPPContainer] Exception in deploying node : " << containerNameInNS);
1491 INFOS("CORBA::SystemException : " << e);
1494 catch(CORBA::Exception& e)
1496 INFOS("[StarPaCOPPContainer] Exception in deploying node : " << containerNameInNS);
1497 INFOS("CORBA::Exception" << e);
1502 INFOS("[StarPaCOPPContainer] Exception in deploying node : " << containerNameInNS);
1503 INFOS("Unknown exception !");
1508 // Step 5 : starting parallel container
1511 MESSAGE ("[StarPaCOPPContainer] Starting parallel object");
1512 container_proxy->start();
1513 MESSAGE ("[StarPaCOPPContainer] Parallel object is started");
1514 ret = Engines::Container::_narrow(container_proxy);
1516 catch(CORBA::SystemException& e)
1518 INFOS("Caught CORBA::SystemException. : " << e);
1520 catch(PortableServer::POA::ServantAlreadyActive&)
1522 INFOS("Caught CORBA::ServantAlreadyActiveException");
1524 catch(CORBA::Exception&)
1526 INFOS("Caught CORBA::Exception.");
1528 catch(std::exception& exc)
1530 INFOS("Caught std::exception - "<<exc.what());
1534 INFOS("Caught unknown exception.");
1540 SALOME_ContainerManager::BuildCommandToLaunchPaCOProxyContainer(const Engines::ContainerParameters& params,
1541 std::string machine_file_name,
1542 std::string & proxy_hostname)
1544 // In the proxy case, we always launch a Dummy Proxy
1545 std::string exe_name = "SALOME_ParallelContainerProxyDummy";
1546 std::string container_name = params.container_name.in();
1548 // Convert nb_proc in string
1549 std::ostringstream tmp_string;
1550 tmp_string << params.nb_proc;
1551 std::string nb_proc_str = tmp_string.str();
1553 // Get resource definition
1554 Engines::ResourceDefinition_var resource_definition =
1555 _ResManager->GetResourceDefinition(params.resource_params.name);
1558 std::string hostname;
1559 std::ifstream machine_file(machine_file_name.c_str());
1560 std::getline(machine_file, hostname, ' ');
1561 size_t found = hostname.find('\n');
1562 if (found!=std::string::npos)
1563 hostname.erase(found, 1); // Remove \n
1564 proxy_hostname = hostname;
1565 MESSAGE("[BuildCommandToLaunchPaCOProxyContainer] machine file name extracted is " << hostname);
1568 bool remote_execution = false;
1569 if (hostname != std::string(Kernel_Utils::GetHostname()))
1571 MESSAGE("[BuildCommandToLaunchPaCOProxyContainer] remote machine case detected !");
1572 remote_execution = true;
1575 // Log environnement
1576 std::string log_type("");
1577 char * get_val = getenv("PARALLEL_LOG");
1581 // Generating the command
1582 std::string command_begin("");
1583 std::string command_end("");
1584 std::ostringstream command;
1586 LogConfiguration(log_type, "proxy", container_name, hostname, command_begin, command_end);
1587 command << command_begin;
1589 // Adding connection command
1590 // We can only have a remote execution with
1591 // a SALOME application
1592 if (remote_execution)
1594 ASSERT(getenv("NSHOST"));
1595 ASSERT(getenv("NSPORT"));
1597 command << resource_definition->protocol.in();
1599 command << resource_definition->username.in();
1600 command << " " << hostname;
1601 command << " " << resource_definition->applipath.in();
1602 command << "/runRemote.sh ";
1603 command << getenv("NSHOST") << " "; // hostname of CORBA name server
1604 command << getenv("NSPORT") << " "; // port of CORBA name server
1607 command << exe_name;
1608 command << " " << container_name;
1609 command << " Dummy";
1610 command << " " << hostname;
1611 command << " " << nb_proc_str;
1613 AddOmninamesParams(command);
1616 command << command_end;
1617 MESSAGE("[BuildCommandToLaunchPaCOProxyContainer] Command is: " << command.str());
1619 return command.str();
1623 SALOME_ContainerManager::BuildCommandToLaunchPaCONodeContainer(const Engines::ContainerParameters& params,
1624 const std::string & machine_file_name,
1625 SALOME_ContainerManager::actual_launch_machine_t & vect_machine,
1626 const std::string & proxy_hostname)
1629 std::string exe_name = "SALOME_ParallelContainerNode";
1630 exe_name += params.parallelLib.in();
1631 std::string container_name = params.container_name.in();
1633 // Convert nb_proc in string
1634 std::ostringstream nb_proc_stream;
1635 nb_proc_stream << params.nb_proc;
1637 // Get resource definition
1638 Engines::ResourceDefinition_var resource_definition =
1639 _ResManager->GetResourceDefinition(params.resource_params.name);
1641 // Log environnement
1642 std::string log_type("");
1643 char * get_val = getenv("PARALLEL_LOG");
1647 // Now the command is different according to paralleLib
1648 std::ostringstream command_nodes;
1649 std::ifstream machine_file(machine_file_name.c_str());
1650 if (std::string(params.parallelLib.in()) == "Dummy")
1652 for (int i= 0; i < params.nb_proc; i++)
1655 std::string hostname;
1656 std::getline(machine_file, hostname);
1657 MESSAGE("[BuildCommandToLaunchPaCONodeContainer] machine file name extracted is " << hostname);
1660 bool remote_execution = false;
1661 if (hostname != std::string(Kernel_Utils::GetHostname()))
1663 MESSAGE("[BuildCommandToLaunchPaCONodeContainer] remote machine case detected !");
1664 remote_execution = true;
1667 // For each node we have a new command
1668 // Generating the command
1669 std::ostringstream command_node_stream;
1670 std::string command_node_begin("");
1671 std::string command_node_end("");
1672 std::ostringstream node_number;
1674 std::string container_node_name = container_name + node_number.str();
1675 LogConfiguration(log_type, "node", container_node_name, hostname, command_node_begin, command_node_end);
1677 // Adding connection command
1678 // We can only have a remote execution with
1679 // a SALOME application
1680 if (remote_execution)
1682 ASSERT(getenv("NSHOST"));
1683 ASSERT(getenv("NSPORT"));
1685 command_node_stream << resource_definition->protocol.in();
1686 command_node_stream << " -l ";
1687 command_node_stream << resource_definition->username.in();
1688 command_node_stream << " " << hostname;
1689 command_node_stream << " " << resource_definition->applipath.in();
1690 command_node_stream << "/runRemote.sh ";
1691 command_node_stream << getenv("NSHOST") << " "; // hostname of CORBA name server
1692 command_node_stream << getenv("NSPORT") << " "; // port of CORBA name server
1695 command_node_stream << exe_name;
1696 command_node_stream << " " << container_name;
1697 command_node_stream << " " << params.parallelLib.in();
1698 command_node_stream << " " << proxy_hostname;
1699 command_node_stream << " " << node_number.str();
1700 command_node_stream << " -";
1701 AddOmninamesParams(command_node_stream);
1703 command_nodes << command_node_begin << command_node_stream.str() << command_node_end;
1704 vect_machine.push_back(hostname);
1708 else if (std::string(params.parallelLib.in()) == "Mpi")
1711 std::string hostname;
1712 std::getline(machine_file, hostname, ' ');
1713 MESSAGE("[BuildCommandToLaunchPaCONodeContainer] machine file name extracted is " << hostname);
1716 bool remote_execution = false;
1717 if (hostname != std::string(Kernel_Utils::GetHostname()))
1719 MESSAGE("[BuildCommandToLaunchPaCONodeContainer] remote machine case detected !");
1720 remote_execution = true;
1723 // In case of Mpi and Remote, we copy machine_file in the applipath
1724 // scp mpi_machine_file user@machine:Path
1725 std::ostringstream command_remote_stream;
1726 std::string::size_type last = machine_file_name.find_last_of("/");
1727 if (last == std::string::npos)
1730 std::string protocol = resource_definition->protocol.in();
1731 if (protocol == "rsh")
1732 command_remote_stream << "rcp ";
1734 command_remote_stream << "scp ";
1735 command_remote_stream << machine_file_name << " ";
1736 command_remote_stream << resource_definition->username.in() << "@";
1737 command_remote_stream << hostname << ":" << resource_definition->applipath.in();
1738 command_remote_stream << "/" << machine_file_name.substr(last+1);
1740 int status = system(command_remote_stream.str().c_str());
1743 INFOS("copy of the MPI machine file failed ! - sorry !");
1747 // Generating the command
1748 std::string command_begin("");
1749 std::string command_end("");
1751 LogConfiguration(log_type, "nodes", container_name, hostname, command_begin, command_end);
1752 command_nodes << command_begin;
1754 // Adding connection command
1755 // We can only have a remote execution with
1756 // a SALOME application
1757 if (remote_execution)
1759 ASSERT(getenv("NSHOST"));
1760 ASSERT(getenv("NSPORT"));
1762 command_nodes << resource_definition->protocol.in();
1763 command_nodes << " -l ";
1764 command_nodes << resource_definition->username.in();
1765 command_nodes << " " << hostname;
1766 command_nodes << " " << resource_definition->applipath.in();
1767 command_nodes << "/runRemote.sh ";
1768 command_nodes << getenv("NSHOST") << " "; // hostname of CORBA name server
1769 command_nodes << getenv("NSPORT") << " "; // port of CORBA name server
1772 if (std::string(resource_definition->mpiImpl.in()) == "lam")
1774 command_nodes << "mpiexec -ssi boot ";
1775 command_nodes << "-machinefile " << machine_file_name << " ";
1776 command_nodes << "-n " << params.nb_proc;
1780 command_nodes << "mpirun -np " << params.nb_proc;
1782 command_nodes << " " << exe_name;
1783 command_nodes << " " << container_name;
1784 command_nodes << " " << params.parallelLib.in();
1785 command_nodes << " " << proxy_hostname;
1786 command_nodes << " -";
1787 AddOmninamesParams(command_nodes);
1789 // We don't put hostname, because nodes are registered in the resource of the proxy
1790 for (int i= 0; i < params.nb_proc; i++)
1791 vect_machine.push_back(proxy_hostname);
1793 command_nodes << command_end;
1795 return command_nodes.str();
1799 SALOME_ContainerManager::LogConfiguration(const std::string & log_type,
1800 const std::string & exe_type,
1801 const std::string & container_name,
1802 const std::string & hostname,
1803 std::string & begin,
1806 if(log_type == "xterm")
1808 begin = "xterm -e \"export LD_LIBRARY_PATH=$LD_LIBRARY_PATH; export PATH=$PATH;";
1811 else if(log_type == "xterm_debug")
1813 begin = "xterm -e \"export LD_LIBRARY_PATH=$LD_LIBRARY_PATH; export PATH=$PATH;";
1818 // default into a file...
1819 std::string logFilename = "/tmp/" + container_name + "_" + hostname + "_" + exe_type + "_";
1820 logFilename += std::string(getenv("USER")) + ".log";
1821 end = " > " + logFilename + " 2>&1 & ";
1826 SALOME_ContainerManager::LaunchPaCOProxyContainer(const std::string& command,
1827 const Engines::ContainerParameters& params,
1828 const std::string & hostname)
1830 PaCO::InterfaceManager_ptr container_proxy = PaCO::InterfaceManager::_nil();
1832 MESSAGE("[LaunchPaCOProxyContainer] Launch command");
1833 int status = system(command.c_str());
1835 INFOS("[LaunchPaCOProxyContainer] failed : system command status -1");
1836 return container_proxy;
1838 else if (status == 217) {
1839 INFOS("[LaunchPaCOProxyContainer] failed : system command status 217");
1840 return container_proxy;
1843 int count = TIME_OUT_TO_LAUNCH_CONT;
1844 CORBA::Object_var obj = CORBA::Object::_nil();
1845 std::string containerNameInNS = _NS->BuildContainerNameForNS(params.container_name.in(),
1847 MESSAGE("[LaunchParallelContainer] Waiting for Parallel Container proxy : " << containerNameInNS);
1849 while (CORBA::is_nil(obj) && count)
1853 obj = _NS->Resolve(containerNameInNS.c_str());
1858 container_proxy = PaCO::InterfaceManager::_narrow(obj);
1860 catch(CORBA::SystemException& e)
1862 INFOS("[StarPaCOPPContainer] Exception in _narrow after LaunchParallelContainer for proxy !");
1863 INFOS("CORBA::SystemException : " << e);
1864 return container_proxy;
1866 catch(CORBA::Exception& e)
1868 INFOS("[StarPaCOPPContainer] Exception in _narrow after LaunchParallelContainer for proxy !");
1869 INFOS("CORBA::Exception" << e);
1870 return container_proxy;
1874 INFOS("[StarPaCOPPContainer] Exception in _narrow after LaunchParallelContainer for proxy !");
1875 INFOS("Unknown exception !");
1876 return container_proxy;
1878 if (CORBA::is_nil(container_proxy))
1880 INFOS("[StarPaCOPPContainer] PaCO::InterfaceManager::_narrow returns NIL !");
1881 return container_proxy;
1886 //=============================================================================
1887 /*! This method launches the parallel container.
1888 * It will may be placed on the ressources manager.
1890 * \param command to launch
1891 * \param container's parameters
1892 * \param name of the container
1894 * \return CORBA container reference
1896 //=============================================================================
1898 SALOME_ContainerManager::LaunchPaCONodeContainer(const std::string& command,
1899 const Engines::ContainerParameters& params,
1900 const std::string& name,
1901 SALOME_ContainerManager::actual_launch_machine_t & vect_machine)
1903 INFOS("[LaunchPaCONodeContainer] Launch command");
1904 int status = system(command.c_str());
1906 INFOS("[LaunchPaCONodeContainer] failed : system command status -1");
1909 else if (status == 217) {
1910 INFOS("[LaunchPaCONodeContainer] failed : system command status 217");
1914 INFOS("[LaunchPaCONodeContainer] Waiting for the nodes of the parallel container");
1915 // We are waiting all the nodes
1916 for (int i = 0; i < params.nb_proc; i++)
1918 CORBA::Object_var obj = CORBA::Object::_nil();
1919 std::string theMachine(vect_machine[i]);
1921 std::ostringstream tmp;
1923 std::string proc_number = tmp.str();
1924 std::string container_node_name = name + proc_number;
1925 std::string containerNameInNS = _NS->BuildContainerNameForNS((char*) container_node_name.c_str(), theMachine.c_str());
1926 INFOS("[LaunchPaCONodeContainer] Waiting for Parallel Container node " << containerNameInNS << " on " << theMachine);
1927 int count = TIME_OUT_TO_LAUNCH_CONT;
1928 while (CORBA::is_nil(obj) && count) {
1931 obj = _NS->Resolve(containerNameInNS.c_str());
1933 if (CORBA::is_nil(obj))
1935 INFOS("[LaunchPaCONodeContainer] Launch of node failed (or not found) !");
1944 Engines::Container_ptr
1945 SALOME_ContainerManager::StartPaCOPPContainer(const Engines::ContainerParameters& params,
1946 std::string resource_selected)
1948 Engines::Container_ptr ret = Engines::Container::_nil();
1949 INFOS("[StarPaCOPPContainer] is disabled !");
1950 INFOS("[StarPaCOPPContainer] recompile SALOME Kernel to enable PaCO++ parallel extension");
1955 SALOME_ContainerManager::BuildCommandToLaunchPaCOProxyContainer(const Engines::ContainerParameters& params,
1956 std::string machine_file_name,
1957 std::string & proxy_hostname)
1963 SALOME_ContainerManager::BuildCommandToLaunchPaCONodeContainer(const Engines::ContainerParameters& params,
1964 const std::string & machine_file_name,
1965 SALOME_ContainerManager::actual_launch_machine_t & vect_machine,
1966 const std::string & proxy_hostname)
1971 SALOME_ContainerManager::LogConfiguration(const std::string & log_type,
1972 const std::string & exe_type,
1973 const std::string & container_name,
1974 const std::string & hostname,
1975 std::string & begin,
1981 SALOME_ContainerManager::LaunchPaCOProxyContainer(const std::string& command,
1982 const Engines::ContainerParameters& params,
1983 const std::string& hostname)
1985 CORBA::Object_ptr ret = CORBA::Object::_nil();
1990 SALOME_ContainerManager::LaunchPaCONodeContainer(const std::string& command,
1991 const Engines::ContainerParameters& params,
1992 const std::string& name,
1993 SALOME_ContainerManager::actual_launch_machine_t & vect_machine)