1 // Copyright (C) 2007-2012 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 #include "SALOME_ContainerManager.hxx"
24 #include "SALOME_NamingService.hxx"
25 #include "SALOME_ModuleCatalog.hh"
26 #include "Basics_Utils.hxx"
27 #include "Basics_DirUtils.hxx"
28 #include <sys/types.h>
35 #include "Utils_CorbaException.hxx"
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 Engines::ResourceList_var possibleResources = _ResManager->GetFittingResources(local_params.resource_params);
301 MESSAGE("[GiveContainer] - length of possible resources " << possibleResources->length());
302 std::vector<std::string> local_resources;
304 // Step 3: if mode is "get" keep only machines with existing containers
307 for(unsigned int i=0; i < possibleResources->length(); i++)
309 Engines::Container_ptr cont = FindContainer(params, possibleResources[i].in());
312 if(!cont->_non_existent())
313 local_resources.push_back(std::string(possibleResources[i]));
315 catch(CORBA::Exception&) {}
318 // if local_resources is empty, we cannot give a container
319 if (local_resources.size() == 0)
321 MESSAGE("[GiveContainer] cannot find a container for mode get");
326 for(unsigned int i=0; i < possibleResources->length(); i++)
327 local_resources.push_back(std::string(possibleResources[i]));
329 // Step 4: select the resource where to get/start the container
330 bool resource_available = true;
331 std::string resource_selected;
332 std::vector<std::string> resources = local_resources;
333 while (resource_available)
335 if (resources.size() == 0)
336 resource_available = false;
341 resource_selected = _ResManager->GetImpl()->Find(params.resource_params.policy.in(), resources);
342 // Remove resource_selected from vector
343 std::vector<std::string>::iterator it;
344 for (it=resources.begin() ; it < resources.end(); it++ )
345 if (*it == resource_selected)
351 catch(const SALOME_Exception &ex)
353 MESSAGE("[GiveContainer] Exception in ResourceManager find !: " << ex.what());
356 MESSAGE("[GiveContainer] Resource selected is: " << resource_selected);
358 // Step 5: Create container name
359 Engines::ResourceDefinition_var resource_definition = _ResManager->GetResourceDefinition(resource_selected.c_str());
360 std::string hostname(resource_definition->hostname.in());
361 std::string containerNameInNS;
364 if ( params.nb_proc <= 0 )
367 nbproc = params.nb_proc;
370 if( getenv("LIBBATCH_NODEFILE") != NULL )
371 machFile = machinesFile(nbproc);
373 catch(const SALOME_Exception & ex)
375 std::string err_msg = ex.what();
376 err_msg += params.container_name;
377 INFOS(err_msg.c_str());
380 // A mpi parallel container register on zero node in NS
381 containerNameInNS = _NS->BuildContainerNameForNS(params, GetMPIZeroNode(hostname,machFile).c_str());
384 containerNameInNS = _NS->BuildContainerNameForNS(params, hostname.c_str());
385 MESSAGE("[GiveContainer] Container name in the naming service: " << containerNameInNS);
387 // Step 6: check if the name exists in naming service
388 //if params.mode == "getorstart" or "get" use the existing container
389 //if params.mode == "start" shutdown the existing container before launching a new one with that name
390 CORBA::Object_var obj = _NS->Resolve(containerNameInNS.c_str());
391 if (!CORBA::is_nil(obj))
395 Engines::Container_var cont=Engines::Container::_narrow(obj);
396 if(!cont->_non_existent())
398 if(std::string(params.mode.in())=="getorstart" || std::string(params.mode.in())=="get"){
399 return cont._retn(); /* the container exists and params.mode is getorstart or get use it*/
403 INFOS("[GiveContainer] A container is already registered with the name: " << containerNameInNS << ", shutdown the existing container");
404 cont->Shutdown(); // shutdown the registered container if it exists
408 catch(CORBA::Exception&)
410 INFOS("[GiveContainer] CORBA::Exception ignored when trying to get the container - we start a new one");
413 Engines::Container_var cont = LaunchContainer(params, resource_selected, hostname, machFile, containerNameInNS);
414 if (!CORBA::is_nil(cont))
416 INFOS("[GiveContainer] container " << containerNameInNS << " launched");
421 INFOS("[GiveContainer] Failed to launch container on resource " << resource_selected);
426 // We were not able to launch the container
427 INFOS("[GiveContainer] Cannot launch the container on the following selected resources:")
428 std::vector<std::string>::iterator it;
429 for (it=local_resources.begin() ; it < local_resources.end(); it++ )
430 INFOS("[GiveContainer] " << *it)
434 Engines::Container_ptr
435 SALOME_ContainerManager::LaunchContainer(const Engines::ContainerParameters& params,
436 const std::string & resource_selected,
437 const std::string & hostname,
438 const std::string & machFile,
439 const std::string & containerNameInNS)
442 // Step 1: type of container: PaCO, Exe, Mpi or Classic
443 // Mpi already tested in step 5, specific code on BuildCommandToLaunch Local/Remote Container methods
444 // TODO -> separates Mpi from Classic/Exe
446 std::string container_exe = "SALOME_Container"; // Classic container
447 Engines::ContainerParameters local_params(params);
448 Engines::Container_ptr ret = Engines::Container::_nil();
452 CORBA::String_var container_exe_tmp;
453 CORBA::Object_var obj = _NS->Resolve("/Kernel/ModulCatalog");
454 SALOME_ModuleCatalog::ModuleCatalog_var Catalog = SALOME_ModuleCatalog::ModuleCatalog::_narrow(obj) ;
455 if (CORBA::is_nil (Catalog))
457 INFOS("[GiveContainer] Module Catalog is not found -> cannot launch a container");
460 // Loop through component list
461 for(unsigned int i=0; i < local_params.resource_params.componentList.length(); i++)
463 const char* compoi = local_params.resource_params.componentList[i];
464 SALOME_ModuleCatalog::Acomponent_var compoInfo = Catalog->GetComponent(compoi);
465 if (CORBA::is_nil (compoInfo))
469 SALOME_ModuleCatalog::ImplType impl=compoInfo->implementation_type();
470 container_exe_tmp=compoInfo->implementation_name();
471 if(impl==SALOME_ModuleCatalog::CEXE)
475 INFOS("ContainerManager Error: you can't have 2 CEXE component in the same container" );
476 return Engines::Container::_nil();
478 MESSAGE("[GiveContainer] Exe container found !: " << container_exe_tmp);
479 container_exe = container_exe_tmp.in();
484 catch (ServiceUnreachable&)
486 INFOS("Caught exception: Naming Service Unreachable");
491 INFOS("Caught unknown exception.");
495 // Step 2: test resource
496 // Only if an application directory is set
497 if(hostname != Kernel_Utils::GetHostname() && _isAppliSalomeDefined)
499 // Preparing remote command
500 std::string command = "";
501 const ParserResourcesType& resInfo = _ResManager->GetImpl()->GetResourcesDescr(resource_selected);
502 command = getCommandToRunRemoteProcess(resInfo.Protocol, resInfo.HostName, resInfo.UserName);
503 if (resInfo.AppliPath != "")
504 command += resInfo.AppliPath;
507 ASSERT(getenv("APPLI"));
508 command += getenv("APPLI");
510 command += "/runRemote.sh ";
511 ASSERT(getenv("NSHOST"));
512 command += getenv("NSHOST"); // hostname of CORBA name server
514 ASSERT(getenv("NSPORT"));
515 command += getenv("NSPORT"); // port of CORBA name server
516 command += " ls /tmp";
518 // Launch remote command
519 int status = system(command.c_str());
522 // Error on resource - cannot launch commands
523 INFOS("[LaunchContainer] Cannot launch commands on machine " << hostname);
524 INFOS("[LaunchContainer] Command was " << command);
526 INFOS("[LaunchContainer] Command status is " << WEXITSTATUS(status));
528 return Engines::Container::_nil();
532 // Step 3: start a new container
533 // Check if a PaCO container
535 if (std::string(local_params.parallelLib.in()) != "")
537 ret = StartPaCOPPContainer(params, resource_selected);
540 // Other type of containers...
541 MESSAGE("[GiveContainer] Try to launch a new container on " << resource_selected);
543 // if a parallel container is launched in batch job, command is: "mpirun -np nbproc -machinefile nodesfile SALOME_MPIContainer"
544 if( getenv("LIBBATCH_NODEFILE") != NULL && params.isMPI )
545 command = BuildCommandToLaunchLocalContainer(params, machFile, container_exe);
546 // if a container is launched on localhost, command is "SALOME_Container" or "mpirun -np nbproc SALOME_MPIContainer"
547 else if(hostname == Kernel_Utils::GetHostname())
548 command = BuildCommandToLaunchLocalContainer(params, machFile, container_exe);
549 // if a container is launched in remote mode, command is "ssh resource_selected SALOME_Container" or "ssh resource_selected mpirun -np nbproc SALOME_MPIContainer"
551 command = BuildCommandToLaunchRemoteContainer(resource_selected, params, container_exe);
553 //redirect stdout and stderr in a file
555 std::string logFilename=getenv("TEMP");
557 std::string user = getenv( "USERNAME" );
559 std::string user = getenv( "USER" );
560 std::string logFilename="/tmp";
561 char* val = getenv("SALOME_TMP_DIR");
564 struct stat file_info;
565 stat(val, &file_info);
566 bool is_dir = S_ISDIR(file_info.st_mode);
567 if (is_dir)logFilename=val;
568 else std::cerr << "SALOME_TMP_DIR environment variable is not a directory use /tmp instead" << std::endl;
572 logFilename += _NS->ContainerName(params)+"_"+ resource_selected +"_"+user;
573 std::ostringstream tmp;
574 tmp << "_" << getpid();
575 logFilename += tmp.str();
576 logFilename += ".log" ;
577 command += " > " + logFilename + " 2>&1";
579 command = "%PYTHONBIN% -c \"import win32pm ; win32pm.spawnpid(r'" + command + "', '')\"";
584 // launch container with a system call
585 int status=system(command.c_str());
588 INFOS("[LaunchContainer] command failed (system command status -1): " << command);
589 RmTmpFile(_TmpFileName); // command file can be removed here
591 return Engines::Container::_nil();
593 else if (status == 217){
594 INFOS("[LaunchContainer] command failed (system command status 217): " << command);
595 RmTmpFile(_TmpFileName); // command file can be removed here
597 return Engines::Container::_nil();
601 // Step 4: Wait for the container
602 int count = TIME_OUT_TO_LAUNCH_CONT;
603 if (getenv("TIMEOUT_TO_LAUNCH_CONTAINER") != 0)
605 std::string new_count_str = getenv("TIMEOUT_TO_LAUNCH_CONTAINER");
607 std::istringstream ss(new_count_str);
608 if (!(ss >> new_count))
610 INFOS("[LaunchContainer] TIMEOUT_TO_LAUNCH_CONTAINER should be an int");
615 INFOS("[GiveContainer] waiting " << count << " second steps container " << containerNameInNS);
616 while (CORBA::is_nil(ret) && count)
624 MESSAGE("[GiveContainer] step " << count << " Waiting for container on " << resource_selected);
625 CORBA::Object_var obj = _NS->Resolve(containerNameInNS.c_str());
626 ret=Engines::Container::_narrow(obj);
628 if (CORBA::is_nil(ret))
630 INFOS("[GiveContainer] was not able to launch container " << containerNameInNS);
634 // Setting log file name
635 logFilename=":"+logFilename;
636 logFilename="@"+Kernel_Utils::GetHostname()+logFilename;
637 logFilename=user+logFilename;
638 ret->logfilename(logFilename.c_str());
639 RmTmpFile(_TmpFileName); // command file can be removed here
646 //=============================================================================
647 //! Find a container given constraints (params) on a list of machines (possibleComputers)
651 //=============================================================================
653 Engines::Container_ptr
654 SALOME_ContainerManager::FindContainer(const Engines::ContainerParameters& params,
655 const Engines::ResourceList& possibleResources)
657 MESSAGE("[FindContainer] FindContainer on " << possibleResources.length() << " resources");
658 for(unsigned int i=0; i < possibleResources.length();i++)
660 Engines::Container_ptr cont = FindContainer(params, possibleResources[i].in());
661 if(!CORBA::is_nil(cont))
664 MESSAGE("[FindContainer] no container found");
665 return Engines::Container::_nil();
668 //=============================================================================
669 //! Find a container given constraints (params) on a machine (theMachine)
673 //=============================================================================
675 Engines::Container_ptr
676 SALOME_ContainerManager::FindContainer(const Engines::ContainerParameters& params,
677 const std::string& resource)
679 Engines::ResourceDefinition_var resource_definition = _ResManager->GetResourceDefinition(resource.c_str());
680 std::string hostname(resource_definition->hostname.in());
681 std::string containerNameInNS(_NS->BuildContainerNameForNS(params, hostname.c_str()));
682 MESSAGE("[FindContainer] Try to find a container " << containerNameInNS << " on resource " << resource);
683 CORBA::Object_var obj = _NS->Resolve(containerNameInNS.c_str());
686 if(obj->_non_existent())
687 return Engines::Container::_nil();
689 return Engines::Container::_narrow(obj);
691 catch(const CORBA::Exception& e)
693 return Engines::Container::_nil();
698 bool isPythonContainer(const char* ContainerName);
700 //=============================================================================
702 * This is no longer valid (C++ container are also python containers)
704 //=============================================================================
705 bool isPythonContainer(const char* ContainerName)
708 int len = strlen(ContainerName);
711 if (strcmp(ContainerName + len - 2, "Py") == 0)
717 //=============================================================================
719 * Builds the script to be launched
721 * If SALOME Application not defined ($APPLI),
722 * see BuildTempFileToLaunchRemoteContainer()
724 * Else rely on distant configuration. Command is under the form (example):
725 * ssh user@machine distantPath/runRemote.sh hostNS portNS WORKINGDIR workingdir \
726 * SALOME_Container containerName &"
728 * - where user is ommited if not specified in CatalogResources,
729 * - where distant path is always relative to user@machine $HOME, and
730 * equal to $APPLI if not specified in CatalogResources,
731 * - where hostNS is the hostname of CORBA naming server (set by scripts to
732 * use to launch SALOME and servers in $APPLI: runAppli.sh, runRemote.sh)
733 * - where portNS is the port used by CORBA naming server (set by scripts to
734 * use to launch SALOME and servers in $APPLI: runAppli.sh, runRemote.sh)
735 * - where workingdir is the requested working directory for the container.
736 * If WORKINGDIR (and workingdir) is not present the working dir will be $HOME
738 //=============================================================================
741 SALOME_ContainerManager::BuildCommandToLaunchRemoteContainer
742 (const std::string& resource_name,
743 const Engines::ContainerParameters& params, const std::string& container_exe)
747 if (!_isAppliSalomeDefined)
748 command = BuildTempFileToLaunchRemoteContainer(resource_name, params);
752 Engines::ResourceDefinition_var resource_definition = _ResManager->GetResourceDefinition(resource_name.c_str());
753 std::string hostname(resource_definition->hostname.in());
754 const ParserResourcesType& resInfo = _ResManager->GetImpl()->GetResourcesDescr(resource_name);
758 if ( params.nb_proc <= 0 )
761 nbproc = params.nb_proc;
764 // "ssh -l user machine distantPath/runRemote.sh hostNS portNS WORKINGDIR workingdir \
765 // SALOME_Container containerName &"
766 command = getCommandToRunRemoteProcess(resInfo.Protocol, resInfo.HostName, resInfo.UserName);
768 if (resInfo.AppliPath != "")
769 command += resInfo.AppliPath; // path relative to user@machine $HOME
772 ASSERT(getenv("APPLI"));
773 command += getenv("APPLI"); // path relative to user@machine $HOME
776 command += "/runRemote.sh ";
778 ASSERT(getenv("NSHOST"));
779 command += getenv("NSHOST"); // hostname of CORBA name server
782 ASSERT(getenv("NSPORT"));
783 command += getenv("NSPORT"); // port of CORBA name server
785 std::string wdir = params.workingdir.in();
788 command += " WORKINGDIR ";
790 if(wdir == "$TEMPDIR")
792 command += wdir; // requested working directory
798 command += " mpirun -np ";
799 std::ostringstream o;
803 command += "-x PATH,LD_LIBRARY_PATH,OMNIORB_CONFIG,SALOME_trace ";
804 #elif defined(WITHOPENMPI)
805 if( getenv("OMPI_URI_FILE") == NULL )
806 command += "-x PATH -x LD_LIBRARY_PATH -x OMNIORB_CONFIG -x SALOME_trace";
808 command += "-x PATH -x LD_LIBRARY_PATH -x OMNIORB_CONFIG -x SALOME_trace -ompi-server file:";
809 command += getenv("OMPI_URI_FILE");
811 #elif defined(WITHMPICH)
812 command += "-nameserver " + Kernel_Utils::GetHostname();
814 command += " SALOME_MPIContainer ";
817 command += " " +container_exe+ " ";
819 command += _NS->ContainerName(params);
821 AddOmninamesParams(command);
823 MESSAGE("command =" << command);
829 //=============================================================================
831 * builds the command to be launched.
833 //=============================================================================
835 SALOME_ContainerManager::BuildCommandToLaunchLocalContainer
836 (const Engines::ContainerParameters& params, const std::string& machinesFile, const std::string& container_exe)
838 _TmpFileName = BuildTemporaryFileName();
842 std::ostringstream o;
848 if ( params.nb_proc <= 0 )
851 nbproc = params.nb_proc;
855 if( getenv("LIBBATCH_NODEFILE") != NULL )
856 o << "-machinefile " << machinesFile << " ";
859 o << "-x PATH,LD_LIBRARY_PATH,OMNIORB_CONFIG,SALOME_trace ";
860 #elif defined(WITHOPENMPI)
861 if( getenv("OMPI_URI_FILE") == NULL )
862 o << "-x PATH -x LD_LIBRARY_PATH -x OMNIORB_CONFIG -x SALOME_trace";
865 o << "-x PATH -x LD_LIBRARY_PATH -x OMNIORB_CONFIG -x SALOME_trace -ompi-server file:";
866 o << getenv("OMPI_URI_FILE");
868 #elif defined(WITHMPICH)
869 o << "-nameserver " + Kernel_Utils::GetHostname();
872 if (isPythonContainer(params.container_name))
873 o << " pyMPI SALOME_ContainerPy.py ";
875 o << " SALOME_MPIContainer ";
880 std::string wdir=params.workingdir.in();
883 // a working directory is requested
884 if(wdir == "$TEMPDIR")
886 // a new temporary directory is requested
887 std::string dir = Kernel_Utils::GetTmpDir();
889 o << "cd /d " << dir << std::endl;
891 o << "cd " << dir << ";";
897 // a permanent directory is requested use it or create it
899 o << "mkdir " + wdir << std::endl;
900 o << "cd /D " + wdir << std::endl;
902 o << "mkdir -p " << wdir << " && cd " << wdir + ";";
907 if (isPythonContainer(params.container_name))
908 o << "SALOME_ContainerPy.py ";
910 o << container_exe + " ";
914 o << _NS->ContainerName(params);
916 AddOmninamesParams(o);
918 std::ofstream command_file( _TmpFileName.c_str() );
919 command_file << o.str();
920 command_file.close();
923 chmod(_TmpFileName.c_str(), 0x1ED);
925 command = _TmpFileName;
927 MESSAGE("Command is file ... " << command);
928 MESSAGE("Command is ... " << o.str());
933 //=============================================================================
935 * removes the generated temporary file in case of a remote launch.
937 //=============================================================================
939 void SALOME_ContainerManager::RmTmpFile(std::string& tmpFileName)
941 int lenght = tmpFileName.size();
945 std::string command = "del /F ";
947 std::string command = "rm ";
950 command += tmpFileName.substr(0, lenght - 3 );
952 command += tmpFileName;
954 system(command.c_str());
955 //if dir is empty - remove it
956 std::string tmp_dir = Kernel_Utils::GetDirByPath( tmpFileName );
957 if ( Kernel_Utils::IsEmptyDir( tmp_dir ) )
960 command = "del /F " + tmp_dir;
962 command = "rmdir " + tmp_dir;
964 system(command.c_str());
969 //=============================================================================
971 * add to command all options relative to naming service.
973 //=============================================================================
975 void SALOME_ContainerManager::AddOmninamesParams(std::string& command) const
977 CORBA::String_var iorstr = _NS->getIORaddr();
978 command += "ORBInitRef NameService=";
982 //=============================================================================
984 * add to command all options relative to naming service.
986 //=============================================================================
988 void SALOME_ContainerManager::AddOmninamesParams(std::ofstream& fileStream) const
990 CORBA::String_var iorstr = _NS->getIORaddr();
991 fileStream << "ORBInitRef NameService=";
992 fileStream << iorstr;
995 //=============================================================================
997 * add to command all options relative to naming service.
999 //=============================================================================
1001 void SALOME_ContainerManager::AddOmninamesParams(std::ostringstream& oss) const
1003 CORBA::String_var iorstr = _NS->getIORaddr();
1004 oss << "ORBInitRef NameService=";
1008 //=============================================================================
1010 * generate a file name in /tmp directory
1012 //=============================================================================
1014 std::string SALOME_ContainerManager::BuildTemporaryFileName() const
1016 //build more complex file name to support multiple salome session
1017 std::string aFileName = Kernel_Utils::GetTmpFileName();
1021 aFileName += ".bat";
1026 //=============================================================================
1028 * Builds in a temporary file the script to be launched.
1030 * Used if SALOME Application ($APPLI) is not defined.
1031 * The command is build with data from CatalogResources, in which every path
1032 * used on remote computer must be defined.
1034 //=============================================================================
1037 SALOME_ContainerManager::BuildTempFileToLaunchRemoteContainer
1038 (const std::string& resource_name,
1039 const Engines::ContainerParameters& params) throw(SALOME_Exception)
1043 _TmpFileName = BuildTemporaryFileName();
1044 std::ofstream tempOutputFile;
1045 tempOutputFile.open(_TmpFileName.c_str(), std::ofstream::out );
1046 const ParserResourcesType& resInfo = _ResManager->GetImpl()->GetResourcesDescr(resource_name);
1047 tempOutputFile << "#! /bin/sh" << std::endl;
1051 tempOutputFile << "export SALOME_trace=local" << std::endl; // mkr : 27.11.2006 : PAL13967 - Distributed supervision graphs - Problem with "SALOME_trace"
1052 //tempOutputFile << "source " << resInfo.PreReqFilePath << endl;
1058 tempOutputFile << "mpirun -np ";
1061 if ( params.nb_proc <= 0 )
1064 nbproc = params.nb_proc;
1066 std::ostringstream o;
1068 tempOutputFile << nbproc << " ";
1070 tempOutputFile << "-x PATH,LD_LIBRARY_PATH,OMNIORB_CONFIG,SALOME_trace ";
1071 #elif defined(WITHOPENMPI)
1072 if( getenv("OMPI_URI_FILE") == NULL )
1073 tempOutputFile << "-x PATH -x LD_LIBRARY_PATH -x OMNIORB_CONFIG -x SALOME_trace";
1075 tempOutputFile << "-x PATH -x LD_LIBRARY_PATH -x OMNIORB_CONFIG -x SALOME_trace -ompi-server file:";
1076 tempOutputFile << getenv("OMPI_URI_FILE");
1078 #elif defined(WITHMPICH)
1079 tempOutputFile << "-nameserver " + Kernel_Utils::GetHostname();
1083 tempOutputFile << getenv("KERNEL_ROOT_DIR") << "/bin/salome/";
1087 if (isPythonContainer(params.container_name))
1088 tempOutputFile << " pyMPI SALOME_ContainerPy.py ";
1090 tempOutputFile << " SALOME_MPIContainer ";
1095 if (isPythonContainer(params.container_name))
1096 tempOutputFile << "SALOME_ContainerPy.py ";
1098 tempOutputFile << "SALOME_Container ";
1101 tempOutputFile << _NS->ContainerName(params) << " -";
1102 AddOmninamesParams(tempOutputFile);
1103 tempOutputFile << " &" << std::endl;
1104 tempOutputFile.flush();
1105 tempOutputFile.close();
1107 chmod(_TmpFileName.c_str(), 0x1ED);
1110 // --- Build command
1112 std::string command;
1114 if (resInfo.Protocol == rsh)
1117 std::string commandRcp = "rcp ";
1118 commandRcp += _TmpFileName;
1120 commandRcp += resInfo.HostName;
1122 commandRcp += _TmpFileName;
1123 status = system(commandRcp.c_str());
1126 else if (resInfo.Protocol == ssh)
1129 std::string commandRcp = "scp ";
1130 commandRcp += _TmpFileName;
1132 commandRcp += resInfo.HostName;
1134 commandRcp += _TmpFileName;
1135 status = system(commandRcp.c_str());
1138 else if (resInfo.Protocol == srun)
1140 command = "srun -n 1 -N 1 --share --nodelist=";
1141 std::string commandRcp = "rcp ";
1142 commandRcp += _TmpFileName;
1144 commandRcp += resInfo.HostName;
1146 commandRcp += _TmpFileName;
1147 status = system(commandRcp.c_str());
1150 throw SALOME_Exception("Unknown protocol");
1153 throw SALOME_Exception("Error of connection on remote host");
1155 command += resInfo.HostName;
1156 _CommandForRemAccess = command;
1158 command += _TmpFileName;
1166 std::string SALOME_ContainerManager::GetMPIZeroNode(const std::string machine, const std::string machinesFile)
1169 std::string zeronode;
1170 std::string command;
1171 std::string tmpFile = BuildTemporaryFileName();
1173 if( getenv("LIBBATCH_NODEFILE") == NULL )
1175 if (_isAppliSalomeDefined)
1177 const ParserResourcesType& resInfo = _ResManager->GetImpl()->GetResourcesDescr(machine);
1179 if (resInfo.Protocol == rsh)
1181 else if (resInfo.Protocol == ssh)
1183 else if (resInfo.Protocol == srun)
1184 command = "srun -n 1 -N 1 --share --nodelist=";
1186 throw SALOME_Exception("Unknown protocol");
1188 if (resInfo.UserName != "")
1191 command += resInfo.UserName;
1195 command += resInfo.HostName;
1198 if (resInfo.AppliPath != "")
1199 command += resInfo.AppliPath; // path relative to user@machine $HOME
1202 ASSERT(getenv("APPLI"));
1203 command += getenv("APPLI"); // path relative to user@machine $HOME
1206 command += "/runRemote.sh ";
1208 ASSERT(getenv("NSHOST"));
1209 command += getenv("NSHOST"); // hostname of CORBA name server
1212 ASSERT(getenv("NSPORT"));
1213 command += getenv("NSPORT"); // port of CORBA name server
1215 command += " mpirun -np 1 hostname -s > " + tmpFile;
1218 command = "mpirun -np 1 hostname -s > " + tmpFile;
1221 command = "mpirun -np 1 -machinefile " + machinesFile + " hostname -s > " + tmpFile;
1223 status = system(command.c_str());
1225 std::ifstream fp(tmpFile.c_str(),std::ios::in);
1226 while(fp >> zeronode);
1234 std::string SALOME_ContainerManager::machinesFile(const int nbproc)
1237 std::string nodesFile = getenv("LIBBATCH_NODEFILE");
1238 std::string machinesFile = Kernel_Utils::GetTmpFileName();
1239 std::ifstream fpi(nodesFile.c_str(),std::ios::in);
1240 std::ofstream fpo(machinesFile.c_str(),std::ios::out);
1242 _numInstanceMutex.lock();
1244 for(int i=0;i<_nbprocUsed;i++)
1247 for(int i=0;i<nbproc;i++)
1249 fpo << tmp << std::endl;
1251 throw SALOME_Exception("You need more processors than batch session have allocated for you! Unable to launch the mpi container: ");
1253 _nbprocUsed += nbproc;
1257 _numInstanceMutex.unlock();
1259 return machinesFile;
1263 std::set<pid_t> SALOME_ContainerManager::getpidofprogram(const std::string program)
1265 std::set<pid_t> thepids;
1266 std::string tmpFile = Kernel_Utils::GetTmpFileName();
1269 cmd = "pidof " + program + " > " + tmpFile;
1270 system(cmd.c_str());
1271 std::ifstream fpi(tmpFile.c_str(),std::ios::in);
1272 while(fpi >> thepid){
1273 thepids.insert(atoi(thepid.c_str()));
1278 std::string SALOME_ContainerManager::getCommandToRunRemoteProcess(AccessProtocolType protocol,
1279 const std::string & hostname,
1280 const std::string & username)
1282 std::ostringstream command;
1289 command << "-l " << username << " ";
1291 command << hostname << " ";
1297 command << "-l " << username << " ";
1299 command << hostname << " ";
1302 // no need to redefine the user with srun, the job user is taken by default
1303 // (note: for srun, user id can be specified with " --uid=<user>")
1304 command << "srun -n 1 -N 1 --share --nodelist=" << hostname << " ";
1307 command << "pbsdsh -o -h " << hostname << " ";
1310 command << "blaunch " << hostname << " ";
1313 throw SALOME_Exception("Unknown protocol");
1316 return command.str();
1320 SALOME_ContainerManager::checkPaCOParameters(Engines::ContainerParameters & params, std::string resource_selected)
1324 // Step 1 : check ContainerParameters
1325 // Check container_name, has to be defined
1326 if (std::string(params.container_name.in()) == "")
1328 INFOS("[checkPaCOParameters] You must define a container_name to launch a PaCO++ container");
1331 // Check parallelLib
1332 std::string parallelLib = params.parallelLib.in();
1333 if (parallelLib != "Mpi" && parallelLib != "Dummy")
1335 INFOS("[checkPaCOParameters] parallelLib is not correctly defined");
1336 INFOS("[checkPaCOParameters] you can chosse between: Mpi and Dummy");
1337 INFOS("[checkPaCOParameters] you entered: " << parallelLib);
1341 if (params.nb_proc <= 0)
1343 INFOS("[checkPaCOParameters] You must define a nb_proc > 0");
1347 // Step 2 : check resource_selected
1348 Engines::ResourceDefinition_var resource_definition = _ResManager->GetResourceDefinition(resource_selected.c_str());
1349 std::string protocol = resource_definition->protocol.in();
1350 std::string username = resource_definition->username.in();
1351 std::string applipath = resource_definition->applipath.in();
1353 if (protocol == "" || username == "" || applipath == "")
1355 INFOS("[checkPaCOParameters] resource selected is not well defined");
1356 INFOS("[checkPaCOParameters] resource name: " << resource_definition->name.in());
1357 INFOS("[checkPaCOParameters] resource hostname: " << resource_definition->hostname.in());
1358 INFOS("[checkPaCOParameters] resource protocol: " << protocol);
1359 INFOS("[checkPaCOParameters] resource username: " << username);
1360 INFOS("[checkPaCOParameters] resource applipath: " << applipath);
1366 #ifdef WITH_PACO_PARALLEL
1368 //=============================================================================
1370 * Start a suitable PaCO++ Parallel Container in a list of machines.
1371 * \param params Container Parameters required for the container
1372 * \return CORBA container reference.
1374 //=============================================================================
1375 Engines::Container_ptr
1376 SALOME_ContainerManager::StartPaCOPPContainer(const Engines::ContainerParameters& params_const,
1377 std::string resource_selected)
1379 CORBA::Object_var obj;
1380 PaCO::InterfaceManager_var container_proxy;
1381 Engines::Container_ptr ret = Engines::Container::_nil();
1382 Engines::ContainerParameters params(params_const);
1383 params.resource_params.name = CORBA::string_dup(resource_selected.c_str());
1385 // Step 0 : Check parameters
1386 if (!checkPaCOParameters(params, resource_selected))
1388 INFOS("[StartPaCOPPContainer] check parameters failed ! see logs...");
1392 // Step 1 : Starting a new parallel container !
1393 INFOS("[StartPaCOPPContainer] Starting a PaCO++ parallel container");
1394 INFOS("[StartPaCOPPContainer] on resource : " << resource_selected);
1396 // Step 2 : Get a MachineFile for the parallel container
1397 std::string machine_file_name = _ResManager->getMachineFile(resource_selected,
1399 params.parallelLib.in());
1401 if (machine_file_name == "")
1403 INFOS("[StartPaCOPPContainer] Machine file generation failed");
1407 // Step 3 : starting parallel container proxy
1408 std::string command_proxy("");
1409 std::string proxy_machine;
1412 command_proxy = BuildCommandToLaunchPaCOProxyContainer(params, machine_file_name, proxy_machine);
1414 catch(const SALOME_Exception & ex)
1416 INFOS("[StartPaCOPPContainer] Exception in BuildCommandToLaunchPaCOContainer");
1420 obj = LaunchPaCOProxyContainer(command_proxy, params, proxy_machine);
1421 if (CORBA::is_nil(obj))
1423 INFOS("[StartPaCOPPContainer] LaunchPaCOContainer for proxy returns NIL !");
1426 container_proxy = PaCO::InterfaceManager::_narrow(obj);
1427 MESSAGE("[StartPaCOPPContainer] PaCO container proxy is launched");
1429 // Step 4 : starting parallel container nodes
1430 std::string command_nodes("");
1431 SALOME_ContainerManager::actual_launch_machine_t nodes_machines;
1434 command_nodes = BuildCommandToLaunchPaCONodeContainer(params, machine_file_name, nodes_machines, proxy_machine);
1436 catch(const SALOME_Exception & ex)
1438 INFOS("[StarPaCOPPContainer] Exception in BuildCommandToLaunchPaCONodeContainer");
1443 std::string container_generic_node_name = std::string(params.container_name.in()) + std::string("Node");
1444 bool result = LaunchPaCONodeContainer(command_nodes, params, container_generic_node_name, nodes_machines);
1447 INFOS("[StarPaCOPPContainer] LaunchPaCONodeContainer failed !");
1448 // Il faut tuer le proxy
1451 Engines::Container_var proxy = Engines::Container::_narrow(container_proxy);
1456 INFOS("[StarPaCOPPContainer] Exception catched from proxy Shutdown...");
1461 // Step 4 : connecting nodes and the proxy to actually create a parallel container
1462 for (int i = 0; i < params.nb_proc; i++)
1464 std::ostringstream tmp;
1466 std::string proc_number = tmp.str();
1467 std::string container_node_name = container_generic_node_name + proc_number;
1469 std::string theNodeMachine(nodes_machines[i]);
1470 std::string containerNameInNS = _NS->BuildContainerNameForNS(container_node_name.c_str(), theNodeMachine.c_str());
1471 obj = _NS->Resolve(containerNameInNS.c_str());
1472 if (CORBA::is_nil(obj))
1474 INFOS("[StarPaCOPPContainer] CONNECTION FAILED From Naming Service !");
1475 INFOS("[StarPaCOPPContainer] Container name is " << containerNameInNS);
1480 MESSAGE("[StarPaCOPPContainer] Deploying node : " << container_node_name);
1481 PaCO::InterfaceParallel_var node = PaCO::InterfaceParallel::_narrow(obj);
1483 MESSAGE("[StarPaCOPPContainer] node " << container_node_name << " is deployed");
1485 catch(CORBA::SystemException& e)
1487 INFOS("[StarPaCOPPContainer] Exception in deploying node : " << containerNameInNS);
1488 INFOS("CORBA::SystemException : " << e);
1491 catch(CORBA::Exception& e)
1493 INFOS("[StarPaCOPPContainer] Exception in deploying node : " << containerNameInNS);
1494 INFOS("CORBA::Exception" << e);
1499 INFOS("[StarPaCOPPContainer] Exception in deploying node : " << containerNameInNS);
1500 INFOS("Unknown exception !");
1505 // Step 5 : starting parallel container
1508 MESSAGE ("[StarPaCOPPContainer] Starting parallel object");
1509 container_proxy->start();
1510 MESSAGE ("[StarPaCOPPContainer] Parallel object is started");
1511 ret = Engines::Container::_narrow(container_proxy);
1513 catch(CORBA::SystemException& e)
1515 INFOS("Caught CORBA::SystemException. : " << e);
1517 catch(PortableServer::POA::ServantAlreadyActive&)
1519 INFOS("Caught CORBA::ServantAlreadyActiveException");
1521 catch(CORBA::Exception&)
1523 INFOS("Caught CORBA::Exception.");
1525 catch(std::exception& exc)
1527 INFOS("Caught std::exception - "<<exc.what());
1531 INFOS("Caught unknown exception.");
1537 SALOME_ContainerManager::BuildCommandToLaunchPaCOProxyContainer(const Engines::ContainerParameters& params,
1538 std::string machine_file_name,
1539 std::string & proxy_hostname)
1541 // In the proxy case, we always launch a Dummy Proxy
1542 std::string exe_name = "SALOME_ParallelContainerProxyDummy";
1543 std::string container_name = params.container_name.in();
1545 // Convert nb_proc in string
1546 std::ostringstream tmp_string;
1547 tmp_string << params.nb_proc;
1548 std::string nb_proc_str = tmp_string.str();
1550 // Get resource definition
1551 Engines::ResourceDefinition_var resource_definition =
1552 _ResManager->GetResourceDefinition(params.resource_params.name);
1555 std::string hostname;
1556 std::ifstream machine_file(machine_file_name.c_str());
1557 std::getline(machine_file, hostname, ' ');
1558 size_t found = hostname.find('\n');
1559 if (found!=std::string::npos)
1560 hostname.erase(found, 1); // Remove \n
1561 proxy_hostname = hostname;
1562 MESSAGE("[BuildCommandToLaunchPaCOProxyContainer] machine file name extracted is " << hostname);
1565 bool remote_execution = false;
1566 if (hostname != std::string(Kernel_Utils::GetHostname()))
1568 MESSAGE("[BuildCommandToLaunchPaCOProxyContainer] remote machine case detected !");
1569 remote_execution = true;
1572 // Log environnement
1573 std::string log_type("");
1574 char * get_val = getenv("PARALLEL_LOG");
1578 // Generating the command
1579 std::string command_begin("");
1580 std::string command_end("");
1581 std::ostringstream command;
1583 LogConfiguration(log_type, "proxy", container_name, hostname, command_begin, command_end);
1584 command << command_begin;
1586 // Adding connection command
1587 // We can only have a remote execution with
1588 // a SALOME application
1589 if (remote_execution)
1591 ASSERT(getenv("NSHOST"));
1592 ASSERT(getenv("NSPORT"));
1594 command << resource_definition->protocol.in();
1596 command << resource_definition->username.in();
1597 command << " " << hostname;
1598 command << " " << resource_definition->applipath.in();
1599 command << "/runRemote.sh ";
1600 command << getenv("NSHOST") << " "; // hostname of CORBA name server
1601 command << getenv("NSPORT") << " "; // port of CORBA name server
1604 command << exe_name;
1605 command << " " << container_name;
1606 command << " Dummy";
1607 command << " " << hostname;
1608 command << " " << nb_proc_str;
1610 AddOmninamesParams(command);
1613 command << command_end;
1614 MESSAGE("[BuildCommandToLaunchPaCOProxyContainer] Command is: " << command.str());
1616 return command.str();
1620 SALOME_ContainerManager::BuildCommandToLaunchPaCONodeContainer(const Engines::ContainerParameters& params,
1621 const std::string & machine_file_name,
1622 SALOME_ContainerManager::actual_launch_machine_t & vect_machine,
1623 const std::string & proxy_hostname)
1626 std::string exe_name = "SALOME_ParallelContainerNode";
1627 exe_name += params.parallelLib.in();
1628 std::string container_name = params.container_name.in();
1630 // Convert nb_proc in string
1631 std::ostringstream nb_proc_stream;
1632 nb_proc_stream << params.nb_proc;
1634 // Get resource definition
1635 Engines::ResourceDefinition_var resource_definition =
1636 _ResManager->GetResourceDefinition(params.resource_params.name);
1638 // Log environnement
1639 std::string log_type("");
1640 char * get_val = getenv("PARALLEL_LOG");
1644 // Now the command is different according to paralleLib
1645 std::ostringstream command_nodes;
1646 std::ifstream machine_file(machine_file_name.c_str());
1647 if (std::string(params.parallelLib.in()) == "Dummy")
1649 for (int i= 0; i < params.nb_proc; i++)
1652 std::string hostname;
1653 std::getline(machine_file, hostname);
1654 MESSAGE("[BuildCommandToLaunchPaCONodeContainer] machine file name extracted is " << hostname);
1657 bool remote_execution = false;
1658 if (hostname != std::string(Kernel_Utils::GetHostname()))
1660 MESSAGE("[BuildCommandToLaunchPaCONodeContainer] remote machine case detected !");
1661 remote_execution = true;
1664 // For each node we have a new command
1665 // Generating the command
1666 std::ostringstream command_node_stream;
1667 std::string command_node_begin("");
1668 std::string command_node_end("");
1669 std::ostringstream node_number;
1671 std::string container_node_name = container_name + node_number.str();
1672 LogConfiguration(log_type, "node", container_node_name, hostname, command_node_begin, command_node_end);
1674 // Adding connection command
1675 // We can only have a remote execution with
1676 // a SALOME application
1677 if (remote_execution)
1679 ASSERT(getenv("NSHOST"));
1680 ASSERT(getenv("NSPORT"));
1682 command_node_stream << resource_definition->protocol.in();
1683 command_node_stream << " -l ";
1684 command_node_stream << resource_definition->username.in();
1685 command_node_stream << " " << hostname;
1686 command_node_stream << " " << resource_definition->applipath.in();
1687 command_node_stream << "/runRemote.sh ";
1688 command_node_stream << getenv("NSHOST") << " "; // hostname of CORBA name server
1689 command_node_stream << getenv("NSPORT") << " "; // port of CORBA name server
1692 command_node_stream << exe_name;
1693 command_node_stream << " " << container_name;
1694 command_node_stream << " " << params.parallelLib.in();
1695 command_node_stream << " " << proxy_hostname;
1696 command_node_stream << " " << node_number.str();
1697 command_node_stream << " -";
1698 AddOmninamesParams(command_node_stream);
1700 command_nodes << command_node_begin << command_node_stream.str() << command_node_end;
1701 vect_machine.push_back(hostname);
1705 else if (std::string(params.parallelLib.in()) == "Mpi")
1708 std::string hostname;
1709 std::getline(machine_file, hostname, ' ');
1710 MESSAGE("[BuildCommandToLaunchPaCONodeContainer] machine file name extracted is " << hostname);
1713 bool remote_execution = false;
1714 if (hostname != std::string(Kernel_Utils::GetHostname()))
1716 MESSAGE("[BuildCommandToLaunchPaCONodeContainer] remote machine case detected !");
1717 remote_execution = true;
1720 // In case of Mpi and Remote, we copy machine_file in the applipath
1721 // scp mpi_machine_file user@machine:Path
1722 std::ostringstream command_remote_stream;
1723 std::string::size_type last = machine_file_name.find_last_of("/");
1724 if (last == std::string::npos)
1727 std::string protocol = resource_definition->protocol.in();
1728 if (protocol == "rsh")
1729 command_remote_stream << "rcp ";
1731 command_remote_stream << "scp ";
1732 command_remote_stream << machine_file_name << " ";
1733 command_remote_stream << resource_definition->username.in() << "@";
1734 command_remote_stream << hostname << ":" << resource_definition->applipath.in();
1735 command_remote_stream << "/" << machine_file_name.substr(last+1);
1737 int status = system(command_remote_stream.str().c_str());
1740 INFOS("copy of the MPI machine file failed ! - sorry !");
1744 // Generating the command
1745 std::string command_begin("");
1746 std::string command_end("");
1748 LogConfiguration(log_type, "nodes", container_name, hostname, command_begin, command_end);
1749 command_nodes << command_begin;
1751 // Adding connection command
1752 // We can only have a remote execution with
1753 // a SALOME application
1754 if (remote_execution)
1756 ASSERT(getenv("NSHOST"));
1757 ASSERT(getenv("NSPORT"));
1759 command_nodes << resource_definition->protocol.in();
1760 command_nodes << " -l ";
1761 command_nodes << resource_definition->username.in();
1762 command_nodes << " " << hostname;
1763 command_nodes << " " << resource_definition->applipath.in();
1764 command_nodes << "/runRemote.sh ";
1765 command_nodes << getenv("NSHOST") << " "; // hostname of CORBA name server
1766 command_nodes << getenv("NSPORT") << " "; // port of CORBA name server
1769 if (std::string(resource_definition->mpiImpl.in()) == "lam")
1771 command_nodes << "mpiexec -ssi boot ";
1772 command_nodes << "-machinefile " << machine_file_name << " ";
1773 command_nodes << "-n " << params.nb_proc;
1777 command_nodes << "mpirun -np " << params.nb_proc;
1779 command_nodes << " " << exe_name;
1780 command_nodes << " " << container_name;
1781 command_nodes << " " << params.parallelLib.in();
1782 command_nodes << " " << proxy_hostname;
1783 command_nodes << " -";
1784 AddOmninamesParams(command_nodes);
1786 // We don't put hostname, because nodes are registered in the resource of the proxy
1787 for (int i= 0; i < params.nb_proc; i++)
1788 vect_machine.push_back(proxy_hostname);
1790 command_nodes << command_end;
1792 return command_nodes.str();
1796 SALOME_ContainerManager::LogConfiguration(const std::string & log_type,
1797 const std::string & exe_type,
1798 const std::string & container_name,
1799 const std::string & hostname,
1800 std::string & begin,
1803 if(log_type == "xterm")
1805 begin = "xterm -e \"export LD_LIBRARY_PATH=$LD_LIBRARY_PATH; export PATH=$PATH;";
1808 else if(log_type == "xterm_debug")
1810 begin = "xterm -e \"export LD_LIBRARY_PATH=$LD_LIBRARY_PATH; export PATH=$PATH;";
1815 // default into a file...
1816 std::string logFilename = "/tmp/" + container_name + "_" + hostname + "_" + exe_type + "_";
1817 logFilename += std::string(getenv("USER")) + ".log";
1818 end = " > " + logFilename + " 2>&1 & ";
1823 SALOME_ContainerManager::LaunchPaCOProxyContainer(const std::string& command,
1824 const Engines::ContainerParameters& params,
1825 const std::string & hostname)
1827 PaCO::InterfaceManager_ptr container_proxy = PaCO::InterfaceManager::_nil();
1829 MESSAGE("[LaunchPaCOProxyContainer] Launch command");
1830 int status = system(command.c_str());
1832 INFOS("[LaunchPaCOProxyContainer] failed : system command status -1");
1833 return container_proxy;
1835 else if (status == 217) {
1836 INFOS("[LaunchPaCOProxyContainer] failed : system command status 217");
1837 return container_proxy;
1840 int count = TIME_OUT_TO_LAUNCH_CONT;
1841 CORBA::Object_var obj = CORBA::Object::_nil();
1842 std::string containerNameInNS = _NS->BuildContainerNameForNS(params.container_name.in(),
1844 MESSAGE("[LaunchParallelContainer] Waiting for Parallel Container proxy : " << containerNameInNS);
1846 while (CORBA::is_nil(obj) && count)
1850 obj = _NS->Resolve(containerNameInNS.c_str());
1855 container_proxy = PaCO::InterfaceManager::_narrow(obj);
1857 catch(CORBA::SystemException& e)
1859 INFOS("[StarPaCOPPContainer] Exception in _narrow after LaunchParallelContainer for proxy !");
1860 INFOS("CORBA::SystemException : " << e);
1861 return container_proxy;
1863 catch(CORBA::Exception& e)
1865 INFOS("[StarPaCOPPContainer] Exception in _narrow after LaunchParallelContainer for proxy !");
1866 INFOS("CORBA::Exception" << e);
1867 return container_proxy;
1871 INFOS("[StarPaCOPPContainer] Exception in _narrow after LaunchParallelContainer for proxy !");
1872 INFOS("Unknown exception !");
1873 return container_proxy;
1875 if (CORBA::is_nil(container_proxy))
1877 INFOS("[StarPaCOPPContainer] PaCO::InterfaceManager::_narrow returns NIL !");
1878 return container_proxy;
1883 //=============================================================================
1884 /*! This method launches the parallel container.
1885 * It will may be placed on the ressources manager.
1887 * \param command to launch
1888 * \param container's parameters
1889 * \param name of the container
1891 * \return CORBA container reference
1893 //=============================================================================
1895 SALOME_ContainerManager::LaunchPaCONodeContainer(const std::string& command,
1896 const Engines::ContainerParameters& params,
1897 const std::string& name,
1898 SALOME_ContainerManager::actual_launch_machine_t & vect_machine)
1900 INFOS("[LaunchPaCONodeContainer] Launch command");
1901 int status = system(command.c_str());
1903 INFOS("[LaunchPaCONodeContainer] failed : system command status -1");
1906 else if (status == 217) {
1907 INFOS("[LaunchPaCONodeContainer] failed : system command status 217");
1911 INFOS("[LaunchPaCONodeContainer] Waiting for the nodes of the parallel container");
1912 // We are waiting all the nodes
1913 for (int i = 0; i < params.nb_proc; i++)
1915 CORBA::Object_var obj = CORBA::Object::_nil();
1916 std::string theMachine(vect_machine[i]);
1918 std::ostringstream tmp;
1920 std::string proc_number = tmp.str();
1921 std::string container_node_name = name + proc_number;
1922 std::string containerNameInNS = _NS->BuildContainerNameForNS((char*) container_node_name.c_str(), theMachine.c_str());
1923 INFOS("[LaunchPaCONodeContainer] Waiting for Parallel Container node " << containerNameInNS << " on " << theMachine);
1924 int count = TIME_OUT_TO_LAUNCH_CONT;
1925 while (CORBA::is_nil(obj) && count) {
1928 obj = _NS->Resolve(containerNameInNS.c_str());
1930 if (CORBA::is_nil(obj))
1932 INFOS("[LaunchPaCONodeContainer] Launch of node failed (or not found) !");
1941 Engines::Container_ptr
1942 SALOME_ContainerManager::StartPaCOPPContainer(const Engines::ContainerParameters& params,
1943 std::string resource_selected)
1945 Engines::Container_ptr ret = Engines::Container::_nil();
1946 INFOS("[StarPaCOPPContainer] is disabled !");
1947 INFOS("[StarPaCOPPContainer] recompile SALOME Kernel to enable PaCO++ parallel extension");
1952 SALOME_ContainerManager::BuildCommandToLaunchPaCOProxyContainer(const Engines::ContainerParameters& params,
1953 std::string machine_file_name,
1954 std::string & proxy_hostname)
1960 SALOME_ContainerManager::BuildCommandToLaunchPaCONodeContainer(const Engines::ContainerParameters& params,
1961 const std::string & machine_file_name,
1962 SALOME_ContainerManager::actual_launch_machine_t & vect_machine,
1963 const std::string & proxy_hostname)
1968 SALOME_ContainerManager::LogConfiguration(const std::string & log_type,
1969 const std::string & exe_type,
1970 const std::string & container_name,
1971 const std::string & hostname,
1972 std::string & begin,
1978 SALOME_ContainerManager::LaunchPaCOProxyContainer(const std::string& command,
1979 const Engines::ContainerParameters& params,
1980 const std::string& hostname)
1982 CORBA::Object_ptr ret = CORBA::Object::_nil();
1987 SALOME_ContainerManager::LaunchPaCONodeContainer(const std::string& command,
1988 const Engines::ContainerParameters& params,
1989 const std::string& name,
1990 SALOME_ContainerManager::actual_launch_machine_t & vect_machine)