1 // Copyright (C) 2007-2023 CEA, EDF, 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, or (at your option) any later version.
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_ResourcesManager.hxx"
25 #include "SALOME_LoadRateManager.hxx"
26 #include "SALOME_NamingService.hxx"
27 #include "SALOME_ResourcesManager_Client.hxx"
28 #include "SALOME_Embedded_NamingService.hxx"
29 #include "SALOME_ModuleCatalog.hh"
30 #include "Basics_Utils.hxx"
31 #include "Basics_DirUtils.hxx"
32 #include "PythonCppUtils.hxx"
33 #include <sys/types.h>
40 #include "Utils_CorbaException.hxx"
47 #include <SALOMEconfig.h>
48 #include CORBA_CLIENT_HEADER(SALOME_Session)
57 #define getpid _getpid
60 #define S_ISREG(mode) (((mode) & S_IFMT) == S_IFREG)
65 #ifdef WITH_PACO_PARALLEL
69 const int SALOME_ContainerManager::TIME_OUT_TO_LAUNCH_CONT=60;
71 const int SALOME_ContainerManager::DFT_DELTA_TIME_NS_LOOKUP_IN_MS=1000;
73 const char *SALOME_ContainerManager::_ContainerManagerNameInNS = "/ContainerManager";
75 omni_mutex SALOME_ContainerManager::_numInstanceMutex;
77 Utils_Mutex SALOME_ContainerManager::_getenvMutex;
79 Utils_Mutex SALOME_ContainerManager::_systemMutex;
81 //=============================================================================
85 * Define a CORBA single thread policy for the server, which avoid to deal
86 * with non thread-safe usage like Change_Directory in SALOME naming service
88 //=============================================================================
90 SALOME_ContainerManager::SALOME_ContainerManager(CORBA::ORB_ptr orb, PortableServer::POA_var poa, SALOME_NamingService_Abstract *ns)
91 : _nbprocUsed(1),_delta_time_ns_lookup_in_ms(DFT_DELTA_TIME_NS_LOOKUP_IN_MS)
93 MESSAGE("constructor");
95 _resManager = new SALOME_ResourcesManager_Client(ns);
96 _time_out_in_second = GetTimeOutToLoaunchServer();
98 PortableServer::POAManager_var pman = poa->the_POAManager();
99 _orb = CORBA::ORB::_duplicate(orb) ;
100 CORBA::PolicyList policies;
102 PortableServer::ThreadPolicy_var threadPol(poa->create_thread_policy(PortableServer::ORB_CTRL_MODEL));
103 policies[0] = PortableServer::ThreadPolicy::_duplicate(threadPol);
105 _poa = poa->create_POA("MThreadPOA",pman,policies);
106 threadPol->destroy();
107 PortableServer::ObjectId_var id = _poa->activate_object(this);
108 CORBA::Object_var obj = _poa->id_to_reference(id);
109 Engines::ContainerManager_var refContMan = Engines::ContainerManager::_narrow(obj);
111 _NS->Register(refContMan,_ContainerManagerNameInNS);
112 _isAppliSalomeDefined = (GetenvThreadSafe("APPLI") != 0);
117 // the urifile name depends on pid of the process
118 std::stringstream urifile;
119 urifile << GetenvThreadSafeAsString("HOME") << "/.urifile_" << getpid();
120 setenv("OMPI_URI_FILE",urifile.str().c_str(),1);
121 if( GetenvThreadSafe("OMPI_URI_FILE") != NULL ){
122 // Linux specific code
123 pid_t pid = fork(); // spawn a child process, following code is executed in both processes
124 if ( pid == 0 ) // I'm a child, replace myself with a new ompi-server
126 std::string uriarg = GetenvThreadSafeAsString("OMPI_URI_FILE");
127 execlp( "ompi-server", "ompi-server", "-r", uriarg.c_str(), NULL );
128 throw SALOME_Exception("Error when launching ompi-server"); // execlp failed
132 throw SALOME_Exception("fork() failed");
136 //wait(NULL); // wait(?) for a child end
137 _pid_mpiServer = pid;
142 // Linux specific code
143 pid_t pid = fork(); // spawn a child process, following code is executed in both processes
144 if ( pid == 0 ) // I'm a child, replace myself with a new hydra_nameserver
146 execlp( "hydra_nameserver", "hydra_nameserver", NULL );
147 throw SALOME_Exception("Error when launching hydra_nameserver"); // execlp failed
151 throw SALOME_Exception("fork() failed");
156 _pid_mpiServer = pid;
161 MESSAGE("constructor end");
164 //=============================================================================
168 //=============================================================================
170 SALOME_ContainerManager::~SALOME_ContainerManager()
172 MESSAGE("destructor");
176 if( GetenvThreadSafe("OMPI_URI_FILE") != NULL ){
177 // kill my ompi-server
178 if( kill(_pid_mpiServer,SIGTERM) != 0 )
179 throw SALOME_Exception("Error when killing ompi-server");
181 int status=SystemThreadSafe("rm -f ${OMPI_URI_FILE}");
183 throw SALOME_Exception("Error when removing urifile");
186 // kill my hydra_nameserver
187 if(_pid_mpiServer > -1)
188 if( kill(_pid_mpiServer,SIGTERM) != 0 )
189 throw SALOME_Exception("Error when killing hydra_nameserver");
194 //=============================================================================
195 //! shutdown all the containers, then the ContainerManager servant
198 //=============================================================================
200 void SALOME_ContainerManager::Shutdown()
203 ShutdownContainers();
205 _NS->Destroy_Name(_ContainerManagerNameInNS);
206 PortableServer::ObjectId_var oid = _poa->servant_to_id(this);
207 _poa->deactivate_object(oid);
210 CORBA::Long SALOME_ContainerManager::GetTimeOutToLaunchServerInSecond()
212 return this->_time_out_in_second;
215 void SALOME_ContainerManager::SetTimeOutToLaunchServerInSecond(CORBA::Long timeInSecond)
217 this->_time_out_in_second = timeInSecond;
220 CORBA::Long SALOME_ContainerManager::GetDeltaTimeBetweenNSLookupAtLaunchTimeInMilliSecond()
222 return this->_delta_time_ns_lookup_in_ms;
225 void SALOME_ContainerManager::SetDeltaTimeBetweenNSLookupAtLaunchTimeInMilliSecond(CORBA::Long timeInMS)
227 this->_delta_time_ns_lookup_in_ms = timeInMS;
230 //=============================================================================
231 //! Loop on all the containers listed in naming service, ask shutdown on each
234 //=============================================================================
236 void SALOME_ContainerManager::ShutdownContainers()
238 MESSAGE("ShutdownContainers");
241 SALOME::Session_var session = SALOME::Session::_nil();
243 CORBA::Object_var objS = _NS->Resolve("/Kernel/Session");
244 if (!CORBA::is_nil(objS))
246 session = SALOME::Session::_narrow(objS);
247 if (!CORBA::is_nil(session))
248 pid = session->getPID();
252 isOK = _NS->Change_Directory("/Containers");
254 std::vector<std::string> vec = _NS->list_directory_recurs();
255 std::list<std::string> lstCont;
256 for(std::vector<std::string>::iterator iter = vec.begin();iter!=vec.end();iter++)
259 CORBA::Object_var obj=_NS->Resolve((*iter).c_str());
262 Engines::Container_var cont=Engines::Container::_narrow(obj);
263 if(!CORBA::is_nil(cont) && pid != cont->getPID())
264 lstCont.push_back((*iter));
266 catch(const CORBA::Exception&)
268 // ignore this entry and continue
271 MESSAGE("Container list: ");
272 for(std::list<std::string>::iterator iter=lstCont.begin();iter!=lstCont.end();iter++){
275 for(std::list<std::string>::iterator iter=lstCont.begin();iter!=lstCont.end();iter++)
280 CORBA::Object_var obj=_NS->Resolve((*iter).c_str());
281 Engines::Container_var cont=Engines::Container::_narrow(obj);
282 if(!CORBA::is_nil(cont))
284 MESSAGE("ShutdownContainers: " << (*iter));
288 MESSAGE("ShutdownContainers: no container ref for " << (*iter));
290 catch(CORBA::SystemException& e)
292 INFOS("CORBA::SystemException ignored : " << e);
294 catch(CORBA::Exception&)
296 INFOS("CORBA::Exception ignored.");
300 INFOS("Unknown exception ignored.");
306 void SALOME_ContainerManager::SetOverrideEnvForContainers(const Engines::KeyValDict& env)
308 this->_override_env.clear();
309 auto sz = env.length();
310 for(auto i = 0 ; i < sz ; ++i)
311 _override_env.emplace_back(env[i].key.in(), env[i].val.in());
314 Engines::KeyValDict *SALOME_ContainerManager::GetOverrideEnvForContainers()
316 std::unique_ptr<Engines::KeyValDict> ret( new Engines::KeyValDict );
317 auto sz = _override_env.size();
319 for(auto i = 0 ; i < sz ; ++i)
321 (*ret)[i].key = CORBA::string_dup( _override_env[i].first.c_str() );
322 (*ret)[i].val = CORBA::string_dup( _override_env[i].second.c_str() );
324 return ret.release();
327 void SALOME_ContainerManager::SetCodeOnContainerStartUp(const char *code)
329 _code_to_exe_on_startup = code;
332 //=============================================================================
333 //! Give a suitable Container given constraints
335 * \param params Container Parameters required for the container
336 * \return the container or nil
338 //=============================================================================
339 Engines::Container_ptr SALOME_ContainerManager::GiveContainer(const Engines::ContainerParameters& params)
341 std::string machFile;
342 Engines::Container_ptr ret(Engines::Container::_nil());
344 // Step 0: Default mode is start
345 Engines::ContainerParameters local_params(params);
346 if (std::string(local_params.mode.in()) == "")
347 local_params.mode = CORBA::string_dup("start");
348 std::string mode = local_params.mode.in();
349 MESSAGE("[GiveContainer] starting with mode: " << mode);
351 // Step 1: Find Container for find and findorstart mode
352 if (mode == "find" || mode == "findorstart")
354 ret = FindContainer(params, params.resource_params.resList);
355 if(!CORBA::is_nil(ret))
361 MESSAGE("[GiveContainer] no container found");
371 // Step 2: Get all possibleResources from the parameters
372 // Consider only resources that can run containers
373 resourceParams resource_params = resourceParameters_CORBAtoCPP(local_params.resource_params);
374 resource_params.can_run_containers = true;
375 std::vector<std::string> possibleResources = _resManager->GetFittingResources(resource_params);
376 MESSAGE("[GiveContainer] - length of possible resources " << possibleResources.size());
377 std::vector<std::string> local_resources;
379 // Step 3: if mode is "get" keep only machines with existing containers
382 for(unsigned int i=0; i < possibleResources.size(); i++)
384 Engines::Container_ptr cont = FindContainer(params, possibleResources[i]);
387 if(!cont->_non_existent())
388 local_resources.push_back(possibleResources[i]);
390 catch(CORBA::Exception&) {}
393 // if local_resources is empty, we cannot give a container
394 if (local_resources.size() == 0)
396 MESSAGE("[GiveContainer] cannot find a container for mode get");
401 local_resources = possibleResources;
403 // Step 4: select the resource where to get/start the container
404 bool resource_available = true;
405 std::string resource_selected;
406 std::vector<std::string> resources = local_resources;
407 while (resource_available)
409 if (resources.size() == 0)
410 resource_available = false;
415 resource_selected = _resManager->Find(params.resource_params.policy.in(), resources);
416 // Remove resource_selected from vector
417 std::vector<std::string>::iterator it;
418 for (it=resources.begin() ; it < resources.end(); it++ )
419 if (*it == resource_selected)
425 catch(const SALOME_Exception &ex) //!< TODO: unused variable
427 MESSAGE("[GiveContainer] Exception in ResourceManager find !: " << ex.what());
430 MESSAGE("[GiveContainer] Resource selected is: " << resource_selected);
432 // Step 5: Create container name
433 ParserResourcesType resource_definition = _resManager->GetResourceDefinition(resource_selected);
434 std::string hostname(resource_definition.HostName);
435 std::string containerNameInNS;
437 int nbproc = params.nb_proc <= 0 ? 1 : params.nb_proc;
440 if( GetenvThreadSafe("LIBBATCH_NODEFILE") != NULL )
441 machFile = machinesFile(nbproc);
443 catch(const SALOME_Exception & ex)
445 std::string err_msg = ex.what();
446 err_msg += params.container_name;
447 INFOS(err_msg.c_str());
450 // A mpi parallel container register on zero node in NS
451 std::string mpiZeroNode = GetMPIZeroNode(resource_selected,machFile).c_str();
452 containerNameInNS = _NS->BuildContainerNameForNS(params, mpiZeroNode.c_str());
455 containerNameInNS = _NS->BuildContainerNameForNS(params, hostname.c_str());
456 MESSAGE("[GiveContainer] Container name in the naming service: " << containerNameInNS);
458 // Step 6: check if the name exists in naming service
459 //if params.mode == "getorstart" or "get" use the existing container
460 //if params.mode == "start" shutdown the existing container before launching a new one with that name
462 { // critical section
463 Utils_Locker lock (&_giveContainerMutex1);
464 CORBA::Object_var obj = _NS->Resolve(containerNameInNS.c_str());
465 if (!CORBA::is_nil(obj))
469 Engines::Container_var cont=Engines::Container::_narrow(obj);
470 if(!cont->_non_existent())
472 if(std::string(params.mode.in())=="getorstart" || std::string(params.mode.in())=="get"){
473 return cont._retn(); /* the container exists and params.mode is getorstart or get use it*/
477 INFOS("[GiveContainer] A container is already registered with the name: " << containerNameInNS << ", shutdown the existing container");
478 cont->Shutdown(); // shutdown the registered container if it exists
482 catch(CORBA::Exception&)
484 INFOS("[GiveContainer] CORBA::Exception ignored when trying to get the container - we start a new one");
487 } // end critical section
488 Engines::Container_var cont = LaunchContainer(params, resource_selected, hostname, machFile, containerNameInNS);
489 if (!CORBA::is_nil(cont))
491 INFOS("[GiveContainer] container " << containerNameInNS << " launched");
492 std::ostringstream envInfo;
493 std::for_each( _override_env.begin(), _override_env.end(), [&envInfo](const std::pair<std::string,std::string>& p) { envInfo << p.first << " = " << p.second << std::endl; } );
494 INFOS("[GiveContainer] container " << containerNameInNS << " override " << envInfo.str());
495 Engines::FieldsDict envCorba;
497 auto sz = _override_env.size();
499 for(auto i = 0 ; i < sz ; ++i)
501 envCorba[i].key = CORBA::string_dup( _override_env[i].first.c_str() );
502 envCorba[i].value <<= CORBA::string_dup( _override_env[i].second.c_str() );
505 cont->override_environment_python( envCorba );
506 if( !_code_to_exe_on_startup.empty() )
507 cont->execute_python_code( _code_to_exe_on_startup.c_str() );
512 INFOS("[GiveContainer] Failed to launch container on resource " << resource_selected);
517 // We were not able to launch the container
518 INFOS("[GiveContainer] Cannot launch the container on the following selected resources:")
519 std::vector<std::string>::iterator it;
520 for (it=local_resources.begin() ; it < local_resources.end(); it++ )
521 INFOS("[GiveContainer] " << *it)
525 std::string SALOME_ContainerManager::GetCppBinaryOfKernelContainer() const
527 std::string ret = this->_isSSL ? "SALOME_Container_No_NS_Serv" : "SALOME_Container";
531 std::string SALOME_ContainerManager::GetRunRemoteExecutableScript() const
533 std::string ret = this->_isSSL ? "runRemoteSSL.sh" : "runRemote.sh";
537 Engines::Container_ptr
538 SALOME_ContainerManager::LaunchContainer(const Engines::ContainerParameters& params,
539 const std::string & resource_selected,
540 const std::string & hostname,
541 const std::string & machFile,
542 const std::string & containerNameInNS)
544 std::string user,command,logFilename,tmpFileName;
546 Engines::Container_ptr ret(Engines::Container::_nil());
547 {//start of critical section
548 Utils_Locker lock (&_giveContainerMutex1);
549 // Step 1: type of container: PaCO, Exe, Mpi or Classic
550 // Mpi already tested in step 5, specific code on BuildCommandToLaunch Local/Remote Container methods
551 // TODO -> separates Mpi from Classic/Exe
553 std::string container_exe = this->GetCppBinaryOfKernelContainer();
554 Engines::ContainerParameters local_params(params);
558 CORBA::String_var container_exe_tmp;
559 CORBA::Object_var obj = _NS->Resolve("/Kernel/ModulCatalog");
560 SALOME_ModuleCatalog::ModuleCatalog_var Catalog = SALOME_ModuleCatalog::ModuleCatalog::_narrow(obj) ;
561 if (CORBA::is_nil (Catalog))
563 INFOS("[GiveContainer] Module Catalog is not found -> cannot launch a container");
566 // Loop through component list
567 for(unsigned int i=0; i < local_params.resource_params.componentList.length(); i++)
569 const char* compoi = local_params.resource_params.componentList[i];
570 SALOME_ModuleCatalog::Acomponent_var compoInfo = Catalog->GetComponent(compoi);
571 if (CORBA::is_nil (compoInfo))
575 SALOME_ModuleCatalog::ImplType impl=compoInfo->implementation_type();
576 container_exe_tmp=compoInfo->implementation_name();
577 if(impl==SALOME_ModuleCatalog::CEXE)
581 INFOS("ContainerManager Error: you can't have 2 CEXE component in the same container" );
582 return Engines::Container::_nil();
584 MESSAGE("[GiveContainer] Exe container found !: " << container_exe_tmp);
585 container_exe = container_exe_tmp.in();
590 catch (ServiceUnreachable&)
592 INFOS("Caught exception: Naming Service Unreachable");
597 INFOS("Caught unknown exception.");
601 // Step 2: test resource
602 // Only if an application directory is set
603 if(hostname != Kernel_Utils::GetHostname() && _isAppliSalomeDefined)
606 const ParserResourcesType resInfo(_resManager->GetResourceDefinition(resource_selected));
607 std::string command = getCommandToRunRemoteProcess(resInfo.Protocol, resInfo.HostName,
608 resInfo.UserName, resInfo.AppliPath);
610 // Launch remote command
611 command += " \"ls /tmp >/dev/null 2>&1\"";
612 // Anthony : command is NO MORE launched to improve dramatically time to launch containers
616 // Error on resource - cannot launch commands
617 INFOS("[LaunchContainer] Cannot launch commands on machine " << hostname);
618 INFOS("[LaunchContainer] Command was " << command);
620 INFOS("[LaunchContainer] Command status is " << WEXITSTATUS(status));
622 return Engines::Container::_nil();
626 // Step 3: start a new container
627 // Check if a PaCO container
629 if (std::string(local_params.parallelLib.in()) != "")
631 ret = StartPaCOPPContainer(params, resource_selected);
634 // Other type of containers...
635 MESSAGE("[GiveContainer] Try to launch a new container on " << resource_selected);
636 // if a parallel container is launched in batch job, command is: "mpirun -np nbproc -machinefile nodesfile SALOME_MPIContainer"
637 if( GetenvThreadSafe("LIBBATCH_NODEFILE") != NULL && params.isMPI )
639 command = BuildCommandToLaunchLocalContainer(params, machFile, container_exe, tmpFileName);
640 MESSAGE("[LaunchContainer] LIBBATCH_NODEFILE : \"" << command << "\"");
642 // if a container is launched on localhost, command is "SALOME_Container" or "mpirun -np nbproc SALOME_MPIContainer"
643 else if(hostname == Kernel_Utils::GetHostname())
645 command = BuildCommandToLaunchLocalContainer(params, machFile, container_exe, tmpFileName);
646 MESSAGE("[LaunchContainer] hostname local : \"" << command << "\"");
648 // if a container is launched in remote mode, command is "ssh resource_selected SALOME_Container" or "ssh resource_selected mpirun -np nbproc SALOME_MPIContainer"
651 command = BuildCommandToLaunchRemoteContainer(resource_selected, params, container_exe);
652 MESSAGE("[LaunchContainer] remote : \"" << command << "\"");
655 //redirect stdout and stderr in a file
657 logFilename=GetenvThreadSafeAsString("TEMP");
659 user = GetenvThreadSafeAsString( "USERNAME" );
661 user = GetenvThreadSafeAsString( "USER" );
663 user = GetenvThreadSafeAsString( "LOGNAME" );
665 char* val = GetenvThreadSafe("SALOME_TMP_DIR");
668 struct stat file_info;
669 stat(val, &file_info);
670 bool is_dir = S_ISDIR(file_info.st_mode);
671 if (is_dir)logFilename=val;
672 else std::cerr << "SALOME_TMP_DIR environment variable is not a directory use /tmp instead" << std::endl;
676 logFilename += _NS->ContainerName(params)+"_"+ resource_selected +"_"+user;
677 std::ostringstream tmp;
678 tmp << "_" << getpid();
679 logFilename += tmp.str();
680 logFilename += ".log" ;
681 command += " > " + logFilename + " 2>&1";
682 MakeTheCommandToBeLaunchedASync(command);
684 MESSAGE("[LaunchContainer] SYSTEM COMMAND that will be launched : \"" << command << "\"");
685 // launch container with a system call
686 status=SystemThreadSafe(command.c_str());
687 }//end of critical of section
691 INFOS("[LaunchContainer] command failed (system command status -1): " << command);
692 RmTmpFile(tmpFileName); // command file can be removed here
693 return Engines::Container::_nil();
695 else if (status == 217)
697 INFOS("[LaunchContainer] command failed (system command status 217): " << command);
698 RmTmpFile(tmpFileName); // command file can be removed here
699 return Engines::Container::_nil();
703 // Step 4: Wait for the container
704 double nbTurn = ( (double)this->_time_out_in_second ) * ( 1000.0 / ( (double) this->_delta_time_ns_lookup_in_ms) );
705 int count( (int)nbTurn );
706 INFOS("[GiveContainer] # attempts : " << count << " name in NS : \"" << containerNameInNS << "\"");
707 INFOS("[GiveContainer] # attempts : Time in second before time out : " << this->_time_out_in_second << " Delta time in ms between NS lookup : " << this->_delta_time_ns_lookup_in_ms);
708 while (CORBA::is_nil(ret) && count)
710 std::this_thread::sleep_for(std::chrono::milliseconds(_delta_time_ns_lookup_in_ms));
712 MESSAGE("[GiveContainer] step " << count << " Waiting for container on " << resource_selected << " with entry in NS = \"" << containerNameInNS << "\"" );
713 CORBA::Object_var obj(_NS->Resolve(containerNameInNS.c_str()));
714 ret=Engines::Container::_narrow(obj);
716 if (CORBA::is_nil(ret))
718 INFOS("[GiveContainer] was not able to launch container " << containerNameInNS);
722 // Setting log file name
723 logFilename=":"+logFilename;
724 logFilename="@"+Kernel_Utils::GetHostname()+logFilename;//threadsafe
725 logFilename=user+logFilename;
726 ret->logfilename(logFilename.c_str());
727 RmTmpFile(tmpFileName); // command file can be removed here
733 //=============================================================================
734 //! Find a container given constraints (params) on a list of machines (possibleComputers)
735 //! agy : this method is ThreadSafe
739 //=============================================================================
741 Engines::Container_ptr SALOME_ContainerManager::FindContainer(const Engines::ContainerParameters& params, const Engines::ResourceList& possibleResources)
743 MESSAGE("[FindContainer] FindContainer on " << possibleResources.length() << " resources");
744 for(unsigned int i=0; i < possibleResources.length();i++)
746 Engines::Container_ptr cont = FindContainer(params, possibleResources[i].in());
747 if(!CORBA::is_nil(cont))
750 MESSAGE("[FindContainer] no container found");
751 return Engines::Container::_nil();
754 //=============================================================================
755 //! Find a container given constraints (params) on a machine (theMachine)
756 //! agy : this method is ThreadSafe
760 //=============================================================================
762 Engines::Container_ptr
763 SALOME_ContainerManager::FindContainer(const Engines::ContainerParameters& params, const std::string& resource)
765 ParserResourcesType resource_definition = _resManager->GetResourceDefinition(resource);
766 std::string hostname(resource_definition.HostName);
767 std::string containerNameInNS(_NS->BuildContainerNameForNS(params, hostname.c_str()));
768 MESSAGE("[FindContainer] Try to find a container " << containerNameInNS << " on resource " << resource);
769 CORBA::Object_var obj = _NS->Resolve(containerNameInNS.c_str());
772 if(obj->_non_existent())
773 return Engines::Container::_nil();
775 return Engines::Container::_narrow(obj);
777 catch(const CORBA::Exception&)
779 return Engines::Container::_nil();
784 bool isPythonContainer(const char* ContainerName);
786 //=============================================================================
788 * This is no longer valid (C++ container are also python containers)
790 //=============================================================================
791 bool isPythonContainer(const char* ContainerName)
793 return false; // VSR 02/08/2013: Python containers are no more supported
795 size_t len = strlen(ContainerName);
798 if (strcmp(ContainerName + len - 2, "Py") == 0)
804 //=============================================================================
806 * Builds the script to be launched
808 * If SALOME Application not defined ($APPLI),
809 * see BuildTempFileToLaunchRemoteContainer()
811 * Else rely on distant configuration. Command is under the form (example):
812 * ssh user@machine distantPath/runRemote.sh hostNS portNS WORKINGDIR workingdir \
813 * SALOME_Container containerName &"
815 * - where user is omitted if not specified in CatalogResources,
816 * - where distant path is always relative to user@machine $HOME, and
817 * equal to $APPLI if not specified in CatalogResources,
818 * - where hostNS is the hostname of CORBA naming server (set by scripts to
819 * use to launch SALOME and servers in $APPLI: runAppli.sh, runRemote.sh)
820 * - where portNS is the port used by CORBA naming server (set by scripts to
821 * use to launch SALOME and servers in $APPLI: runAppli.sh, runRemote.sh)
822 * - where workingdir is the requested working directory for the container.
823 * If WORKINGDIR (and workingdir) is not present the working dir will be $HOME
825 //=============================================================================
828 SALOME_ContainerManager::BuildCommandToLaunchRemoteContainer(const std::string& resource_name, const Engines::ContainerParameters& params, const std::string& container_exe) const
830 std::string command,tmpFileName;
831 const ParserResourcesType resInfo(_resManager->GetResourceDefinition(resource_name));
832 std::string wdir = params.workingdir.in();
833 if (!_isAppliSalomeDefined)
835 MESSAGE("[BuildCommandToLaunchRemoteContainer] NO APPLI MODE : " << " Protocol :" << resInfo.Protocol << " hostname :" << resInfo.HostName << " username : " << resInfo.UserName << " appli : " << resInfo.AppliPath << " wdir : \"" << wdir << "\"");
836 command = getCommandToRunRemoteProcessNoAppli(resInfo.Protocol, resInfo.HostName,
837 resInfo.UserName, resInfo.AppliPath,
842 MESSAGE("[BuildCommandToLaunchRemoteContainer] WITH APPLI MODE : " << " Protocol :" << resInfo.Protocol << " hostname :" << resInfo.HostName << " username : " << resInfo.UserName << " appli : " << resInfo.AppliPath << " wdir : \"" << wdir << "\"");
843 // "ssh -l user machine distantPath/runRemote.sh hostNS portNS WORKINGDIR workingdir
844 // SALOME_Container containerName -ORBInitRef NameService=IOR:01000..."
846 // "ssh -l user machine distantLauncher remote -p hostNS -m portNS -d dir
847 // -- SALOME_Container contName -ORBInitRef NameService=IOR:01000..."
848 command = getCommandToRunRemoteProcess(resInfo.Protocol, resInfo.HostName,
849 resInfo.UserName, resInfo.AppliPath,
854 int nbproc = params.nb_proc <= 0 ? 1 : params.nb_proc;
855 command += " mpirun -np ";
856 std::ostringstream o;
860 command += "-x PATH,LD_LIBRARY_PATH,OMNIORB_CONFIG,SALOME_trace ";
861 #elif defined(OPEN_MPI)
862 if( GetenvThreadSafe("OMPI_URI_FILE") == NULL )
863 command += "-x PATH -x LD_LIBRARY_PATH -x OMNIORB_CONFIG -x SALOME_trace";
865 command += "-x PATH -x LD_LIBRARY_PATH -x OMNIORB_CONFIG -x SALOME_trace -ompi-server file:";
866 command += GetenvThreadSafeAsString("OMPI_URI_FILE");
869 command += "-nameserver " + Kernel_Utils::GetHostname();
871 command += " SALOME_MPIContainer ";
874 command += " " +container_exe+ " ";
876 command += _NS->ContainerName(params) + " ";
879 Engines::EmbeddedNamingService_var ns = GetEmbeddedNamingService();
880 CORBA::String_var iorNS = _orb->object_to_string(ns);
881 command += std::string(iorNS);
883 else //if(!this->_isSSL)
886 AddOmninamesParams(command);
888 MESSAGE("command =" << command);
893 //=============================================================================
894 //! Return a path to the directory with scripts templates
896 * \return the path pointed by SALOME_KERNEL_SCRIPTS_DIR environment variable, if it is defined,
897 * ${KERNEL_ROOT_DIR}/share/salome/resources/separator/kernel/ScriptsTemplate - otherwise
899 //=============================================================================
900 std::string getScriptTemplateFilePath()
902 auto parseScriptTemplateFilePath = []() -> std::string
904 std::string scriptTemplateFilePath = SALOME_ContainerManager::GetenvThreadSafeAsString("SALOME_KERNEL_SCRIPTS_DIR");
905 if (!scriptTemplateFilePath.empty())
907 return scriptTemplateFilePath;
910 return SALOME_ContainerManager::GetenvThreadSafeAsString("KERNEL_ROOT_DIR") +
911 "/share/salome/resources/kernel/ScriptsTemplate";
915 static const std::string scriptTemplateFilePath = parseScriptTemplateFilePath();
916 return scriptTemplateFilePath;
919 //=============================================================================
920 //! Return a command line constructed based on Python scripts templates
922 * \param theScriptName the name of Python script template
923 * \param theScriptParameters the queue of parameter values
924 * \return the command line constructed according to the given parameters
926 //=============================================================================
927 std::string GetCommandFromTemplate(const std::string& theScriptName,
928 std::queue<std::string>& theScriptParameters)
934 PyObject* mod(PyImport_ImportModule(theScriptName.c_str()));
937 PyObject* sys = PyImport_ImportModule("sys");
938 PyObject* sys_path = PyObject_GetAttrString(sys, "path");
939 PyObject* folder_path = PyUnicode_FromString(getScriptTemplateFilePath().c_str());
940 PyList_Append(sys_path, folder_path);
942 mod = PyImport_ImportModule(theScriptName.c_str());
944 Py_XDECREF(folder_path);
945 Py_XDECREF(sys_path);
951 PyObject* meth(PyObject_GetAttrString(mod, "command"));
959 PyObject* tuple(PyTuple_New(theScriptParameters.size()));
961 auto insert_parameter = [&tuple, &theScriptParameters, &id]()
963 if (!theScriptParameters.empty())
965 PyTuple_SetItem(tuple, ++id, PyUnicode_FromString(theScriptParameters.front().c_str()));
966 theScriptParameters.pop();
970 while (!theScriptParameters.empty())
975 PyObject *args(PyTuple_New(1));
976 PyTuple_SetItem(args, 0, tuple);
978 PyObject *res(PyObject_CallObject(meth, args));
981 command = PyUnicode_AsUTF8(res);
992 MESSAGE("Command from template is ... " << command << std::endl);
995 //=============================================================================
997 //=============================================================================
999 * builds the command to be launched.
1001 //=============================================================================
1002 std::string SALOME_ContainerManager::BuildCommandToLaunchLocalContainer(const Engines::ContainerParameters& params, const std::string& machinesFile, const std::string& container_exe, std::string& tmpFileName) const
1004 // Prepare name of the script to be used
1005 std::string script_name = "SALOME_CM_LOCAL_NO_MPI";
1009 script_name = "SALOME_CM_LOCAL_MPI_LAN";
1010 #elif defined(OPEN_MPI)
1011 script_name = "SALOME_CM_LOCAL_MPI_OPENMPI";
1012 #elif defined(MPICH)
1013 script_name = "SALOME_CM_LOCAL_MPI_MPICH";
1017 // Prepare parameters to use in the Python script:
1018 // 1. All parameters are strings.
1019 // 2. For some booleans use "1" = True, "0" = False.
1020 // 3. If a parameter is NULL, then its value is "NULL".
1022 std::queue<std::string> script_parameters;
1024 // ===== Number of processes (key = "nb_proc")
1025 script_parameters.push(params.isMPI ? std::to_string(params.nb_proc <= 0 ? 1 : params.nb_proc) : "NULL");
1027 // ===== Working directory (key = "workdir") and temporary directory flag (key = "isTmpDir")
1028 // A working directory is requested
1029 std::string workdir = params.workingdir.in();
1030 std::string isTmpDir = std::to_string(0);
1031 if (workdir == "$TEMPDIR")
1033 // A new temporary directory is requested
1034 isTmpDir = std::to_string(1);
1035 workdir = Kernel_Utils::GetTmpDir();
1037 script_parameters.push(workdir);
1038 script_parameters.push(isTmpDir);
1040 // ===== Server name (key = "name_server")
1041 script_parameters.push(Kernel_Utils::GetHostname());
1043 // ===== Container (key = "container")
1044 std::string container;
1047 container = isPythonContainer(params.container_name) ? "pyMPI SALOME_ContainerPy.py" : "SALOME_MPIContainer";
1051 container = isPythonContainer(params.container_name) ? "SALOME_ContainerPy.py" : container_exe;
1053 script_parameters.push(container);
1055 // ===== Container name (key = "container_name")
1056 script_parameters.push(_NS->ContainerName(params));
1058 // ===== LIBBATCH node file (key = "libbatch_nodefile")
1059 script_parameters.push(std::to_string(GetenvThreadSafe("LIBBATCH_NODEFILE") != NULL ? 1 : 0));
1061 // ===== Machine file (key = "machine_file")
1062 script_parameters.push(machinesFile.empty() ? "NULL" : machinesFile);
1064 // ===== OMPI uri file (key = "ompi_uri_file")
1065 std::string ompi_uri_file = GetenvThreadSafeAsString("OMPI_URI_FILE");
1066 script_parameters.push(ompi_uri_file.empty() ? "NULL" : ompi_uri_file);
1068 std::string command_from_template = GetCommandFromTemplate(script_name, script_parameters);
1070 std::ostringstream o;
1071 o << command_from_template << " ";
1073 //==================================================================================== */
1077 Engines::EmbeddedNamingService_var ns = GetEmbeddedNamingService();
1078 CORBA::String_var iorNS = _orb->object_to_string(ns);
1084 AddOmninamesParams(o);
1087 tmpFileName = BuildTemporaryFileName();
1088 std::ofstream command_file( tmpFileName.c_str() );
1089 command_file << o.str();
1090 command_file.close();
1093 chmod(tmpFileName.c_str(), 0x1ED);
1096 std::string command = tmpFileName;
1097 MESSAGE("Command is file ... " << command);
1098 MESSAGE("Command is ... " << o.str());
1103 //=============================================================================
1105 * removes the generated temporary file in case of a remote launch.
1106 * This method is thread safe
1108 //=============================================================================
1110 void SALOME_ContainerManager::RmTmpFile(std::string& tmpFileName)
1112 size_t length = tmpFileName.size();
1116 std::string command = "del /F ";
1118 std::string command = "rm ";
1121 command += tmpFileName.substr(0, length - 3 );
1123 command += tmpFileName;
1125 SystemThreadSafe(command.c_str());
1126 //if dir is empty - remove it
1127 std::string tmp_dir = Kernel_Utils::GetDirByPath( tmpFileName );
1128 if ( Kernel_Utils::IsEmptyDir( tmp_dir ) )
1131 command = "del /F " + tmp_dir;
1133 command = "rmdir " + tmp_dir;
1135 SystemThreadSafe(command.c_str());
1140 //=============================================================================
1142 * add to command all options relative to naming service.
1144 //=============================================================================
1146 void SALOME_ContainerManager::AddOmninamesParams(std::string& command) const
1148 std::ostringstream oss;
1149 AddOmninamesParams(oss);
1153 //=============================================================================
1155 * add to command all options relative to naming service.
1157 //=============================================================================
1159 void SALOME_ContainerManager::AddOmninamesParams(std::ostream& fileStream) const
1161 AddOmninamesParams(fileStream,_NS);
1164 //=============================================================================
1166 * add to command all options relative to naming service.
1168 //=============================================================================
1170 void SALOME_ContainerManager::AddOmninamesParams(std::ostream& fileStream, SALOME_NamingService_Abstract *ns)
1172 SALOME_NamingService *nsTrad(dynamic_cast<SALOME_NamingService *>(ns));
1175 CORBA::String_var iorstr(nsTrad->getIORaddr());
1176 fileStream << "ORBInitRef NameService=";
1177 fileStream << iorstr;
1181 void SALOME_ContainerManager::MakeTheCommandToBeLaunchedASync(std::string& command)
1184 command = "%PYTHONBIN% -c \"import subprocess ; subprocess.Popen(r'" + command + "').pid\"";
1191 * Return in second the time out to give chance to server to be launched and
1192 * to register into NS
1194 int SALOME_ContainerManager::GetTimeOutToLoaunchServer()
1196 int count(TIME_OUT_TO_LAUNCH_CONT);
1197 if (GetenvThreadSafe("TIMEOUT_TO_LAUNCH_CONTAINER") != 0)
1199 std::string new_count_str(GetenvThreadSafeAsString("TIMEOUT_TO_LAUNCH_CONTAINER"));
1201 std::istringstream ss(new_count_str);
1202 if (!(ss >> new_count))
1204 INFOS("[LaunchContainer] TIMEOUT_TO_LAUNCH_CONTAINER should be an int");
1212 void SALOME_ContainerManager::SleepInSecond(int ellapseTimeInSecond)
1215 sleep( ellapseTimeInSecond ) ;
1217 int timeInMS(1000*ellapseTimeInSecond);
1222 //=============================================================================
1224 * generate a file name in /tmp directory
1226 //=============================================================================
1228 std::string SALOME_ContainerManager::BuildTemporaryFileName()
1230 //build more complex file name to support multiple salome session
1231 std::string aFileName = Kernel_Utils::GetTmpFileName();
1232 std::ostringstream str_pid;
1233 str_pid << ::getpid();
1234 aFileName = aFileName + "-" + str_pid.str();
1238 aFileName += ".bat";
1243 //=============================================================================
1245 * Builds in a temporary file the script to be launched.
1247 * Used if SALOME Application ($APPLI) is not defined.
1248 * The command is build with data from CatalogResources, in which every path
1249 * used on remote computer must be defined.
1251 //=============================================================================
1253 std::string SALOME_ContainerManager::BuildTempFileToLaunchRemoteContainer (const std::string& resource_name, const Engines::ContainerParameters& params, std::string& tmpFileName) const
1257 tmpFileName = BuildTemporaryFileName();
1258 std::ofstream tempOutputFile;
1259 tempOutputFile.open(tmpFileName.c_str(), std::ofstream::out );
1260 const ParserResourcesType resInfo(_resManager->GetResourceDefinition(resource_name));
1261 tempOutputFile << "#! /bin/sh" << std::endl;
1265 tempOutputFile << "export SALOME_trace=local" << std::endl; // mkr : 27.11.2006 : PAL13967 - Distributed supervision graphs - Problem with "SALOME_trace"
1266 //tempOutputFile << "source " << resInfo.PreReqFilePath << endl;
1272 int nbproc = params.nb_proc <= 0 ? 1 : params.nb_proc;
1274 tempOutputFile << "mpirun -np ";
1276 tempOutputFile << nbproc << " ";
1278 tempOutputFile << "-x PATH,LD_LIBRARY_PATH,OMNIORB_CONFIG,SALOME_trace ";
1279 #elif defined(OPEN_MPI)
1280 if( GetenvThreadSafe("OMPI_URI_FILE") == NULL )
1281 tempOutputFile << "-x PATH -x LD_LIBRARY_PATH -x OMNIORB_CONFIG -x SALOME_trace";
1283 tempOutputFile << "-x PATH -x LD_LIBRARY_PATH -x OMNIORB_CONFIG -x SALOME_trace -ompi-server file:";
1284 tempOutputFile << GetenvThreadSafeAsString("OMPI_URI_FILE");
1286 #elif defined(MPICH)
1287 tempOutputFile << "-nameserver " + Kernel_Utils::GetHostname();
1291 tempOutputFile << GetenvThreadSafeAsString("KERNEL_ROOT_DIR") << "/bin/salome/";
1295 if (isPythonContainer(params.container_name))
1296 tempOutputFile << " pyMPI SALOME_ContainerPy.py ";
1298 tempOutputFile << " SALOME_MPIContainer ";
1303 if (isPythonContainer(params.container_name))
1304 tempOutputFile << "SALOME_ContainerPy.py ";
1306 tempOutputFile << "SALOME_Container ";
1309 tempOutputFile << _NS->ContainerName(params) << " -";
1310 AddOmninamesParams(tempOutputFile);
1311 tempOutputFile << " &" << std::endl;
1312 tempOutputFile.flush();
1313 tempOutputFile.close();
1315 chmod(tmpFileName.c_str(), 0x1ED);
1318 // --- Build command
1320 std::string command;
1322 if (resInfo.Protocol == rsh)
1325 std::string commandRcp = "rcp ";
1326 commandRcp += tmpFileName;
1328 commandRcp += resInfo.HostName;
1330 commandRcp += tmpFileName;
1331 status = SystemThreadSafe(commandRcp.c_str());
1334 else if (resInfo.Protocol == ssh)
1337 std::string commandRcp = "scp ";
1338 commandRcp += tmpFileName;
1340 commandRcp += resInfo.HostName;
1342 commandRcp += tmpFileName;
1343 status = SystemThreadSafe(commandRcp.c_str());
1346 else if (resInfo.Protocol == srun)
1348 command = "srun -n 1 -N 1 --overlap --mem-per-cpu=0 --cpu-bind=none --nodelist=";
1349 std::string commandRcp = "rcp ";
1350 commandRcp += tmpFileName;
1352 commandRcp += resInfo.HostName;
1354 commandRcp += tmpFileName;
1355 status = SystemThreadSafe(commandRcp.c_str());
1358 throw SALOME_Exception("Unknown protocol");
1361 throw SALOME_Exception("Error of connection on remote host");
1363 command += resInfo.HostName;
1365 command += tmpFileName;
1373 std::string SALOME_ContainerManager::GetMPIZeroNode(const std::string machine, const std::string machinesFile) const
1376 std::string zeronode;
1377 std::string command;
1378 std::string tmpFile = BuildTemporaryFileName();
1379 const ParserResourcesType resInfo(_resManager->GetResourceDefinition(machine));
1381 if(resInfo.Protocol == sh)
1383 return resInfo.HostName;
1386 if( GetenvThreadSafe("LIBBATCH_NODEFILE") == NULL )
1388 if (_isAppliSalomeDefined)
1390 command = getCommandToRunRemoteProcess(resInfo.Protocol, resInfo.HostName,
1391 resInfo.UserName, resInfo.AppliPath);
1392 command += " mpirun -np 1 hostname -s > " + tmpFile;
1395 command = "mpirun -np 1 hostname -s > " + tmpFile;
1398 command = "mpirun -np 1 -machinefile " + machinesFile + " hostname -s > " + tmpFile;
1400 status = SystemThreadSafe(command.c_str());
1402 std::ifstream fp(tmpFile.c_str(),std::ios::in);
1403 while(fp >> zeronode);
1411 std::string SALOME_ContainerManager::machinesFile(const int nbproc)
1414 std::string nodesFile = GetenvThreadSafeAsString("LIBBATCH_NODEFILE");
1415 std::string machinesFile = Kernel_Utils::GetTmpFileName();
1416 std::ifstream fpi(nodesFile.c_str(),std::ios::in);
1417 std::ofstream fpo(machinesFile.c_str(),std::ios::out);
1419 _numInstanceMutex.lock();
1421 for(int i=0;i<_nbprocUsed;i++)
1424 for(int i=0;i<nbproc;i++)
1426 fpo << tmp << std::endl;
1428 throw SALOME_Exception("You need more processors than batch session have allocated for you! Unable to launch the mpi container: ");
1430 _nbprocUsed += nbproc;
1434 _numInstanceMutex.unlock();
1436 return machinesFile;
1440 std::string SALOME_ContainerManager::getCommandToRunRemoteProcessNoAppli(AccessProtocolType protocol, const std::string & hostname, const std::string & username, const std::string & applipath, const std::string & workdir) const
1442 return getCommandToRunRemoteProcessCommon("SALOME_CM_REMOTE","salome shell --",protocol,hostname,username,applipath,workdir);
1445 std::string SALOME_ContainerManager::getCommandToRunRemoteProcess(AccessProtocolType protocol, const std::string & hostname, const std::string & username, const std::string & applipath, const std::string & workdir) const
1447 return getCommandToRunRemoteProcessCommon("SALOME_CM_REMOTE_OLD",this->GetRunRemoteExecutableScript(),protocol,hostname,username,applipath,workdir);
1450 std::string SALOME_ContainerManager::getCommandToRunRemoteProcessCommon(const std::string& templateName,
1451 const std::string& remoteScript,
1452 AccessProtocolType protocol,
1453 const std::string & hostname,
1454 const std::string & username,
1455 const std::string & applipath,
1456 const std::string & workdir) const
1458 std::ostringstream command;
1460 // Prepare parameters to use in the Python script:
1461 // 1. All parameters are strings.
1462 // 2. For some booleans use "1" = True, "0" = False.
1463 // 3. If a parameter is NULL, then its value is "NULL".
1465 std::queue<std::string> script_parameters;
1467 // ===== Protocol (key = "protocol")
1468 std::string strProtocol;
1471 case rsh: strProtocol = "rsh"; break;
1472 case ssh: strProtocol = "ssh"; break;
1473 case srun: strProtocol = "srun"; break;
1474 case pbsdsh: strProtocol = "pbsdsh"; break;
1475 case blaunch: strProtocol = "blaunch"; break;
1477 throw SALOME_Exception("Unknown protocol");
1479 script_parameters.push(strProtocol);
1481 // ===== User name (key = "user")
1482 script_parameters.push(username.empty() ? "NULL" : username);
1484 // ===== Host name (key = "host")
1485 script_parameters.push(hostname.empty() ? "NULL" : hostname);
1488 // ===== Remote APPLI path (key = "appli")
1489 script_parameters.push(applipath.empty() ? GetenvThreadSafeAsString("APPLI") : applipath);
1493 ASSERT(GetenvThreadSafe("NSHOST"));
1494 ASSERT(GetenvThreadSafe("NSPORT"));
1497 struct stat statbuf;
1498 std::string appli_mode = (stat(GetenvThreadSafe("APPLI"), &statbuf) == 0 && S_ISREG(statbuf.st_mode)) ? "launcher" : "dir";
1500 // ===== Working directory (key = "workdir")
1501 script_parameters.push(workdir == "$TEMPDIR" ? "\\$TEMPDIR" : workdir);
1503 // ===== SSL (key = "ssl")
1504 script_parameters.push(this->_isSSL ? "1" : "0");
1506 // ===== Hostname of CORBA name server (key = "nshost")
1507 std::string nshost = GetenvThreadSafeAsString("NSHOST");
1508 script_parameters.push(nshost.empty() ? "NULL" : nshost);
1510 // ===== Port of CORBA name server (key = "nsport")
1511 std::string nsport = GetenvThreadSafeAsString("NSPORT");
1512 script_parameters.push(nsport.empty() ? "NULL" : nsport);
1514 // ===== Remote script (key = "remote_script")
1515 script_parameters.push(remoteScript.empty() ? "NONE" : remoteScript);
1517 // ===== Naming service (key = "naming_service")
1518 std::string namingService = "NONE";
1521 Engines::EmbeddedNamingService_var ns = GetEmbeddedNamingService();
1522 CORBA::String_var iorNS = _orb->object_to_string(ns);
1523 namingService = iorNS;
1525 script_parameters.push(namingService);
1527 // ===== APPLI mode (key = "appli_mode")
1528 // $APPLI points either to an application directory, or to a salome launcher file
1529 // we prepare the remote command according to the case
1530 script_parameters.push(appli_mode);
1532 command << GetCommandFromTemplate(templateName, script_parameters);
1534 return command.str();
1538 SALOME_ContainerManager::checkPaCOParameters(Engines::ContainerParameters & params, std::string resource_selected)
1542 // Step 1 : check ContainerParameters
1543 // Check container_name, has to be defined
1544 if (std::string(params.container_name.in()) == "")
1546 INFOS("[checkPaCOParameters] You must define a container_name to launch a PaCO++ container");
1549 // Check parallelLib
1550 std::string parallelLib = params.parallelLib.in();
1551 if (parallelLib != "Mpi" && parallelLib != "Dummy")
1553 INFOS("[checkPaCOParameters] parallelLib is not correctly defined");
1554 INFOS("[checkPaCOParameters] you can chosse between: Mpi and Dummy");
1555 INFOS("[checkPaCOParameters] you entered: " << parallelLib);
1559 if (params.nb_proc <= 0)
1561 INFOS("[checkPaCOParameters] You must define a nb_proc > 0");
1565 // Step 2 : check resource_selected
1566 const ParserResourcesType resource_definition = _resManager->GetResourceDefinition(resource_selected);
1567 //std::string protocol = resource_definition->protocol.in();
1568 std::string username = resource_definition.UserName;
1569 std::string applipath = resource_definition.AppliPath;
1571 //if (protocol == "" || username == "" || applipath == "")
1572 if (username == "" || applipath == "")
1574 INFOS("[checkPaCOParameters] resource selected is not well defined");
1575 INFOS("[checkPaCOParameters] resource name: " << resource_definition.Name);
1576 INFOS("[checkPaCOParameters] resource hostname: " << resource_definition.HostName);
1577 INFOS("[checkPaCOParameters] resource protocol: " << resource_definition.getAccessProtocolTypeStr());
1578 INFOS("[checkPaCOParameters] resource username: " << username);
1579 INFOS("[checkPaCOParameters] resource applipath: " << applipath);
1587 * :WARNING: Do not directly convert returned value to std::string
1588 * This function may return NULL if env variable is not defined.
1589 * And std::string(NULL) causes undefined behavior.
1590 * Use GetenvThreadSafeAsString to properly get a std::string.
1592 char *SALOME_ContainerManager::GetenvThreadSafe(const char *name)
1593 {// getenv is not thread safe. See man 7 pthread.
1594 Utils_Locker lock (&_getenvMutex);
1595 return getenv(name);
1599 * Return env variable as a std::string.
1600 * Return empty string if env variable is not set.
1602 std::string SALOME_ContainerManager::GetenvThreadSafeAsString(const char *name)
1604 char* var = GetenvThreadSafe(name);
1605 return var ? std::string(var) : std::string();
1608 int SALOME_ContainerManager::SystemThreadSafe(const char *command)
1610 Utils_Locker lock (&_systemMutex);
1611 return system(command);
1614 long SALOME_ContainerManager::SystemWithPIDThreadSafe(const std::vector<std::string>& command)
1616 Utils_Locker lock(&_systemMutex);
1617 if(command.size()<1)
1618 throw SALOME_Exception("SystemWithPIDThreadSafe : command is expected to have a length of size 1 at least !");
1620 pid_t pid ( fork() ) ; // spawn a child process, following code is executed in both processes
1622 pid_t pid = -1; //Throw SALOME_Exception on Windows
1624 if ( pid == 0 ) // I'm a child, replace myself with a new ompi-server
1626 std::size_t sz(command.size());
1627 char **args = new char *[sz+1];
1628 for(std::size_t i=0;i<sz;i++)
1629 args[i] = strdup(command[i].c_str());
1631 execvp( command[0].c_str() , args );
1632 std::ostringstream oss;
1633 oss << "Error when launching " << command[0];
1634 throw SALOME_Exception(oss.str().c_str()); // execvp failed
1638 throw SALOME_Exception("fork() failed");
1640 else // I'm a parent
1646 #ifdef WITH_PACO_PARALLEL
1648 //=============================================================================
1650 * Start a suitable PaCO++ Parallel Container in a list of machines.
1651 * \param params Container Parameters required for the container
1652 * \return CORBA container reference.
1654 //=============================================================================
1655 Engines::Container_ptr
1656 SALOME_ContainerManager::StartPaCOPPContainer(const Engines::ContainerParameters& params_const,
1657 std::string resource_selected)
1659 CORBA::Object_var obj;
1660 PaCO::InterfaceManager_var container_proxy;
1661 Engines::Container_ptr ret = Engines::Container::_nil();
1662 Engines::ContainerParameters params(params_const);
1663 params.resource_params.name = CORBA::string_dup(resource_selected.c_str());
1665 // Step 0 : Check parameters
1666 if (!checkPaCOParameters(params, resource_selected))
1668 INFOS("[StartPaCOPPContainer] check parameters failed ! see logs...");
1672 // Step 1 : Starting a new parallel container !
1673 INFOS("[StartPaCOPPContainer] Starting a PaCO++ parallel container");
1674 INFOS("[StartPaCOPPContainer] on resource : " << resource_selected);
1676 // Step 2 : Get a MachineFile for the parallel container
1677 std::string machine_file_name = _resManager->getMachineFile(resource_selected,
1679 params.parallelLib.in());
1681 if (machine_file_name == "")
1683 INFOS("[StartPaCOPPContainer] Machine file generation failed");
1687 // Step 3 : starting parallel container proxy
1688 std::string command_proxy("");
1689 std::string proxy_machine;
1692 command_proxy = BuildCommandToLaunchPaCOProxyContainer(params, machine_file_name, proxy_machine);
1694 catch(const SALOME_Exception & ex)
1696 INFOS("[StartPaCOPPContainer] Exception in BuildCommandToLaunchPaCOContainer");
1700 obj = LaunchPaCOProxyContainer(command_proxy, params, proxy_machine);
1701 if (CORBA::is_nil(obj))
1703 INFOS("[StartPaCOPPContainer] LaunchPaCOContainer for proxy returns NIL !");
1706 container_proxy = PaCO::InterfaceManager::_narrow(obj);
1707 MESSAGE("[StartPaCOPPContainer] PaCO container proxy is launched");
1709 // Step 4 : starting parallel container nodes
1710 std::string command_nodes("");
1711 SALOME_ContainerManager::actual_launch_machine_t nodes_machines;
1714 command_nodes = BuildCommandToLaunchPaCONodeContainer(params, machine_file_name, nodes_machines, proxy_machine);
1716 catch(const SALOME_Exception & ex)
1718 INFOS("[StarPaCOPPContainer] Exception in BuildCommandToLaunchPaCONodeContainer");
1723 std::string container_generic_node_name = std::string(params.container_name.in()) + std::string("Node");
1724 bool result = LaunchPaCONodeContainer(command_nodes, params, container_generic_node_name, nodes_machines);
1727 INFOS("[StarPaCOPPContainer] LaunchPaCONodeContainer failed !");
1728 // Il faut tuer le proxy
1731 Engines::Container_var proxy = Engines::Container::_narrow(container_proxy);
1736 INFOS("[StarPaCOPPContainer] Exception caught from proxy Shutdown...");
1741 // Step 4 : connecting nodes and the proxy to actually create a parallel container
1742 for (int i = 0; i < params.nb_proc; i++)
1744 std::ostringstream tmp;
1746 std::string proc_number = tmp.str();
1747 std::string container_node_name = container_generic_node_name + proc_number;
1749 std::string theNodeMachine(nodes_machines[i]);
1750 std::string containerNameInNS = _NS->BuildContainerNameForNS(container_node_name.c_str(), theNodeMachine.c_str());
1751 obj = _NS->Resolve(containerNameInNS.c_str());
1752 if (CORBA::is_nil(obj))
1754 INFOS("[StarPaCOPPContainer] CONNECTION FAILED From Naming Service !");
1755 INFOS("[StarPaCOPPContainer] Container name is " << containerNameInNS);
1760 MESSAGE("[StarPaCOPPContainer] Deploying node : " << container_node_name);
1761 PaCO::InterfaceParallel_var node = PaCO::InterfaceParallel::_narrow(obj);
1763 MESSAGE("[StarPaCOPPContainer] node " << container_node_name << " is deployed");
1765 catch(CORBA::SystemException& e)
1767 INFOS("[StarPaCOPPContainer] Exception in deploying node : " << containerNameInNS);
1768 INFOS("CORBA::SystemException : " << e);
1771 catch(CORBA::Exception& e)
1773 INFOS("[StarPaCOPPContainer] Exception in deploying node : " << containerNameInNS);
1774 INFOS("CORBA::Exception" << e);
1779 INFOS("[StarPaCOPPContainer] Exception in deploying node : " << containerNameInNS);
1780 INFOS("Unknown exception !");
1785 // Step 5 : starting parallel container
1788 MESSAGE ("[StarPaCOPPContainer] Starting parallel object");
1789 container_proxy->start();
1790 MESSAGE ("[StarPaCOPPContainer] Parallel object is started");
1791 ret = Engines::Container::_narrow(container_proxy);
1793 catch(CORBA::SystemException& e)
1795 INFOS("Caught CORBA::SystemException. : " << e);
1797 catch(PortableServer::POA::ServantAlreadyActive&)
1799 INFOS("Caught CORBA::ServantAlreadyActiveException");
1801 catch(CORBA::Exception&)
1803 INFOS("Caught CORBA::Exception.");
1805 catch(std::exception& exc)
1807 INFOS("Caught std::exception - "<<exc.what());
1811 INFOS("Caught unknown exception.");
1817 SALOME_ContainerManager::BuildCommandToLaunchPaCOProxyContainer(const Engines::ContainerParameters& params,
1818 std::string machine_file_name,
1819 std::string & proxy_hostname)
1821 // In the proxy case, we always launch a Dummy Proxy
1822 std::string exe_name = "SALOME_ParallelContainerProxyDummy";
1823 std::string container_name = params.container_name.in();
1825 // Convert nb_proc in string
1826 std::ostringstream tmp_string;
1827 tmp_string << params.nb_proc;
1828 std::string nb_proc_str = tmp_string.str();
1830 // Get resource definition
1831 ParserResourcesType resource_definition =
1832 _resManager->GetResourceDefinition(params.resource_params.name.in());
1835 std::string hostname;
1836 std::ifstream machine_file(machine_file_name.c_str());
1837 std::getline(machine_file, hostname, ' ');
1838 size_t found = hostname.find('\n');
1839 if (found!=std::string::npos)
1840 hostname.erase(found, 1); // Remove \n
1841 proxy_hostname = hostname;
1842 MESSAGE("[BuildCommandToLaunchPaCOProxyContainer] machine file name extracted is " << hostname);
1845 bool remote_execution = false;
1846 if (hostname != std::string(Kernel_Utils::GetHostname()))
1848 MESSAGE("[BuildCommandToLaunchPaCOProxyContainer] remote machine case detected !");
1849 remote_execution = true;
1853 std::string log_type("");
1854 char * get_val = GetenvThreadSafe("PARALLEL_LOG");
1858 // Generating the command
1859 std::string command_begin("");
1860 std::string command_end("");
1861 std::ostringstream command;
1863 LogConfiguration(log_type, "proxy", container_name, hostname, command_begin, command_end);
1864 command << command_begin;
1866 // Adding connection command
1867 // We can only have a remote execution with
1868 // a SALOME application
1869 if (remote_execution)
1871 ASSERT(GetenvThreadSafe("NSHOST"));
1872 ASSERT(GetenvThreadSafe("NSPORT"));
1874 command << resource_definition.getAccessProtocolTypeStr();
1876 command << resource_definition.UserName;
1877 command << " " << hostname;
1878 command << " " << resource_definition.AppliPath;
1879 command << "/runRemote.sh ";
1880 command << GetenvThreadSafeAsString("NSHOST") << " "; // hostname of CORBA name server
1881 command << GetenvThreadSafeAsString("NSPORT") << " "; // port of CORBA name server
1884 command << exe_name;
1885 command << " " << container_name;
1886 command << " Dummy";
1887 command << " " << hostname;
1888 command << " " << nb_proc_str;
1890 AddOmninamesParams(command);
1893 command << command_end;
1894 MESSAGE("[BuildCommandToLaunchPaCOProxyContainer] Command is: " << command.str());
1896 return command.str();
1900 SALOME_ContainerManager::BuildCommandToLaunchPaCONodeContainer(const Engines::ContainerParameters& params,
1901 const std::string & machine_file_name,
1902 SALOME_ContainerManager::actual_launch_machine_t & vect_machine,
1903 const std::string & proxy_hostname)
1906 std::string exe_name = "SALOME_ParallelContainerNode";
1907 exe_name += params.parallelLib.in();
1908 std::string container_name = params.container_name.in();
1910 // Convert nb_proc in string
1911 std::ostringstream nb_proc_stream;
1912 nb_proc_stream << params.nb_proc;
1914 // Get resource definition
1915 ParserResourcesType resource_definition =
1916 _resManager->GetResourceDefinition(params.resource_params.name.in());
1919 std::string log_type("");
1920 char * get_val = GetenvThreadSafe("PARALLEL_LOG");
1924 // Now the command is different according to paralleLib
1925 std::ostringstream command_nodes;
1926 std::ifstream machine_file(machine_file_name.c_str());
1927 if (std::string(params.parallelLib.in()) == "Dummy")
1929 for (int i= 0; i < params.nb_proc; i++)
1932 std::string hostname;
1933 std::getline(machine_file, hostname);
1934 MESSAGE("[BuildCommandToLaunchPaCONodeContainer] machine file name extracted is " << hostname);
1937 bool remote_execution = false;
1938 if (hostname != std::string(Kernel_Utils::GetHostname()))
1940 MESSAGE("[BuildCommandToLaunchPaCONodeContainer] remote machine case detected !");
1941 remote_execution = true;
1944 // For each node we have a new command
1945 // Generating the command
1946 std::ostringstream command_node_stream;
1947 std::string command_node_begin("");
1948 std::string command_node_end("");
1949 std::ostringstream node_number;
1951 std::string container_node_name = container_name + node_number.str();
1952 LogConfiguration(log_type, "node", container_node_name, hostname, command_node_begin, command_node_end);
1954 // Adding connection command
1955 // We can only have a remote execution with
1956 // a SALOME application
1957 if (remote_execution)
1959 ASSERT(GetenvThreadSafe("NSHOST"));
1960 ASSERT(GetenvThreadSafe("NSPORT"));
1962 command_node_stream << resource_definition.getAccessProtocolTypeStr();
1963 command_node_stream << " -l ";
1964 command_node_stream << resource_definition.UserName;
1965 command_node_stream << " " << hostname;
1966 command_node_stream << " " << resource_definition.AppliPath;
1967 command_node_stream << "/runRemote.sh ";
1968 command_node_stream << GetenvThreadSafeAsString("NSHOST") << " "; // hostname of CORBA name server
1969 command_node_stream << GetenvThreadSafeAsString("NSPORT") << " "; // port of CORBA name server
1972 command_node_stream << exe_name;
1973 command_node_stream << " " << container_name;
1974 command_node_stream << " " << params.parallelLib.in();
1975 command_node_stream << " " << proxy_hostname;
1976 command_node_stream << " " << node_number.str();
1977 command_node_stream << " -";
1978 AddOmninamesParams(command_node_stream);
1980 command_nodes << command_node_begin << command_node_stream.str() << command_node_end;
1981 vect_machine.push_back(hostname);
1985 else if (std::string(params.parallelLib.in()) == "Mpi")
1988 std::string hostname;
1989 std::getline(machine_file, hostname, ' ');
1990 MESSAGE("[BuildCommandToLaunchPaCONodeContainer] machine file name extracted is " << hostname);
1993 bool remote_execution = false;
1994 if (hostname != std::string(Kernel_Utils::GetHostname()))
1996 MESSAGE("[BuildCommandToLaunchPaCONodeContainer] remote machine case detected !");
1997 remote_execution = true;
2000 // In case of Mpi and Remote, we copy machine_file in the applipath
2001 // scp mpi_machine_file user@machine:Path
2002 std::ostringstream command_remote_stream;
2003 std::string::size_type last = machine_file_name.find_last_of("/");
2004 if (last == std::string::npos)
2007 if (resource_definition.Protocol == rsh)
2008 command_remote_stream << "rcp ";
2010 command_remote_stream << "scp ";
2011 command_remote_stream << machine_file_name << " ";
2012 command_remote_stream << resource_definition.UserName << "@";
2013 command_remote_stream << hostname << ":" << resource_definition.AppliPath;
2014 command_remote_stream << "/" << machine_file_name.substr(last+1);
2016 int status = SystemThreadSafe(command_remote_stream.str().c_str());
2019 INFOS("copy of the MPI machine file failed ! - sorry !");
2023 // Generating the command
2024 std::string command_begin("");
2025 std::string command_end("");
2027 LogConfiguration(log_type, "nodes", container_name, hostname, command_begin, command_end);
2028 command_nodes << command_begin;
2030 // Adding connection command
2031 // We can only have a remote execution with
2032 // a SALOME application
2033 if (remote_execution)
2035 ASSERT(GetenvThreadSafe("NSHOST"));
2036 ASSERT(GetenvThreadSafe("NSPORT"));
2038 command_nodes << resource_definition.getAccessProtocolTypeStr();
2039 command_nodes << " -l ";
2040 command_nodes << resource_definition.UserName;
2041 command_nodes << " " << hostname;
2042 command_nodes << " " << resource_definition.AppliPath;
2043 command_nodes << "/runRemote.sh ";
2044 command_nodes << GetenvThreadSafeAsString("NSHOST") << " "; // hostname of CORBA name server
2045 command_nodes << GetenvThreadSafeAsString("NSPORT") << " "; // port of CORBA name server
2048 if (resource_definition.mpi == lam)
2050 command_nodes << "mpiexec -ssi boot ";
2051 command_nodes << "-machinefile " << machine_file_name << " ";
2052 command_nodes << "-n " << params.nb_proc;
2056 command_nodes << "mpirun -np " << params.nb_proc;
2058 command_nodes << " " << exe_name;
2059 command_nodes << " " << container_name;
2060 command_nodes << " " << params.parallelLib.in();
2061 command_nodes << " " << proxy_hostname;
2062 command_nodes << " -";
2063 AddOmninamesParams(command_nodes);
2065 // We don't put hostname, because nodes are registered in the resource of the proxy
2066 for (int i= 0; i < params.nb_proc; i++)
2067 vect_machine.push_back(proxy_hostname);
2069 command_nodes << command_end;
2071 return command_nodes.str();
2075 SALOME_ContainerManager::LogConfiguration(const std::string & log_type,
2076 const std::string & exe_type,
2077 const std::string & container_name,
2078 const std::string & hostname,
2079 std::string & begin,
2082 if(log_type == "xterm")
2084 begin = "xterm -e \"export LD_LIBRARY_PATH=$LD_LIBRARY_PATH; export PATH=$PATH;";
2087 else if(log_type == "xterm_debug")
2089 begin = "xterm -e \"export LD_LIBRARY_PATH=$LD_LIBRARY_PATH; export PATH=$PATH;";
2094 // default into a file...
2095 std::string logFilename = "/tmp/" + container_name + "_" + hostname + "_" + exe_type + "_";
2096 std::string user = GetenvThreadSafeAsString("USER");
2098 user = GetenvThreadSafeAsString("LOGNAME");
2099 logFilename += user + ".log";
2100 end = " > " + logFilename + " 2>&1 & ";
2105 SALOME_ContainerManager::LaunchPaCOProxyContainer(const std::string& command,
2106 const Engines::ContainerParameters& params,
2107 const std::string & hostname)
2109 PaCO::InterfaceManager_ptr container_proxy = PaCO::InterfaceManager::_nil();
2111 MESSAGE("[LaunchPaCOProxyContainer] Launch command");
2112 int status = SystemThreadSafe(command.c_str());
2114 INFOS("[LaunchPaCOProxyContainer] failed : system command status -1");
2115 return container_proxy;
2117 else if (status == 217) {
2118 INFOS("[LaunchPaCOProxyContainer] failed : system command status 217");
2119 return container_proxy;
2122 int count(GetTimeOutToLoaunchServer());
2123 CORBA::Object_var obj = CORBA::Object::_nil();
2124 std::string containerNameInNS = _NS->BuildContainerNameForNS(params.container_name.in(),
2126 MESSAGE("[LaunchParallelContainer] Waiting for Parallel Container proxy : " << containerNameInNS);
2128 while (CORBA::is_nil(obj) && count)
2132 obj = _NS->Resolve(containerNameInNS.c_str());
2137 container_proxy = PaCO::InterfaceManager::_narrow(obj);
2139 catch(CORBA::SystemException& e)
2141 INFOS("[StarPaCOPPContainer] Exception in _narrow after LaunchParallelContainer for proxy !");
2142 INFOS("CORBA::SystemException : " << e);
2143 return container_proxy;
2145 catch(CORBA::Exception& e)
2147 INFOS("[StarPaCOPPContainer] Exception in _narrow after LaunchParallelContainer for proxy !");
2148 INFOS("CORBA::Exception" << e);
2149 return container_proxy;
2153 INFOS("[StarPaCOPPContainer] Exception in _narrow after LaunchParallelContainer for proxy !");
2154 INFOS("Unknown exception !");
2155 return container_proxy;
2157 if (CORBA::is_nil(container_proxy))
2159 INFOS("[StarPaCOPPContainer] PaCO::InterfaceManager::_narrow returns NIL !");
2160 return container_proxy;
2165 //=============================================================================
2166 /*! This method launches the parallel container.
2167 * It will may be placed on the resources manager.
2169 * \param command to launch
2170 * \param container's parameters
2171 * \param name of the container
2173 * \return CORBA container reference
2175 //=============================================================================
2177 SALOME_ContainerManager::LaunchPaCONodeContainer(const std::string& command,
2178 const Engines::ContainerParameters& params,
2179 const std::string& name,
2180 SALOME_ContainerManager::actual_launch_machine_t & vect_machine)
2182 INFOS("[LaunchPaCONodeContainer] Launch command");
2183 int status = SystemThreadSafe(command.c_str());
2185 INFOS("[LaunchPaCONodeContainer] failed : system command status -1");
2188 else if (status == 217) {
2189 INFOS("[LaunchPaCONodeContainer] failed : system command status 217");
2193 INFOS("[LaunchPaCONodeContainer] Waiting for the nodes of the parallel container");
2194 // We are waiting all the nodes
2195 for (int i = 0; i < params.nb_proc; i++)
2197 CORBA::Object_var obj = CORBA::Object::_nil();
2198 std::string theMachine(vect_machine[i]);
2200 std::ostringstream tmp;
2202 std::string proc_number = tmp.str();
2203 std::string container_node_name = name + proc_number;
2204 std::string containerNameInNS = _NS->BuildContainerNameForNS((char*) container_node_name.c_str(), theMachine.c_str());
2205 INFOS("[LaunchPaCONodeContainer] Waiting for Parallel Container node " << containerNameInNS << " on " << theMachine);
2206 int count(GetTimeOutToLoaunchServer());
2207 while (CORBA::is_nil(obj) && count) {
2210 obj = _NS->Resolve(containerNameInNS.c_str());
2212 if (CORBA::is_nil(obj))
2214 INFOS("[LaunchPaCONodeContainer] Launch of node failed (or not found) !");
2223 Engines::Container_ptr
2224 SALOME_ContainerManager::StartPaCOPPContainer(const Engines::ContainerParameters& /*params*/,
2225 std::string /*resource_selected*/)
2227 Engines::Container_ptr ret = Engines::Container::_nil();
2228 INFOS("[StarPaCOPPContainer] is disabled !");
2229 INFOS("[StarPaCOPPContainer] recompile SALOME Kernel to enable PaCO++ parallel extension");
2234 SALOME_ContainerManager::BuildCommandToLaunchPaCOProxyContainer(const Engines::ContainerParameters& /*params*/,
2235 std::string /*machine_file_name*/,
2236 std::string & /*proxy_hostname*/)
2242 SALOME_ContainerManager::BuildCommandToLaunchPaCONodeContainer(const Engines::ContainerParameters& /*params*/,
2243 const std::string & /*machine_file_name*/,
2244 SALOME_ContainerManager::actual_launch_machine_t & /*vect_machine*/,
2245 const std::string & /*proxy_hostname*/)
2250 SALOME_ContainerManager::LogConfiguration(const std::string & /*log_type*/,
2251 const std::string & /*exe_type*/,
2252 const std::string & /*container_name*/,
2253 const std::string & /*hostname*/,
2254 std::string & /*begin*/,
2255 std::string & /*end*/)
2260 SALOME_ContainerManager::LaunchPaCOProxyContainer(const std::string& /*command*/,
2261 const Engines::ContainerParameters& /*params*/,
2262 const std::string& /*hostname*/)
2264 CORBA::Object_ptr ret = CORBA::Object::_nil();
2269 SALOME_ContainerManager::LaunchPaCONodeContainer(const std::string& /*command*/,
2270 const Engines::ContainerParameters& /*params*/,
2271 const std::string& /*name*/,
2272 SALOME_ContainerManager::actual_launch_machine_t & /*vect_machine*/)