+
+std::string
+SALOME_ContainerManager::BuildCommandToLaunchPaCOProxyContainer(const Engines::ContainerParameters& params,
+ std::string machine_file_name,
+ std::string & proxy_hostname)
+{
+ // In the proxy case, we always launch a Dummy Proxy
+ std::string exe_name = "SALOME_ParallelContainerProxyDummy";
+ std::string container_name = params.container_name.in();
+
+ // Convert nb_proc in string
+ std::ostringstream tmp_string;
+ tmp_string << params.nb_proc;
+ std::string nb_proc_str = tmp_string.str();
+
+ // Get resource definition
+ ParserResourcesType resource_definition =
+ _resManager->GetResourceDefinition(params.resource_params.name.in());
+
+ // Choose hostname
+ std::string hostname;
+ std::ifstream machine_file(machine_file_name.c_str());
+ std::getline(machine_file, hostname, ' ');
+ size_t found = hostname.find('\n');
+ if (found!=std::string::npos)
+ hostname.erase(found, 1); // Remove \n
+ proxy_hostname = hostname;
+ MESSAGE("[BuildCommandToLaunchPaCOProxyContainer] machine file name extracted is " << hostname);
+
+ // Remote execution
+ bool remote_execution = false;
+ if (hostname != std::string(Kernel_Utils::GetHostname()))
+ {
+ MESSAGE("[BuildCommandToLaunchPaCOProxyContainer] remote machine case detected !");
+ remote_execution = true;
+ }
+
+ // Log environment
+ std::string log_type("");
+ char * get_val = GetenvThreadSafe("PARALLEL_LOG");
+ if (get_val)
+ log_type = get_val;
+
+ // Generating the command
+ std::string command_begin("");
+ std::string command_end("");
+ std::ostringstream command;
+
+ LogConfiguration(log_type, "proxy", container_name, hostname, command_begin, command_end);
+ command << command_begin;
+
+ // Adding connection command
+ // We can only have a remote execution with
+ // a SALOME application
+ if (remote_execution)
+ {
+ ASSERT(GetenvThreadSafe("NSHOST"));
+ ASSERT(GetenvThreadSafe("NSPORT"));
+
+ command << resource_definition.getAccessProtocolTypeStr();
+ command << " -l ";
+ command << resource_definition.UserName;
+ command << " " << hostname;
+ command << " " << resource_definition.AppliPath;
+ command << "/runRemote.sh ";
+ command << GetenvThreadSafeAsString("NSHOST") << " "; // hostname of CORBA name server
+ command << GetenvThreadSafeAsString("NSPORT") << " "; // port of CORBA name server
+ }
+
+ command << exe_name;
+ command << " " << container_name;
+ command << " Dummy";
+ command << " " << hostname;
+ command << " " << nb_proc_str;
+ command << " -";
+ AddOmninamesParams(command);
+
+ // Final command
+ command << command_end;
+ MESSAGE("[BuildCommandToLaunchPaCOProxyContainer] Command is: " << command.str());
+
+ return command.str();
+}
+
+std::string
+SALOME_ContainerManager::BuildCommandToLaunchPaCONodeContainer(const Engines::ContainerParameters& params,
+ const std::string & machine_file_name,
+ SALOME_ContainerManager::actual_launch_machine_t & vect_machine,
+ const std::string & proxy_hostname)
+{
+ // Name of exe
+ std::string exe_name = "SALOME_ParallelContainerNode";
+ exe_name += params.parallelLib.in();
+ std::string container_name = params.container_name.in();
+
+ // Convert nb_proc in string
+ std::ostringstream nb_proc_stream;
+ nb_proc_stream << params.nb_proc;
+
+ // Get resource definition
+ ParserResourcesType resource_definition =
+ _resManager->GetResourceDefinition(params.resource_params.name.in());
+
+ // Log environment
+ std::string log_type("");
+ char * get_val = GetenvThreadSafe("PARALLEL_LOG");
+ if (get_val)
+ log_type = get_val;
+
+ // Now the command is different according to paralleLib
+ std::ostringstream command_nodes;
+ std::ifstream machine_file(machine_file_name.c_str());
+ if (std::string(params.parallelLib.in()) == "Dummy")
+ {
+ for (int i= 0; i < params.nb_proc; i++)
+ {
+ // Choose hostname
+ std::string hostname;
+ std::getline(machine_file, hostname);
+ MESSAGE("[BuildCommandToLaunchPaCONodeContainer] machine file name extracted is " << hostname);
+
+ // Remote execution
+ bool remote_execution = false;
+ if (hostname != std::string(Kernel_Utils::GetHostname()))
+ {
+ MESSAGE("[BuildCommandToLaunchPaCONodeContainer] remote machine case detected !");
+ remote_execution = true;
+ }
+
+ // For each node we have a new command
+ // Generating the command
+ std::ostringstream command_node_stream;
+ std::string command_node_begin("");
+ std::string command_node_end("");
+ std::ostringstream node_number;
+ node_number << i;
+ std::string container_node_name = container_name + node_number.str();
+ LogConfiguration(log_type, "node", container_node_name, hostname, command_node_begin, command_node_end);
+
+ // Adding connection command
+ // We can only have a remote execution with
+ // a SALOME application
+ if (remote_execution)
+ {
+ ASSERT(GetenvThreadSafe("NSHOST"));
+ ASSERT(GetenvThreadSafe("NSPORT"));
+
+ command_node_stream << resource_definition.getAccessProtocolTypeStr();
+ command_node_stream << " -l ";
+ command_node_stream << resource_definition.UserName;
+ command_node_stream << " " << hostname;
+ command_node_stream << " " << resource_definition.AppliPath;
+ command_node_stream << "/runRemote.sh ";
+ command_node_stream << GetenvThreadSafeAsString("NSHOST") << " "; // hostname of CORBA name server
+ command_node_stream << GetenvThreadSafeAsString("NSPORT") << " "; // port of CORBA name server
+ }
+
+ command_node_stream << exe_name;
+ command_node_stream << " " << container_name;
+ command_node_stream << " " << params.parallelLib.in();
+ command_node_stream << " " << proxy_hostname;
+ command_node_stream << " " << node_number.str();
+ command_node_stream << " -";
+ AddOmninamesParams(command_node_stream);
+
+ command_nodes << command_node_begin << command_node_stream.str() << command_node_end;
+ vect_machine.push_back(hostname);
+ }
+ }
+
+ else if (std::string(params.parallelLib.in()) == "Mpi")
+ {
+ // Choose hostname
+ std::string hostname;
+ std::getline(machine_file, hostname, ' ');
+ MESSAGE("[BuildCommandToLaunchPaCONodeContainer] machine file name extracted is " << hostname);
+
+ // Remote execution
+ bool remote_execution = false;
+ if (hostname != std::string(Kernel_Utils::GetHostname()))
+ {
+ MESSAGE("[BuildCommandToLaunchPaCONodeContainer] remote machine case detected !");
+ remote_execution = true;
+ }
+
+ // In case of Mpi and Remote, we copy machine_file in the applipath
+ // scp mpi_machine_file user@machine:Path
+ std::ostringstream command_remote_stream;
+ std::string::size_type last = machine_file_name.find_last_of("/");
+ if (last == std::string::npos)
+ last = -1;
+
+ if (resource_definition.Protocol == rsh)
+ command_remote_stream << "rcp ";
+ else
+ command_remote_stream << "scp ";
+ command_remote_stream << machine_file_name << " ";
+ command_remote_stream << resource_definition.UserName << "@";
+ command_remote_stream << hostname << ":" << resource_definition.AppliPath;
+ command_remote_stream << "/" << machine_file_name.substr(last+1);
+
+ int status = SystemThreadSafe(command_remote_stream.str().c_str());
+ if (status == -1)
+ {
+ INFOS("copy of the MPI machine file failed ! - sorry !");
+ return "";
+ }
+
+ // Generating the command
+ std::string command_begin("");
+ std::string command_end("");
+
+ LogConfiguration(log_type, "nodes", container_name, hostname, command_begin, command_end);
+ command_nodes << command_begin;
+
+ // Adding connection command
+ // We can only have a remote execution with
+ // a SALOME application
+ if (remote_execution)
+ {
+ ASSERT(GetenvThreadSafe("NSHOST"));
+ ASSERT(GetenvThreadSafe("NSPORT"));
+
+ command_nodes << resource_definition.getAccessProtocolTypeStr();
+ command_nodes << " -l ";
+ command_nodes << resource_definition.UserName;
+ command_nodes << " " << hostname;
+ command_nodes << " " << resource_definition.AppliPath;
+ command_nodes << "/runRemote.sh ";
+ command_nodes << GetenvThreadSafeAsString("NSHOST") << " "; // hostname of CORBA name server
+ command_nodes << GetenvThreadSafeAsString("NSPORT") << " "; // port of CORBA name server
+ }
+
+ if (resource_definition.mpi == lam)
+ {
+ command_nodes << "mpiexec -ssi boot ";
+ command_nodes << "-machinefile " << machine_file_name << " ";
+ command_nodes << "-n " << params.nb_proc;
+ }
+ else
+ {
+ command_nodes << "mpirun -np " << params.nb_proc;
+ }
+ command_nodes << " " << exe_name;
+ command_nodes << " " << container_name;
+ command_nodes << " " << params.parallelLib.in();
+ command_nodes << " " << proxy_hostname;
+ command_nodes << " -";
+ AddOmninamesParams(command_nodes);
+
+ // We don't put hostname, because nodes are registered in the resource of the proxy
+ for (int i= 0; i < params.nb_proc; i++)
+ vect_machine.push_back(proxy_hostname);
+
+ command_nodes << command_end;
+ }
+ return command_nodes.str();
+}
+
+void
+SALOME_ContainerManager::LogConfiguration(const std::string & log_type,
+ const std::string & exe_type,
+ const std::string & container_name,
+ const std::string & hostname,
+ std::string & begin,
+ std::string & end)
+{
+ if(log_type == "xterm")
+ {
+ begin = "xterm -e \"export LD_LIBRARY_PATH=$LD_LIBRARY_PATH; export PATH=$PATH;";
+ end = "\"&";
+ }
+ else if(log_type == "xterm_debug")
+ {
+ begin = "xterm -e \"export LD_LIBRARY_PATH=$LD_LIBRARY_PATH; export PATH=$PATH;";
+ end = "; cat \" &";
+ }
+ else
+ {
+ // default into a file...
+ std::string logFilename = "/tmp/" + container_name + "_" + hostname + "_" + exe_type + "_";
+ std::string user = GetenvThreadSafeAsString("USER");
+ if (user.empty())
+ user = GetenvThreadSafeAsString("LOGNAME");
+ logFilename += user + ".log";
+ end = " > " + logFilename + " 2>&1 & ";
+ }
+}
+
+CORBA::Object_ptr
+SALOME_ContainerManager::LaunchPaCOProxyContainer(const std::string& command,
+ const Engines::ContainerParameters& params,
+ const std::string & hostname)
+{
+ PaCO::InterfaceManager_ptr container_proxy = PaCO::InterfaceManager::_nil();
+
+ MESSAGE("[LaunchPaCOProxyContainer] Launch command");
+ int status = SystemThreadSafe(command.c_str());
+ if (status == -1) {
+ INFOS("[LaunchPaCOProxyContainer] failed : system command status -1");
+ return container_proxy;
+ }
+ else if (status == 217) {
+ INFOS("[LaunchPaCOProxyContainer] failed : system command status 217");
+ return container_proxy;
+ }
+
+ int count(GetTimeOutToLoaunchServer());
+ CORBA::Object_var obj = CORBA::Object::_nil();
+ std::string containerNameInNS = _NS->BuildContainerNameForNS(params.container_name.in(),
+ hostname.c_str());
+ MESSAGE("[LaunchParallelContainer] Waiting for Parallel Container proxy : " << containerNameInNS);
+
+ while (CORBA::is_nil(obj) && count)
+ {
+ sleep(1);
+ count--;
+ obj = _NS->Resolve(containerNameInNS.c_str());
+ }
+
+ try
+ {
+ container_proxy = PaCO::InterfaceManager::_narrow(obj);
+ }
+ catch(CORBA::SystemException& e)
+ {
+ INFOS("[StarPaCOPPContainer] Exception in _narrow after LaunchParallelContainer for proxy !");
+ INFOS("CORBA::SystemException : " << e);
+ return container_proxy;
+ }
+ catch(CORBA::Exception& e)
+ {
+ INFOS("[StarPaCOPPContainer] Exception in _narrow after LaunchParallelContainer for proxy !");
+ INFOS("CORBA::Exception" << e);
+ return container_proxy;
+ }
+ catch(...)
+ {
+ INFOS("[StarPaCOPPContainer] Exception in _narrow after LaunchParallelContainer for proxy !");
+ INFOS("Unknown exception !");
+ return container_proxy;
+ }
+ if (CORBA::is_nil(container_proxy))
+ {
+ INFOS("[StarPaCOPPContainer] PaCO::InterfaceManager::_narrow returns NIL !");
+ return container_proxy;
+ }
+ return obj._retn();
+}
+
+//=============================================================================
+/*! This method launches the parallel container.
+ * It will may be placed on the resources manager.
+ *
+ * \param command to launch
+ * \param container's parameters
+ * \param name of the container
+ *
+ * \return CORBA container reference
+ */
+//=============================================================================
+bool
+SALOME_ContainerManager::LaunchPaCONodeContainer(const std::string& command,
+ const Engines::ContainerParameters& params,
+ const std::string& name,
+ SALOME_ContainerManager::actual_launch_machine_t & vect_machine)
+{
+ INFOS("[LaunchPaCONodeContainer] Launch command");
+ int status = SystemThreadSafe(command.c_str());
+ if (status == -1) {
+ INFOS("[LaunchPaCONodeContainer] failed : system command status -1");
+ return false;
+ }
+ else if (status == 217) {
+ INFOS("[LaunchPaCONodeContainer] failed : system command status 217");
+ return false;
+ }
+
+ INFOS("[LaunchPaCONodeContainer] Waiting for the nodes of the parallel container");
+ // We are waiting all the nodes
+ for (int i = 0; i < params.nb_proc; i++)
+ {
+ CORBA::Object_var obj = CORBA::Object::_nil();
+ std::string theMachine(vect_machine[i]);
+ // Name of the node
+ std::ostringstream tmp;
+ tmp << i;
+ std::string proc_number = tmp.str();
+ std::string container_node_name = name + proc_number;
+ std::string containerNameInNS = _NS->BuildContainerNameForNS((char*) container_node_name.c_str(), theMachine.c_str());
+ INFOS("[LaunchPaCONodeContainer] Waiting for Parallel Container node " << containerNameInNS << " on " << theMachine);
+ int count(GetTimeOutToLoaunchServer());
+ while (CORBA::is_nil(obj) && count) {
+ SleepInSecond(1);
+ count-- ;
+ obj = _NS->Resolve(containerNameInNS.c_str());
+ }
+ if (CORBA::is_nil(obj))
+ {
+ INFOS("[LaunchPaCONodeContainer] Launch of node failed (or not found) !");
+ return false;
+ }
+ }
+ return true;
+}
+
+#else
+
+Engines::Container_ptr
+SALOME_ContainerManager::StartPaCOPPContainer(const Engines::ContainerParameters& /*params*/,
+ std::string /*resource_selected*/)
+{
+ Engines::Container_ptr ret = Engines::Container::_nil();
+ INFOS("[StarPaCOPPContainer] is disabled !");
+ INFOS("[StarPaCOPPContainer] recompile SALOME Kernel to enable PaCO++ parallel extension");
+ return ret;
+}
+
+std::string
+SALOME_ContainerManager::BuildCommandToLaunchPaCOProxyContainer(const Engines::ContainerParameters& /*params*/,
+ std::string /*machine_file_name*/,
+ std::string & /*proxy_hostname*/)
+{
+ return "";
+}
+
+std::string
+SALOME_ContainerManager::BuildCommandToLaunchPaCONodeContainer(const Engines::ContainerParameters& /*params*/,
+ const std::string & /*machine_file_name*/,
+ SALOME_ContainerManager::actual_launch_machine_t & /*vect_machine*/,
+ const std::string & /*proxy_hostname*/)
+{
+ return "";
+}
+void
+SALOME_ContainerManager::LogConfiguration(const std::string & /*log_type*/,
+ const std::string & /*exe_type*/,
+ const std::string & /*container_name*/,
+ const std::string & /*hostname*/,
+ std::string & /*begin*/,
+ std::string & /*end*/)
+{
+}
+
+CORBA::Object_ptr
+SALOME_ContainerManager::LaunchPaCOProxyContainer(const std::string& /*command*/,
+ const Engines::ContainerParameters& /*params*/,
+ const std::string& /*hostname*/)
+{
+ CORBA::Object_ptr ret = CORBA::Object::_nil();
+ return ret;
+}
+
+bool
+SALOME_ContainerManager::LaunchPaCONodeContainer(const std::string& /*command*/,
+ const Engines::ContainerParameters& /*params*/,
+ const std::string& /*name*/,
+ SALOME_ContainerManager::actual_launch_machine_t & /*vect_machine*/)
+{
+ return false;
+}
+#endif