1 // Copyright (C) 2007-2008 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
22 #include "SALOME_ContainerManager.hxx"
23 #include "SALOME_NamingService.hxx"
24 #include "SALOME_ModuleCatalog.hh"
25 #include "Basics_Utils.hxx"
26 #include "Basics_DirUtils.hxx"
27 #include <sys/types.h>
33 #include "Utils_CorbaException.hxx"
34 #include "Batch_Date.hxx"
37 #ifdef WITH_PACO_PARALLEL
41 #define TIME_OUT_TO_LAUNCH_CONT 61
45 vector<Engines::Container_ptr> SALOME_ContainerManager::_batchLaunchedContainers;
47 vector<Engines::Container_ptr>::iterator SALOME_ContainerManager::_batchLaunchedContainersIter;
49 const char *SALOME_ContainerManager::_ContainerManagerNameInNS =
52 //=============================================================================
56 * Define a CORBA single thread policy for the server, which avoid to deal
57 * with non thread-safe usage like Change_Directory in SALOME naming service
59 //=============================================================================
61 SALOME_ContainerManager::SALOME_ContainerManager(CORBA::ORB_ptr orb, PortableServer::POA_var poa, SALOME_ResourcesManager *rm, SALOME_NamingService *ns)
63 MESSAGE("constructor");
67 PortableServer::POAManager_var pman = poa->the_POAManager();
68 _orb = CORBA::ORB::_duplicate(orb) ;
69 CORBA::PolicyList policies;
71 PortableServer::ThreadPolicy_var threadPol =
72 poa->create_thread_policy(PortableServer::SINGLE_THREAD_MODEL);
73 policies[0] = PortableServer::ThreadPolicy::_duplicate(threadPol);
75 _poa = poa->create_POA("SThreadPOA",pman,policies);
77 PortableServer::ObjectId_var id = _poa->activate_object(this);
78 CORBA::Object_var obj = _poa->id_to_reference(id);
79 Engines::ContainerManager_var refContMan =
80 Engines::ContainerManager::_narrow(obj);
82 _NS->Register(refContMan,_ContainerManagerNameInNS);
83 _isAppliSalomeDefined = (getenv("APPLI") != 0);
84 MESSAGE("constructor end");
87 //=============================================================================
91 //=============================================================================
93 SALOME_ContainerManager::~SALOME_ContainerManager()
95 MESSAGE("destructor");
98 //=============================================================================
99 //! shutdown all the containers, then the ContainerManager servant
102 //=============================================================================
104 void SALOME_ContainerManager::Shutdown()
107 ShutdownContainers();
108 _NS->Destroy_Name(_ContainerManagerNameInNS);
109 PortableServer::ObjectId_var oid = _poa->servant_to_id(this);
110 _poa->deactivate_object(oid);
113 //=============================================================================
114 //! Loop on all the containers listed in naming service, ask shutdown on each
117 //=============================================================================
119 void SALOME_ContainerManager::ShutdownContainers()
121 MESSAGE("ShutdownContainers");
123 isOK = _NS->Change_Directory("/Containers");
125 vector<string> vec = _NS->list_directory_recurs();
126 list<string> lstCont;
127 for(vector<string>::iterator iter = vec.begin();iter!=vec.end();iter++)
130 CORBA::Object_var obj=_NS->Resolve((*iter).c_str());
133 Engines::Container_var cont=Engines::Container::_narrow(obj);
134 if(!CORBA::is_nil(cont))
135 lstCont.push_back((*iter));
137 catch(const CORBA::Exception& e)
139 // ignore this entry and continue
142 MESSAGE("Container list: ");
143 for(list<string>::iterator iter=lstCont.begin();iter!=lstCont.end();iter++){
146 for(list<string>::iterator iter=lstCont.begin();iter!=lstCont.end();iter++)
151 CORBA::Object_var obj=_NS->Resolve((*iter).c_str());
152 Engines::Container_var cont=Engines::Container::_narrow(obj);
153 if(!CORBA::is_nil(cont))
155 MESSAGE("ShutdownContainers: " << (*iter));
159 MESSAGE("ShutdownContainers: no container ref for " << (*iter));
161 catch(CORBA::SystemException& e)
163 INFOS("CORBA::SystemException ignored : " << e);
165 catch(CORBA::Exception&)
167 INFOS("CORBA::Exception ignored.");
171 INFOS("Unknown exception ignored.");
177 //=============================================================================
178 //! Give a suitable Container given constraints
180 * \param params Machine Parameters required for the container
181 * \return the container or nil
183 //=============================================================================
185 Engines::Container_ptr
186 SALOME_ContainerManager::GiveContainer(const Engines::MachineParameters& params)
188 char *valenv=getenv("SALOME_BATCH");
190 if (strcmp(valenv,"1")==0)
192 if(_batchLaunchedContainers.empty())
193 fillBatchLaunchedContainers();
195 if (_batchLaunchedContainersIter == _batchLaunchedContainers.end())
196 _batchLaunchedContainersIter = _batchLaunchedContainers.begin();
198 Engines::Container_ptr rtn = Engines::Container::_duplicate(*_batchLaunchedContainersIter);
199 _batchLaunchedContainersIter++;
202 return StartContainer(params);
205 //=============================================================================
206 //! Start a suitable Container in a list of machines with constraints
208 * Constraints are given by a machine parameters struct
209 * \param params Machine Parameters required for the container
210 * \param possibleComputers list of machines usable for start
211 * \param container_exe specific container executable (default=SALOME_Container)
213 //=============================================================================
215 Engines::Container_ptr
216 SALOME_ContainerManager::StartContainer(const Engines::MachineParameters& params,
217 const Engines::MachineList& possibleComputers,
218 const std::string& container_exe)
220 #ifdef WITH_PACO_PARALLEL
221 std::string parallelLib(params.parallelLib);
222 if (parallelLib != "")
224 Engines::MachineParameters myparams(params);
225 myparams.computerList=possibleComputers;
226 return StartParallelContainer(myparams);
229 string containerNameInNS;
230 Engines::Container_ptr ret = Engines::Container::_nil();
232 MESSAGE("SALOME_ContainerManager::StartContainer " << possibleComputers.length());
235 // if mode is "get" keep only machines with existing containers
236 if(std::string(params.mode.in())=="get")
238 for(unsigned int i=0;i<possibleComputers.length();i++)
240 Engines::Container_ptr cont = FindContainer(params,possibleComputers[i]);
243 if(!cont->_non_existent())
244 lm.push_back(string(possibleComputers[i]));
246 catch(CORBA::Exception&)
248 // CORBA::Exception ignored.
254 for(unsigned int i=0;i<possibleComputers.length();i++)
255 lm.push_back(string(possibleComputers[i]));
261 theMachine=_ResManager->GetImpl()->Find(params.policy.in(),lm);
263 catch( const SALOME_Exception &ex )
266 return Engines::Container::_nil();
269 //If the machine name is localhost use the real name
270 if(theMachine == "localhost")
271 theMachine=Kernel_Utils::GetHostname();
273 //check if an entry exists in Naming service
274 //if params.mode == "start" or "" shutdown the existing container before launching a new one with that name
275 //if params.mode == "getorstart" or "get" use the existing container
277 // A parallel container register on zero node in NS
278 containerNameInNS = _NS->BuildContainerNameForNS(params,GetMPIZeroNode(theMachine).c_str());
280 containerNameInNS = _NS->BuildContainerNameForNS(params,theMachine.c_str());
282 SCRUTE(containerNameInNS);
283 CORBA::Object_var obj = _NS->Resolve(containerNameInNS.c_str());
284 if ( !CORBA::is_nil(obj) )
288 Engines::Container_var cont=Engines::Container::_narrow(obj);
289 if(!cont->_non_existent())
291 if(std::string(params.mode.in())=="getorstart"||std::string(params.mode.in())=="get")
292 return cont._retn(); /* the container exists and params.mode is getorstart or get use it*/
295 INFOS("A container is already registered with the name: " << containerNameInNS << ", shutdown the existing container");
296 cont->Shutdown(); // shutdown the registered container if it exists
300 catch(CORBA::Exception&)
302 INFOS("CORBA::Exception ignored.");
306 //try to launch a new container
307 MESSAGE("try to launch it on " << theMachine);
311 MESSAGE("SALOME_ContainerManager::StartContainer : no possible computer");
312 return Engines::Container::_nil();
314 else if(theMachine==Kernel_Utils::GetHostname())
315 command = BuildCommandToLaunchLocalContainer(params,container_exe);
317 command = BuildCommandToLaunchRemoteContainer(theMachine,params,container_exe);
319 //redirect stdout and stderr in a file
320 string logFilename="/tmp/"+_NS->ContainerName(params)+"_"+ theMachine +"_"+getenv( "USER" )+".log" ;
321 command += " > " + logFilename + " 2>&1 &";
323 // launch container with a system call
324 int status=system(command.c_str());
327 MESSAGE("SALOME_ContainerManager::StartContainer rsh failed (system command status -1)");
328 RmTmpFile(_TmpFileName); // command file can be removed here
329 return Engines::Container::_nil();
331 else if (status == 217){
332 MESSAGE("SALOME_ContainerManager::StartContainer rsh failed (system command status 217)");
333 RmTmpFile(_TmpFileName); // command file can be removed here
334 return Engines::Container::_nil();
337 int count=TIME_OUT_TO_LAUNCH_CONT;
338 MESSAGE("count = "<<count);
339 while ( CORBA::is_nil(ret) && count ){
347 MESSAGE( count << ". Waiting for container on " << theMachine);
349 CORBA::Object_var obj = _NS->Resolve(containerNameInNS.c_str());
350 ret=Engines::Container::_narrow(obj);
353 if ( CORBA::is_nil(ret) )
355 MESSAGE("SALOME_ContainerManager::StartContainer rsh failed");
359 logFilename=":"+logFilename;
360 logFilename="@"+Kernel_Utils::GetHostname()+logFilename;
361 logFilename=getenv( "USER" )+logFilename;
362 ret->logfilename(logFilename.c_str());
365 RmTmpFile(_TmpFileName); // command file can be removed here
370 //=============================================================================
371 //! Start a suitable Container given constraints
373 * \param params Machine Parameters required for the container
375 //=============================================================================
377 Engines::Container_ptr
378 SALOME_ContainerManager::StartContainer(const Engines::MachineParameters& params)
380 Engines::MachineList_var possibleComputers = _ResManager->GetFittingResources(params);
382 // Look into ModulCatalog if a specific container must be launched
383 CORBA::String_var container_exe;
387 CORBA::Object_var obj = _NS->Resolve("/Kernel/ModulCatalog");
388 SALOME_ModuleCatalog::ModuleCatalog_var Catalog = SALOME_ModuleCatalog::ModuleCatalog::_narrow(obj) ;
389 if (CORBA::is_nil (Catalog))
390 return Engines::Container::_nil();
391 // Loop through component list
392 for(unsigned int i=0;i<params.componentList.length();i++)
394 const char* compoi = params.componentList[i];
395 SALOME_ModuleCatalog::Acomponent_var compoInfo = Catalog->GetComponent(compoi);
396 if (CORBA::is_nil (compoInfo))
400 SALOME_ModuleCatalog::ImplType impl=compoInfo->implementation_type();
401 container_exe=compoInfo->implementation_name();
402 if(impl==SALOME_ModuleCatalog::CEXE)
406 INFOS("ContainerManager Error: you can't have 2 CEXE component in the same container" );
407 return Engines::Container::_nil();
413 catch (ServiceUnreachable&)
415 INFOS("Caught exception: Naming Service Unreachable");
416 return Engines::Container::_nil();
420 INFOS("Caught unknown exception.");
421 return Engines::Container::_nil();
425 return StartContainer(params,possibleComputers,container_exe.in());
427 return StartContainer(params,possibleComputers);
430 //=============================================================================
431 //! Find or start a suitable Container given some constraints
433 * \param params Machine Parameters required for the container
434 * \return the container or nil
436 //=============================================================================
438 Engines::Container_ptr
439 SALOME_ContainerManager::FindOrStartContainer(const Engines::MachineParameters& params)
441 Engines::Container_ptr ret = FindContainer(params,params.computerList);
442 if(!CORBA::is_nil(ret))
444 MESSAGE("Container doesn't exist try to launch it ...");
446 return StartContainer(params);
449 //=============================================================================
450 //! Find a container given constraints (params) on a list of machines (possibleComputers)
454 //=============================================================================
456 Engines::Container_ptr
457 SALOME_ContainerManager::FindContainer(const Engines::MachineParameters& params,
458 const Engines::MachineList& possibleComputers)
460 MESSAGE("FindContainer "<<possibleComputers.length());
461 for(unsigned int i=0;i<possibleComputers.length();i++)
463 MESSAGE("FindContainer possible " << possibleComputers[i]);
464 Engines::Container_ptr cont = FindContainer(params,possibleComputers[i]);
465 if( !CORBA::is_nil(cont) )
468 MESSAGE("FindContainer: not found");
469 return Engines::Container::_nil();
472 //=============================================================================
473 //! Find a container given constraints (params) on a machine (theMachine)
477 //=============================================================================
479 Engines::Container_ptr
480 SALOME_ContainerManager::FindContainer(const Engines::MachineParameters& params,
481 const char *theMachine)
483 string containerNameInNS(_NS->BuildContainerNameForNS(params,theMachine));
484 CORBA::Object_var obj = _NS->Resolve(containerNameInNS.c_str());
487 if(obj->_non_existent())
488 return Engines::Container::_nil();
490 return Engines::Container::_narrow(obj);
492 catch(const CORBA::Exception& e)
494 return Engines::Container::_nil();
498 #ifdef WITH_PACO_PARALLEL
499 //=============================================================================
501 * Find or Start a suitable PaCO++ Parallel Container in a list of machines.
502 * \param params Machine Parameters required for the container
503 * \return CORBA container reference.
505 //=============================================================================
506 Engines::Container_ptr
507 SALOME_ContainerManager::StartParallelContainer(const Engines::MachineParameters& params_const)
509 CORBA::Object_var obj;
510 PaCO::InterfaceManager_var container_proxy;
511 Engines::Container_ptr ret = Engines::Container::_nil();
512 Engines::MachineParameters params(params_const);
514 // Step 1 : Try to find a suitable container
515 // Currently not as good as could be since
516 // we have to verified the number of nodes of the container
517 // if a user tell that.
518 ret = FindContainer(params, params.computerList);
519 if(CORBA::is_nil(ret)) {
520 // Step 2 : Starting a new parallel container !
521 INFOS("[StartParallelContainer] Starting a PaCO++ parallel container");
523 // Step 3 : Choose a computer
524 std::string theMachine = _ResManager->FindFirst(params.computerList);
525 //If the machine name is localhost use the real name
526 if(theMachine == "localhost")
527 theMachine=Kernel_Utils::GetHostname();
529 if(theMachine == "") {
530 INFOS("[StartParallelContainer] !!!!!!!!!!!!!!!!!!!!!!!!!!");
531 INFOS("[StartParallelContainer] No possible computer found");
532 INFOS("[StartParallelContainer] !!!!!!!!!!!!!!!!!!!!!!!!!!");
535 INFOS("[StartParallelContainer] on machine : " << theMachine);
536 params.hostname = CORBA::string_dup(theMachine.c_str());
538 // Step 4 : starting parallel container proxy
539 Engines::MachineParameters params_proxy(params);
540 std::string command_proxy;
541 SALOME_ContainerManager::actual_launch_machine_t proxy_machine;
544 command_proxy = BuildCommandToLaunchParallelContainer("SALOME_ParallelContainerProxy", params_proxy, proxy_machine);
546 catch(const SALOME_Exception & ex)
548 INFOS("[StartParallelContainer] Exception in BuildCommandToLaunchParallelContainer");
552 params_proxy.nb_component_nodes = 0; // LaunchParallelContainer uses this value to know if it launches the proxy or the nodes
553 obj = LaunchParallelContainer(command_proxy, params_proxy, _NS->ContainerName(params_proxy), proxy_machine);
554 if (CORBA::is_nil(obj))
556 INFOS("[StartParallelContainer] LaunchParallelContainer for proxy returns NIL !");
561 container_proxy = PaCO::InterfaceManager::_narrow(obj);
563 catch(CORBA::SystemException& e)
565 INFOS("[StartParallelContainer] Exception in _narrow after LaunchParallelContainer for proxy !");
566 INFOS("CORBA::SystemException : " << e);
569 catch(CORBA::Exception& e)
571 INFOS("[StartParallelContainer] Exception in _narrow after LaunchParallelContainer for proxy !");
572 INFOS("CORBA::Exception" << e);
577 INFOS("[StartParallelContainer] Exception in _narrow after LaunchParallelContainer for proxy !");
578 INFOS("Unknown exception !");
581 if (CORBA::is_nil(container_proxy))
583 INFOS("[StartParallelContainer] PaCO::InterfaceManager::_narrow returns NIL !");
587 // Step 5 : starting parallel container nodes
588 std::string command_nodes;
589 Engines::MachineParameters params_nodes(params);
590 SALOME_ContainerManager::actual_launch_machine_t nodes_machines;
593 command_nodes = BuildCommandToLaunchParallelContainer("SALOME_ParallelContainerNode", params_nodes, nodes_machines, proxy_machine[0]);
595 catch(const SALOME_Exception & ex)
597 INFOS("[StartParallelContainer] Exception in BuildCommandToLaunchParallelContainer");
601 std::string container_generic_node_name = _NS->ContainerName(params) + "Node";
602 obj = LaunchParallelContainer(command_nodes, params_nodes, container_generic_node_name, nodes_machines);
603 if (CORBA::is_nil(obj))
605 INFOS("[StartParallelContainer] LaunchParallelContainer for nodes returns NIL !");
606 // Il faut tuer le proxy
609 Engines::Container_var proxy = Engines::Container::_narrow(container_proxy);
614 INFOS("[StartParallelContainer] Exception catched from proxy Shutdown...");
619 // Step 6 : connecting nodes and the proxy to actually create a parallel container
620 for (int i = 0; i < params.nb_component_nodes; i++)
622 std::ostringstream tmp;
624 std::string proc_number = tmp.str();
625 std::string container_node_name = container_generic_node_name + proc_number;
627 std::string theNodeMachine(nodes_machines[i]);
628 std::string containerNameInNS = _NS->BuildContainerNameForNS(container_node_name.c_str(), theNodeMachine.c_str());
629 obj = _NS->Resolve(containerNameInNS.c_str());
630 if (CORBA::is_nil(obj))
632 INFOS("[StartParallelContainer] CONNECTION FAILED From Naming Service !");
633 INFOS("[StartParallelContainer] Container name is " << containerNameInNS);
638 MESSAGE("[StartParallelContainer] Deploying node : " << container_node_name);
639 PaCO::InterfaceParallel_var node = PaCO::InterfaceParallel::_narrow(obj);
641 MESSAGE("[StartParallelContainer] node " << container_node_name << " is deployed");
643 catch(CORBA::SystemException& e)
645 INFOS("[StartParallelContainer] Exception in deploying node : " << containerNameInNS);
646 INFOS("CORBA::SystemException : " << e);
649 catch(CORBA::Exception& e)
651 INFOS("[StartParallelContainer] Exception in deploying node : " << containerNameInNS);
652 INFOS("CORBA::Exception" << e);
657 INFOS("[StartParallelContainer] Exception in deploying node : " << containerNameInNS);
658 INFOS("Unknown exception !");
663 // Step 7 : starting parallel container
666 MESSAGE ("[StartParallelContainer] Starting parallel object");
667 container_proxy->start();
668 MESSAGE ("[StartParallelContainer] Parallel object is started");
669 ret = Engines::Container::_narrow(container_proxy);
671 catch(CORBA::SystemException& e)
673 INFOS("Caught CORBA::SystemException. : " << e);
675 catch(PortableServer::POA::ServantAlreadyActive&)
677 INFOS("Caught CORBA::ServantAlreadyActiveException");
679 catch(CORBA::Exception&)
681 INFOS("Caught CORBA::Exception.");
683 catch(std::exception& exc)
685 INFOS("Caught std::exception - "<<exc.what());
689 INFOS("Caught unknown exception.");
695 //=============================================================================
697 * Find or Start a suitable PaCO++ Parallel Container in a list of machines.
698 * \param params Machine Parameters required for the container
699 * \return CORBA container reference.
701 //=============================================================================
702 Engines::Container_ptr
703 SALOME_ContainerManager::StartParallelContainer(const Engines::MachineParameters& params)
705 Engines::Container_ptr ret = Engines::Container::_nil();
706 INFOS("[StartParallelContainer] is disabled !");
707 INFOS("[StartParallelContainer] recompile SALOME Kernel to enable parallel extension");
712 //=============================================================================
713 /*! This method launches the parallel container.
714 * It will may be placed on the ressources manager.
716 * \param command to launch
717 * \param container's parameters
718 * \param name of the container
720 * \return CORBA container reference
722 //=============================================================================
724 SALOME_ContainerManager::LaunchParallelContainer(const std::string& command,
725 const Engines::MachineParameters& params,
726 const std::string& name,
727 SALOME_ContainerManager::actual_launch_machine_t & vect_machine)
729 CORBA::Object_ptr obj = CORBA::Object::_nil();
730 std::string containerNameInNS;
731 int count = TIME_OUT_TO_LAUNCH_CONT;
733 INFOS("[LaunchParallelContainer] Begin");
734 int status = system(command.c_str());
736 INFOS("[LaunchParallelContainer] failed : system command status -1");
739 else if (status == 217) {
740 INFOS("[LaunchParallelContainer] failed : system command status 217");
744 if (params.nb_component_nodes == 0)
746 std::string theMachine(vect_machine[0]);
747 // Proxy We have launch a proxy
748 containerNameInNS = _NS->BuildContainerNameForNS((char*) name.c_str(), theMachine.c_str());
749 INFOS("[LaunchParallelContainer] Waiting for Parallel Container proxy " << containerNameInNS << " on " << theMachine);
750 while (CORBA::is_nil(obj) && count)
758 obj = _NS->Resolve(containerNameInNS.c_str());
763 INFOS("[LaunchParallelContainer] launching the nodes of the parallel container");
764 // We are waiting all the nodes
765 for (int i = 0; i < params.nb_component_nodes; i++)
767 obj = CORBA::Object::_nil();
768 std::string theMachine(vect_machine[i]);
770 std::ostringstream tmp;
772 std::string proc_number = tmp.str();
773 std::string container_node_name = name + proc_number;
774 containerNameInNS = _NS->BuildContainerNameForNS((char*) container_node_name.c_str(), theMachine.c_str());
775 INFOS("[LaunchParallelContainer] Waiting for Parallel Container node " << containerNameInNS << " on " << theMachine);
776 while (CORBA::is_nil(obj) && count) {
783 obj = _NS->Resolve(containerNameInNS.c_str());
785 if (CORBA::is_nil(obj))
787 INFOS("[LaunchParallelContainer] Launch of node failed (or not found) !");
792 if (CORBA::is_nil(obj))
793 INFOS("[LaunchParallelContainer] failed");
798 void SALOME_ContainerManager::fillBatchLaunchedContainers()
800 _batchLaunchedContainers.clear();
801 _NS->Change_Directory("/Containers");
802 vector<string> vec = _NS->list_directory_recurs();
803 for(vector<string>::iterator iter = vec.begin();iter!=vec.end();iter++){
804 CORBA::Object_var obj=_NS->Resolve((*iter).c_str());
805 Engines::Container_ptr cont=Engines::Container::_narrow(obj);
806 if(!CORBA::is_nil(cont)){
807 _batchLaunchedContainers.push_back(cont);
810 _batchLaunchedContainersIter=_batchLaunchedContainers.begin();
813 //=============================================================================
815 * This is no longer valid (C++ container are also python containers)
817 //=============================================================================
819 bool isPythonContainer(const char* ContainerName)
822 int len = strlen(ContainerName);
825 if (strcmp(ContainerName + len - 2, "Py") == 0)
831 //=============================================================================
833 * Builds the script to be launched
835 * If SALOME Application not defined ($APPLI),
836 * see BuildTempFileToLaunchRemoteContainer()
838 * Else rely on distant configuration. Command is under the form (example):
839 * ssh user@machine distantPath/runRemote.sh hostNS portNS WORKINGDIR workingdir \
840 * SALOME_Container containerName &"
842 * - where user is ommited if not specified in CatalogResources,
843 * - where distant path is always relative to user@machine $HOME, and
844 * equal to $APPLI if not specified in CatalogResources,
845 * - where hostNS is the hostname of CORBA naming server (set by scripts to
846 * use to launch SALOME and servers in $APPLI: runAppli.sh, runRemote.sh)
847 * - where portNS is the port used by CORBA naming server (set by scripts to
848 * use to launch SALOME and servers in $APPLI: runAppli.sh, runRemote.sh)
849 * - where workingdir is the requested working directory for the container.
850 * If WORKINGDIR (and workingdir) is not present the working dir will be $HOME
852 //=============================================================================
855 SALOME_ContainerManager::BuildCommandToLaunchRemoteContainer
856 (const string& machine,
857 const Engines::MachineParameters& params, const std::string& container_exe)
862 if ( ! _isAppliSalomeDefined )
863 command = BuildTempFileToLaunchRemoteContainer(machine, params);
867 const ParserResourcesType& resInfo = _ResManager->GetImpl()->GetResourcesList(machine);
871 if ( (params.nb_node <= 0) && (params.nb_proc_per_node <= 0) )
873 else if ( params.nb_node == 0 )
874 nbproc = params.nb_proc_per_node;
875 else if ( params.nb_proc_per_node == 0 )
876 nbproc = params.nb_node;
878 nbproc = params.nb_node * params.nb_proc_per_node;
881 // "ssh user@machine distantPath/runRemote.sh hostNS portNS WORKINGDIR workingdir \
882 // SALOME_Container containerName &"
884 if (resInfo.Protocol == rsh)
886 else if (resInfo.Protocol == ssh)
889 throw SALOME_Exception("Unknown protocol");
891 if (resInfo.UserName != "")
893 command += resInfo.UserName;
900 if (resInfo.AppliPath != "")
901 command += resInfo.AppliPath; // path relative to user@machine $HOME
904 ASSERT(getenv("APPLI"));
905 command += getenv("APPLI"); // path relative to user@machine $HOME
908 command += "/runRemote.sh ";
910 ASSERT(getenv("NSHOST"));
911 command += getenv("NSHOST"); // hostname of CORBA name server
914 ASSERT(getenv("NSPORT"));
915 command += getenv("NSPORT"); // port of CORBA name server
917 std::string wdir=params.workingdir.in();
920 command += " WORKINGDIR ";
922 if(wdir == "$TEMPDIR")
924 command += wdir; // requested working directory
930 command += " mpirun -np ";
931 std::ostringstream o;
935 command += "-x PATH,LD_LIBRARY_PATH,OMNIORB_CONFIG,SALOME_trace ";
936 #elif defined(WITHOPENMPI)
937 if( getenv("OMPI_URI_FILE") == NULL )
938 command += "-x PATH -x LD_LIBRARY_PATH -x OMNIORB_CONFIG -x SALOME_trace";
940 command += "-x PATH -x LD_LIBRARY_PATH -x OMNIORB_CONFIG -x SALOME_trace -ompi-server file:";
941 command += getenv("OMPI_URI_FILE");
944 command += " SALOME_MPIContainer ";
947 command += " " +container_exe+ " ";
949 command += _NS->ContainerName(params);
951 AddOmninamesParams(command);
953 MESSAGE("command =" << command);
959 //=============================================================================
961 * builds the command to be launched.
963 //=============================================================================
966 SALOME_ContainerManager::BuildCommandToLaunchLocalContainer
967 (const Engines::MachineParameters& params, const std::string& container_exe)
969 _TmpFileName = BuildTemporaryFileName();
973 ofstream command_file( _TmpFileName.c_str() );
977 //command = "mpirun -np ";
978 command_file << "mpirun -np ";
980 if ( (params.nb_node <= 0) && (params.nb_proc_per_node <= 0) )
982 else if ( params.nb_node == 0 )
983 nbproc = params.nb_proc_per_node;
984 else if ( params.nb_proc_per_node == 0 )
985 nbproc = params.nb_node;
987 nbproc = params.nb_node * params.nb_proc_per_node;
989 //std::ostringstream o;
991 //o << nbproc << " ";
992 command_file << nbproc << " ";
994 //command += o.str();
996 //command += "-x PATH,LD_LIBRARY_PATH,OMNIORB_CONFIG,SALOME_trace ";
997 command_file << "-x PATH,LD_LIBRARY_PATH,OMNIORB_CONFIG,SALOME_trace ";
998 #elif defined(WITHOPENMPI)
999 //command += "-x PATH -x LD_LIBRARY_PATH -x OMNIORB_CONFIG -x SALOME_trace ";
1000 if( getenv("OMPI_URI_FILE") == NULL )
1001 command_file << "-x PATH -x LD_LIBRARY_PATH -x OMNIORB_CONFIG -x SALOME_trace";
1004 command_file << "-x PATH -x LD_LIBRARY_PATH -x OMNIORB_CONFIG -x SALOME_trace -ompi-server file:";
1005 command_file << getenv("OMPI_URI_FILE");
1009 if (isPythonContainer(params.container_name))
1010 //command += "pyMPI SALOME_ContainerPy.py ";
1011 command_file << " pyMPI SALOME_ContainerPy.py ";
1013 //command += "SALOME_MPIContainer ";
1014 command_file << " SALOME_MPIContainer ";
1020 std::string wdir=params.workingdir.in();
1023 // a working directory is requested
1024 if(wdir == "$TEMPDIR")
1026 // a new temporary directory is requested
1027 string dir = Kernel_Utils::GetTmpDir();
1029 //command += "cd /d "+ dir +";";
1030 command_file << "cd /d " << dir << endl;
1032 //command = "cd "+ dir +";";
1033 command_file << "cd " << dir << ";";
1039 // a permanent directory is requested use it or create it
1041 //command="mkdir " + wdir;
1042 command_file << "mkdir " + wdir << endl;
1043 command_file << "cd /D " + wdir << endl;
1045 //command="mkdir -p " + wdir + " && cd " + wdir + ";";
1046 command_file << "mkdir -p " << wdir << " && cd " << wdir + ";";
1050 if (isPythonContainer(params.container_name))
1051 //command += "SALOME_ContainerPy.py ";
1052 command_file << "SALOME_ContainerPy.py ";
1054 //command += container_exe + " ";
1055 command_file << container_exe + " ";
1059 command_file << _NS->ContainerName(params);
1060 command_file << " -";
1061 AddOmninamesParams(command_file);
1062 command_file.close();
1065 chmod(_TmpFileName.c_str(), 0x1ED);
1067 command = _TmpFileName;
1069 MESSAGE("Command is file ... " << command);
1074 //=============================================================================
1076 * removes the generated temporary file in case of a remote launch.
1078 //=============================================================================
1080 void SALOME_ContainerManager::RmTmpFile(std::string& tmpFileName)
1082 int lenght = tmpFileName.size();
1086 string command = "del /F ";
1088 string command = "rm ";
1091 command += tmpFileName.substr(0, lenght - 3 );
1093 command += tmpFileName;
1095 system(command.c_str());
1096 //if dir is empty - remove it
1097 string tmp_dir = Kernel_Utils::GetDirByPath( tmpFileName );
1098 if ( Kernel_Utils::IsEmptyDir( tmp_dir ) )
1101 command = "del /F " + tmp_dir;
1103 command = "rmdir " + tmp_dir;
1105 system(command.c_str());
1110 //=============================================================================
1112 * add to command all options relative to naming service.
1114 //=============================================================================
1116 void SALOME_ContainerManager::AddOmninamesParams(string& command) const
1118 CORBA::String_var iorstr = _NS->getIORaddr();
1119 command += "ORBInitRef NameService=";
1124 //=============================================================================
1126 * add to command all options relative to naming service.
1128 //=============================================================================
1130 void SALOME_ContainerManager::AddOmninamesParams(ofstream& fileStream) const
1132 CORBA::String_var iorstr = _NS->getIORaddr();
1133 fileStream << "ORBInitRef NameService=";
1134 fileStream << iorstr;
1137 //=============================================================================
1139 * generate a file name in /tmp directory
1141 //=============================================================================
1143 string SALOME_ContainerManager::BuildTemporaryFileName() const
1145 //build more complex file name to support multiple salome session
1146 string aFileName = Kernel_Utils::GetTmpFileName();
1150 aFileName += ".bat";
1156 //=============================================================================
1158 * Builds in a temporary file the script to be launched.
1160 * Used if SALOME Application ($APPLI) is not defined.
1161 * The command is build with data from CatalogResources, in which every path
1162 * used on remote computer must be defined.
1164 //=============================================================================
1167 SALOME_ContainerManager::BuildTempFileToLaunchRemoteContainer
1168 (const string& machine,
1169 const Engines::MachineParameters& params) throw(SALOME_Exception)
1173 _TmpFileName = BuildTemporaryFileName();
1174 ofstream tempOutputFile;
1175 tempOutputFile.open(_TmpFileName.c_str(), ofstream::out );
1176 const ParserResourcesType& resInfo = _ResManager->GetImpl()->GetResourcesList(machine);
1177 tempOutputFile << "#! /bin/sh" << endl;
1181 tempOutputFile << "export SALOME_trace=local" << endl; // mkr : 27.11.2006 : PAL13967 - Distributed supervision graphs - Problem with "SALOME_trace"
1182 //tempOutputFile << "source " << resInfo.PreReqFilePath << endl;
1188 tempOutputFile << "mpirun -np ";
1191 if ( (params.nb_node <= 0) && (params.nb_proc_per_node <= 0) )
1193 else if ( params.nb_node == 0 )
1194 nbproc = params.nb_proc_per_node;
1195 else if ( params.nb_proc_per_node == 0 )
1196 nbproc = params.nb_node;
1198 nbproc = params.nb_node * params.nb_proc_per_node;
1200 std::ostringstream o;
1202 tempOutputFile << nbproc << " ";
1204 tempOutputFile << "-x PATH,LD_LIBRARY_PATH,OMNIORB_CONFIG,SALOME_trace ";
1205 #elif defined(WITHOPENMPI)
1206 if( getenv("OMPI_URI_FILE") == NULL )
1207 tempOutputFile << "-x PATH -x LD_LIBRARY_PATH -x OMNIORB_CONFIG -x SALOME_trace";
1209 tempOutputFile << "-x PATH -x LD_LIBRARY_PATH -x OMNIORB_CONFIG -x SALOME_trace -ompi-server file:";
1210 tempOutputFile << getenv("OMPI_URI_FILE");
1215 tempOutputFile << getenv("KERNEL_ROOT_DIR") << "/bin/salome/";
1219 if (isPythonContainer(params.container_name))
1220 tempOutputFile << " pyMPI SALOME_ContainerPy.py ";
1222 tempOutputFile << " SALOME_MPIContainer ";
1227 if (isPythonContainer(params.container_name))
1228 tempOutputFile << "SALOME_ContainerPy.py ";
1230 tempOutputFile << "SALOME_Container ";
1233 tempOutputFile << _NS->ContainerName(params) << " -";
1234 AddOmninamesParams(tempOutputFile);
1235 tempOutputFile << " &" << endl;
1236 tempOutputFile.flush();
1237 tempOutputFile.close();
1239 chmod(_TmpFileName.c_str(), 0x1ED);
1242 // --- Build command
1246 if (resInfo.Protocol == rsh)
1249 string commandRcp = "rcp ";
1250 commandRcp += _TmpFileName;
1252 commandRcp += machine;
1254 commandRcp += _TmpFileName;
1255 status = system(commandRcp.c_str());
1258 else if (resInfo.Protocol == ssh)
1261 string commandRcp = "scp ";
1262 commandRcp += _TmpFileName;
1264 commandRcp += machine;
1266 commandRcp += _TmpFileName;
1267 status = system(commandRcp.c_str());
1270 throw SALOME_Exception("Unknown protocol");
1273 throw SALOME_Exception("Error of connection on remote host");
1276 _CommandForRemAccess = command;
1278 command += _TmpFileName;
1286 //=============================================================================
1287 /*! Creates a command line that the container manager uses to launch
1288 * a parallel container.
1290 //=============================================================================
1292 SALOME_ContainerManager::BuildCommandToLaunchParallelContainer(const std::string& exe_name,
1293 const Engines::MachineParameters& params,
1294 SALOME_ContainerManager::actual_launch_machine_t & vect_machine,
1295 const std::string proxy_hostname)
1297 // This method knows the differences between the proxy and the nodes.
1298 // nb_component_nodes is not used in the same way if it is a proxy or
1301 //command = "gdb --args ";
1302 //command = "valgrind --tool=memcheck --log-file=val_log ";
1303 //command += real_exe_name;
1305 // Step 0 : init some variables...
1306 std::string parallelLib(CORBA::string_dup(params.parallelLib));
1307 std::string real_exe_name = exe_name + parallelLib;
1308 std::string machine_file_name("");
1309 bool remote = false;
1310 bool is_a_proxy = false;
1311 std::string hostname(CORBA::string_dup(params.hostname));
1313 std::ostringstream tmp_string;
1314 CORBA::Long nb_nodes = params.nb_component_nodes;
1315 tmp_string << nb_nodes;
1316 std::string nbproc = tmp_string.str();
1318 Engines::MachineParameters_var rtn = new Engines::MachineParameters();
1319 rtn->container_name = params.container_name;
1320 rtn->hostname = params.hostname;
1321 rtn->OS = params.OS;
1322 rtn->mem_mb = params.mem_mb;
1323 rtn->cpu_clock = params.cpu_clock;
1324 rtn->nb_proc_per_node = params.nb_proc_per_node;
1325 rtn->nb_node = params.nb_node;
1326 rtn->isMPI = params.isMPI;
1328 // Step 1 : local or remote launch ?
1329 if (hostname != std::string(Kernel_Utils::GetHostname()) )
1331 MESSAGE("[BuildCommandToLaunchParallelContainer] remote machine case detected !");
1335 // Step 2 : proxy or nodes launch ?
1336 std::string::size_type loc_proxy = exe_name.find("Proxy");
1337 if( loc_proxy != string::npos ) {
1341 // Step 3 : Depending of the parallelLib, getting the machine file
1342 // ParallelLib Dummy has is own machine for this method
1347 machine_file_name = _ResManager->getMachineFile(hostname,
1353 machine_file_name = _ResManager->getMachineFile(hostname,
1354 params.nb_component_nodes,
1357 if (machine_file_name == "")
1359 INFOS("[BuildCommandToLaunchParallelContainer] Error machine_file was not generated for machine " << hostname);
1360 throw SALOME_Exception("Error machine_file was not generated");
1362 MESSAGE("[BuildCommandToLaunchParallelContainer] machine_file_name is : " << machine_file_name);
1365 // Step 4 : Log type choosen by the user
1366 std::string log_env("");
1367 char * get_val = getenv("PARALLEL_LOG");
1370 std::string command_begin("");
1371 std::string command_end("");
1372 if(log_env == "xterm")
1374 command_begin = "/usr/X11R6/bin/xterm -e \"export LD_LIBRARY_PATH=$LD_LIBRARY_PATH; export PATH=$PATH;";
1375 command_end = "\"&";
1377 else if(log_env == "xterm_debug")
1379 command_begin = "/usr/X11R6/bin/xterm -e \"export LD_LIBRARY_PATH=$LD_LIBRARY_PATH; export PATH=$PATH;";
1380 command_end = "; cat \" &";
1384 // default into a file...
1385 std::string logFilename = "/tmp/" + _NS->ContainerName(params) + "_" + hostname;
1387 logFilename += "_Proxy_";
1389 logFilename += "_Node_";
1390 logFilename += std::string(getenv("USER")) + ".log";
1391 command_end = " > " + logFilename + " 2>&1 & ";
1394 // Step 5 : Building the command
1395 std::string command("");
1396 if (parallelLib == "Dummy")
1400 std::string command_remote("");
1403 std::string machine_name;
1404 std::ifstream machine_file(machine_file_name.c_str());
1405 std::getline(machine_file, machine_name);
1406 MESSAGE("[BuildCommandToLaunchParallelContainer] machine file name extracted is " << machine_name)
1408 // We want to launch a command like :
1409 // ssh user@machine distantPath/runRemote.sh hostNS portNS
1410 const ParserResourcesType& resInfo = _ResManager->GetImpl()->GetResourcesList(machine_name);
1411 if (resInfo.Protocol == rsh)
1412 command_remote = "rsh ";
1414 command_remote = "ssh ";
1415 command_remote += resInfo.UserName;
1416 command_remote += "@";
1417 command_remote += machine_name;
1418 command_remote += " ";
1419 command_remote += resInfo.AppliPath; // path relative to user@machine $HOME
1420 command_remote += "/runRemote.sh ";
1421 ASSERT(getenv("NSHOST"));
1422 command_remote += getenv("NSHOST"); // hostname of CORBA name server
1423 command_remote += " ";
1424 ASSERT(getenv("NSPORT"));
1425 command_remote += getenv("NSPORT"); // port of CORBA name server
1426 command_remote += " ";
1428 hostname = machine_name;
1431 command = real_exe_name;
1432 command += " " + _NS->ContainerName(rtn);
1433 command += " " + parallelLib;
1434 command += " " + hostname;
1435 command += " " + nbproc;
1437 AddOmninamesParams(command);
1439 command = command_begin + command_remote + command + command_end;
1440 vect_machine.push_back(hostname);
1444 std::ifstream * machine_file = NULL;
1446 machine_file = new std::ifstream(machine_file_name.c_str());
1447 for (int i= 0; i < nb_nodes; i++)
1449 std::string command_remote("");
1452 std::string machine_name;
1453 std::getline(*machine_file, machine_name);
1454 MESSAGE("[BuildCommandToLaunchParallelContainer] machine file name extracted is " << machine_name)
1456 // We want to launch a command like :
1457 // ssh user@machine distantPath/runRemote.sh hostNS portNS
1458 const ParserResourcesType& resInfo = _ResManager->GetImpl()->GetResourcesList(machine_name);
1459 if (resInfo.Protocol == rsh)
1460 command_remote = "rsh ";
1462 command_remote = "ssh ";
1463 command_remote += resInfo.UserName;
1464 command_remote += "@";
1465 command_remote += machine_name;
1466 command_remote += " ";
1467 command_remote += resInfo.AppliPath; // path relative to user@machine $HOME
1468 command_remote += "/runRemote.sh ";
1469 ASSERT(getenv("NSHOST"));
1470 command_remote += getenv("NSHOST"); // hostname of CORBA name server
1471 command_remote += " ";
1472 ASSERT(getenv("NSPORT"));
1473 command_remote += getenv("NSPORT"); // port of CORBA name server
1474 command_remote += " ";
1476 hostname = machine_name;
1479 std::ostringstream tmp;
1481 std::string proc_number = tmp.str();
1483 std::string command_tmp("");
1484 command_tmp += real_exe_name;
1485 command_tmp += " " + _NS->ContainerName(rtn);
1486 command_tmp += " " + parallelLib;
1487 command_tmp += " " + proxy_hostname;
1488 command_tmp += " " + proc_number;
1489 command_tmp += " -";
1490 AddOmninamesParams(command_tmp);
1492 // On change _Node_ par _Nodex_ pour avoir chaque noeud
1494 std::string command_end_tmp = command_end;
1495 std::string::size_type loc_node = command_end_tmp.find("_Node_");
1496 if (loc_node != std::string::npos)
1497 command_end_tmp.insert(loc_node+5, proc_number);
1498 command += command_begin + command_remote + command_tmp + command_end_tmp;
1499 vect_machine.push_back(hostname);
1502 delete machine_file;
1505 else if (parallelLib == "Mpi")
1507 // Step 0: if remote we have to copy the file
1508 // to the first machine of the file
1509 std::string remote_machine("");
1512 std::ifstream * machine_file = NULL;
1513 machine_file = new std::ifstream(machine_file_name.c_str());
1514 // Get first word of the line
1515 // For MPI implementation the first word is the
1517 std::getline(*machine_file, remote_machine, ' ');
1518 machine_file->close();
1519 MESSAGE("[BuildCommandToLaunchParallelContainer] machine file name extracted is " << remote_machine)
1521 // We want to launch a command like :
1522 // scp mpi_machine_file user@machine:Path
1523 std::string command_remote("");
1524 const ParserResourcesType& resInfo = _ResManager->GetImpl()->GetResourcesList(remote_machine);
1525 if (resInfo.Protocol == rsh)
1526 command_remote = "rcp ";
1528 command_remote = "scp ";
1530 command_remote += machine_file_name;
1531 command_remote += " ";
1532 command_remote += resInfo.UserName;
1533 command_remote += "@";
1534 command_remote += remote_machine;
1535 command_remote += ":";
1536 command_remote += machine_file_name;
1538 int status = system(command_remote.c_str());
1541 INFOS("copy of the mpi machine file failed !");
1548 std::string command_remote("");
1551 // We want to launch a command like :
1552 // ssh user@machine distantPath/runRemote.sh hostNS portNS
1553 const ParserResourcesType& resInfo = _ResManager->GetImpl()->GetResourcesList(remote_machine);
1554 if (resInfo.Protocol == rsh)
1555 command_remote = "rsh ";
1557 command_remote = "ssh ";
1558 command_remote += resInfo.UserName;
1559 command_remote += "@";
1560 command_remote += remote_machine;
1561 command_remote += " ";
1562 command_remote += resInfo.AppliPath; // path relative to user@machine $HOME
1563 command_remote += "/runRemote.sh ";
1564 ASSERT(getenv("NSHOST"));
1565 command_remote += getenv("NSHOST"); // hostname of CORBA name server
1566 command_remote += " ";
1567 ASSERT(getenv("NSPORT"));
1568 command_remote += getenv("NSPORT"); // port of CORBA name server
1569 command_remote += " ";
1571 hostname = remote_machine;
1574 // We use Dummy proxy for MPI parallel containers
1575 real_exe_name = exe_name + "Dummy";
1576 command = real_exe_name;
1577 command += " " + _NS->ContainerName(rtn);
1578 command += " Dummy";
1579 command += " " + hostname;
1580 command += " " + nbproc;
1582 AddOmninamesParams(command);
1584 command = command_begin + command_remote + command + command_end;
1585 vect_machine.push_back(hostname);
1589 std::string command_remote("");
1592 const ParserResourcesType& resInfo = _ResManager->GetImpl()->GetResourcesList(remote_machine);
1593 if (resInfo.Protocol == rsh)
1594 command_remote = "rsh ";
1596 command_remote = "ssh ";
1597 command_remote += resInfo.UserName;
1598 command_remote += "@";
1599 command_remote += remote_machine;
1600 command_remote += " ";
1602 std::string new_real_exe_name("");
1603 new_real_exe_name += resInfo.AppliPath; // path relative to user@machine $HOME
1604 new_real_exe_name += "/runRemote.sh ";
1605 ASSERT(getenv("NSHOST"));
1606 new_real_exe_name += getenv("NSHOST"); // hostname of CORBA name server
1607 new_real_exe_name += " ";
1608 ASSERT(getenv("NSPORT"));
1609 new_real_exe_name += getenv("NSPORT"); // port of CORBA name server
1610 new_real_exe_name += " ";
1612 real_exe_name = new_real_exe_name + real_exe_name;
1613 hostname = remote_machine;
1616 const ParserResourcesType& resInfo = _ResManager->GetImpl()->GetResourcesList(hostname);
1617 if (resInfo.mpi == lam)
1619 command = "mpiexec -ssi boot ";
1620 if (resInfo.Protocol == rsh)
1624 command += "-machinefile " + machine_file_name + " ";
1625 command += "-n " + nbproc + " ";
1626 command += real_exe_name;
1627 command += " " + _NS->ContainerName(rtn);
1628 command += " " + parallelLib;
1629 command += " " + proxy_hostname;
1631 AddOmninamesParams(command);
1635 command = "mpirun -np " + nbproc + " ";
1636 command += real_exe_name;
1637 command += " " + _NS->ContainerName(rtn);
1638 command += " " + parallelLib;
1639 command += " " + proxy_hostname;
1641 AddOmninamesParams(command);
1644 command = command_begin + command_remote + command + command_end;
1645 for (int i= 0; i < nb_nodes; i++)
1646 vect_machine.push_back(proxy_hostname);
1651 std::string message("Unknown parallelLib : " + parallelLib);
1652 throw SALOME_Exception(message.c_str());
1655 MESSAGE("Parallel launch is: " << command);
1659 string SALOME_ContainerManager::GetMPIZeroNode(string machine)
1664 string tmpFile = BuildTemporaryFileName();
1666 cmd = "ssh " + machine + " mpirun -np 1 hostname > " + tmpFile;
1668 status = system(cmd.c_str());
1670 ifstream fp(tmpFile.c_str(),ios::in);