-// Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2010 CEA/DEN, EDF R&D, OPEN CASCADE
//
// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
//
// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
//
+
#include "SALOME_ContainerManager.hxx"
#include "SALOME_NamingService.hxx"
#include "SALOME_ModuleCatalog.hh"
#include "Utils_CorbaException.hxx"
#include <sstream>
+#ifdef WNT
+#include <process.h>
+#define getpid _getpid
+#endif
+
#ifdef WITH_PACO_PARALLEL
#include "PaCOPP.hxx"
#endif
#define TIME_OUT_TO_LAUNCH_CONT 61
-using namespace std;
-
const char *SALOME_ContainerManager::_ContainerManagerNameInNS =
"/ContainerManager";
+omni_mutex SALOME_ContainerManager::_numInstanceMutex;
+
+
//=============================================================================
/*!
* Constructor
*/
//=============================================================================
-SALOME_ContainerManager::SALOME_ContainerManager(CORBA::ORB_ptr orb, PortableServer::POA_var poa,
- SALOME_ResourcesManager *rm, SALOME_NamingService *ns)
+SALOME_ContainerManager::SALOME_ContainerManager(CORBA::ORB_ptr orb, PortableServer::POA_var poa, SALOME_ResourcesManager *rm, SALOME_NamingService *ns):_nbprocUsed(0)
{
MESSAGE("constructor");
_NS = ns;
#ifdef HAVE_MPI2
#ifdef WITHOPENMPI
+ std::string urifile = getenv("HOME");
+ std::ostringstream mypid;
+ mypid << getpid();
+ urifile += "/.urifile_" + mypid.str();
+ setenv("OMPI_URI_FILE",urifile.c_str(),0);
if( getenv("OMPI_URI_FILE") != NULL ){
system("killall ompi-server");
- string command;
+ std::string command;
command = "ompi-server -r ";
command += getenv("OMPI_URI_FILE");
int status=system(command.c_str());
bool isOK;
isOK = _NS->Change_Directory("/Containers");
if( isOK ){
- vector<string> vec = _NS->list_directory_recurs();
- list<string> lstCont;
- for(vector<string>::iterator iter = vec.begin();iter!=vec.end();iter++)
+ std::vector<std::string> vec = _NS->list_directory_recurs();
+ std::list<std::string> lstCont;
+ for(std::vector<std::string>::iterator iter = vec.begin();iter!=vec.end();iter++)
{
SCRUTE((*iter));
CORBA::Object_var obj=_NS->Resolve((*iter).c_str());
}
}
MESSAGE("Container list: ");
- for(list<string>::iterator iter=lstCont.begin();iter!=lstCont.end();iter++){
+ for(std::list<std::string>::iterator iter=lstCont.begin();iter!=lstCont.end();iter++){
SCRUTE((*iter));
}
- for(list<string>::iterator iter=lstCont.begin();iter!=lstCont.end();iter++)
+ for(std::list<std::string>::iterator iter=lstCont.begin();iter!=lstCont.end();iter++)
{
try
{
Engines::Container_ptr
SALOME_ContainerManager::GiveContainer(const Engines::ContainerParameters& params)
{
+ std::string machFile;
Engines::Container_ptr ret = Engines::Container::_nil();
// Step 0: Default mode is start
MESSAGE("[GiveContainer] starting with mode: " << mode);
// Step 1: Find Container for find and findorstart mode
- if (mode == "find" or mode == "findorstart")
+ if (mode == "find" || mode == "findorstart")
{
ret = FindContainer(params, params.resource_params.resList);
if(!CORBA::is_nil(ret))
try
{
if(!cont->_non_existent())
- local_resources.push_back(string(possibleResources[i]));
+ local_resources.push_back(std::string(possibleResources[i]));
}
catch(CORBA::Exception&) {}
}
}
else
for(unsigned int i=0; i < possibleResources->length(); i++)
- local_resources.push_back(string(possibleResources[i]));
+ local_resources.push_back(std::string(possibleResources[i]));
// Step 4: select the resource where to get/start the container
std::string resource_selected;
// Step 5: get container in the naming service
Engines::ResourceDefinition_var resource_definition = _ResManager->GetResourceDefinition(resource_selected.c_str());
- std::string hostname(resource_definition->name.in());
+ std::string hostname(resource_definition->hostname.in());
std::string containerNameInNS;
- if(params.isMPI)
+ if(params.isMPI){
+ int nbproc;
+ if ( params.nb_proc <= 0 )
+ nbproc = 1;
+ else
+ nbproc = params.nb_proc;
+ if( getenv("LIBBATCH_NODEFILE") != NULL )
+ machFile = machinesFile(nbproc);
// A mpi parallel container register on zero node in NS
- containerNameInNS = _NS->BuildContainerNameForNS(params, GetMPIZeroNode(hostname).c_str());
+ containerNameInNS = _NS->BuildContainerNameForNS(params, GetMPIZeroNode(hostname,machFile).c_str());
+ }
else
containerNameInNS = _NS->BuildContainerNameForNS(params, hostname.c_str());
MESSAGE("[GiveContainer] Container name in the naming service: " << containerNameInNS);
Engines::Container_var cont=Engines::Container::_narrow(obj);
if(!cont->_non_existent())
{
- if(std::string(params.mode.in())=="getorstart" or std::string(params.mode.in())=="get")
+ if(std::string(params.mode.in())=="getorstart" || std::string(params.mode.in())=="get"){
return cont._retn(); /* the container exists and params.mode is getorstart or get use it*/
+ }
else
{
INFOS("[GiveContainer] A container is already registered with the name: " << containerNameInNS << ", shutdown the existing container");
// Step 7: type of container: PaCO, Exe, Mpi or Classic
// Mpi already tested in step 5, specific code on BuildCommandToLaunch Local/Remote Container methods
// TODO -> separates Mpi from Classic/Exe
- // PaCO++
- std::string parallelLib(params.parallelLib);
- if (std::string(local_params.parallelLib.in()) != "")
- {
- INFOS("[GiveContainer] PaCO++ container are not currently available");
- return ret;
- }
// Classic or Exe ?
std::string container_exe = "SALOME_Container"; // Classic container
int found=0;
}
// Step 8: start a new container
+ // Check if a PaCO container
+ // PaCO++
+ if (std::string(local_params.parallelLib.in()) != "")
+ {
+ ret = StartPaCOPPContainer(params, resource_selected);
+ return ret;
+ }
+ // Other type of containers...
MESSAGE("[GiveContainer] Try to launch a new container on " << resource_selected);
std::string command;
- if(hostname == Kernel_Utils::GetHostname())
- command = BuildCommandToLaunchLocalContainer(params, container_exe);
+ // if a parallel container is launched in batch job, command is: "mpirun -np nbproc -machinefile nodesfile SALOME_MPIContainer"
+ if( getenv("LIBBATCH_NODEFILE") != NULL && params.isMPI )
+ command = BuildCommandToLaunchLocalContainer(params, machFile, container_exe);
+ // if a container is launched on localhost, command is "SALOME_Container" or "mpirun -np nbproc SALOME_MPIContainer"
+ else if(hostname == Kernel_Utils::GetHostname())
+ command = BuildCommandToLaunchLocalContainer(params, machFile, container_exe);
+ // if a container is launched in remote mode, command is "ssh resource_selected SALOME_Container" or "ssh resource_selected mpirun -np nbproc SALOME_MPIContainer"
else
command = BuildCommandToLaunchRemoteContainer(resource_selected, params, container_exe);
//redirect stdout and stderr in a file
#ifdef WNT
- string logFilename=getenv("TEMP");
+ std::string logFilename=getenv("TEMP");
logFilename += "\\";
+ std::string user = getenv( "USERNAME" );
#else
- string logFilename="/tmp";
+ std::string user = getenv( "USER" );
+ std::string logFilename="/tmp";
char* val = getenv("SALOME_TMP_DIR");
if(val)
{
}
logFilename += "/";
#endif
- logFilename += _NS->ContainerName(params)+"_"+ resource_selected +"_"+getenv( "USER" )+".log" ;
+ logFilename += _NS->ContainerName(params)+"_"+ resource_selected +"_"+user;
+ std::ostringstream tmp;
+ tmp << "_" << getpid();
+ logFilename += tmp.str();
+ logFilename += ".log" ;
command += " > " + logFilename + " 2>&1";
#ifdef WNT
command = "%PYTHONBIN% -c \"import win32pm ; win32pm.spawnpid(r'" + command + "', '')\"";
// Setting log file name
logFilename=":"+logFilename;
logFilename="@"+Kernel_Utils::GetHostname()+logFilename;
- logFilename=getenv( "USER" )+logFilename;
+ logFilename=user+logFilename;
ret->logfilename(logFilename.c_str());
RmTmpFile(_TmpFileName); // command file can be removed here
}
SALOME_ContainerManager::FindContainer(const Engines::ContainerParameters& params,
const std::string& resource)
{
- std::string containerNameInNS(_NS->BuildContainerNameForNS(params, resource.c_str()));
+ Engines::ResourceDefinition_var resource_definition = _ResManager->GetResourceDefinition(resource.c_str());
+ std::string hostname(resource_definition->hostname.in());
+ std::string containerNameInNS(_NS->BuildContainerNameForNS(params, hostname.c_str()));
MESSAGE("[FindContainer] Try to find a container " << containerNameInNS << " on resource " << resource);
CORBA::Object_var obj = _NS->Resolve(containerNameInNS.c_str());
try
}
}
+
+bool isPythonContainer(const char* ContainerName);
+
//=============================================================================
/*!
* This is no longer valid (C++ container are also python containers)
*/
//=============================================================================
-string
+std::string
SALOME_ContainerManager::BuildCommandToLaunchRemoteContainer
-(const string& resource_name,
+(const std::string& resource_name,
const Engines::ContainerParameters& params, const std::string& container_exe)
{
- string command;
+ std::string command;
if (!_isAppliSalomeDefined)
command = BuildTempFileToLaunchRemoteContainer(resource_name, params);
else
{
int nbproc;
Engines::ResourceDefinition_var resource_definition = _ResManager->GetResourceDefinition(resource_name.c_str());
- std::string hostname(resource_definition->name.in());
+ std::string hostname(resource_definition->hostname.in());
const ParserResourcesType& resInfo = _ResManager->GetImpl()->GetResourcesDescr(resource_name);
if (params.isMPI)
{
- if ((params.resource_params.nb_node <= 0) && (params.resource_params.nb_proc_per_node <= 0))
+ if ( params.nb_proc <= 0 )
nbproc = 1;
- else if (params.resource_params.nb_node == 0)
- nbproc = params.resource_params.nb_proc_per_node;
- else if (params.resource_params.nb_proc_per_node == 0)
- nbproc = params.resource_params.nb_node;
else
- nbproc = params.resource_params.nb_node * params.resource_params.nb_proc_per_node;
+ nbproc = params.nb_proc;
}
// "ssh -l user machine distantPath/runRemote.sh hostNS portNS WORKINGDIR workingdir \
* builds the command to be launched.
*/
//=============================================================================
-string
+std::string
SALOME_ContainerManager::BuildCommandToLaunchLocalContainer
-(const Engines::ContainerParameters& params, const std::string& container_exe)
+(const Engines::ContainerParameters& params, const std::string& machinesFile, const std::string& container_exe)
{
_TmpFileName = BuildTemporaryFileName();
- string command;
+ std::string command;
int nbproc = 0;
- ostringstream o;
+ std::ostringstream o;
if (params.isMPI)
{
o << "mpirun -np ";
- if ( (params.resource_params.nb_node <= 0) && (params.resource_params.nb_proc_per_node <= 0) )
+ if ( params.nb_proc <= 0 )
nbproc = 1;
- else if ( params.resource_params.nb_node == 0 )
- nbproc = params.resource_params.nb_proc_per_node;
- else if ( params.resource_params.nb_proc_per_node == 0 )
- nbproc = params.resource_params.nb_node;
else
- nbproc = params.resource_params.nb_node * params.resource_params.nb_proc_per_node;
+ nbproc = params.nb_proc;
o << nbproc << " ";
+ if( getenv("LIBBATCH_NODEFILE") != NULL )
+ o << "-machinefile " << machinesFile << " ";
+
#ifdef WITHLAM
o << "-x PATH,LD_LIBRARY_PATH,OMNIORB_CONFIG,SALOME_trace ";
#elif defined(WITHOPENMPI)
if(wdir == "$TEMPDIR")
{
// a new temporary directory is requested
- string dir = Kernel_Utils::GetTmpDir();
+ std::string dir = Kernel_Utils::GetTmpDir();
#ifdef WIN32
- o << "cd /d " << dir << endl;
+ o << "cd /d " << dir << std::endl;
#else
o << "cd " << dir << ";";
#endif
{
// a permanent directory is requested use it or create it
#ifdef WIN32
- o << "mkdir " + wdir << endl;
- o << "cd /D " + wdir << endl;
+ o << "mkdir " + wdir << std::endl;
+ o << "cd /D " + wdir << std::endl;
#else
o << "mkdir -p " << wdir << " && cd " << wdir + ";";
#endif
o << " -";
AddOmninamesParams(o);
- ofstream command_file( _TmpFileName.c_str() );
+ std::ofstream command_file( _TmpFileName.c_str() );
command_file << o.str();
command_file.close();
if ( lenght > 0)
{
#ifdef WIN32
- string command = "del /F ";
+ std::string command = "del /F ";
#else
- string command = "rm ";
+ std::string command = "rm ";
#endif
if ( lenght > 4 )
command += tmpFileName.substr(0, lenght - 3 );
command += '*';
system(command.c_str());
//if dir is empty - remove it
- string tmp_dir = Kernel_Utils::GetDirByPath( tmpFileName );
+ std::string tmp_dir = Kernel_Utils::GetDirByPath( tmpFileName );
if ( Kernel_Utils::IsEmptyDir( tmp_dir ) )
{
#ifdef WIN32
*/
//=============================================================================
-void SALOME_ContainerManager::AddOmninamesParams(string& command) const
+void SALOME_ContainerManager::AddOmninamesParams(std::string& command) const
{
CORBA::String_var iorstr = _NS->getIORaddr();
command += "ORBInitRef NameService=";
*/
//=============================================================================
-void SALOME_ContainerManager::AddOmninamesParams(ofstream& fileStream) const
+void SALOME_ContainerManager::AddOmninamesParams(std::ofstream& fileStream) const
{
CORBA::String_var iorstr = _NS->getIORaddr();
fileStream << "ORBInitRef NameService=";
*/
//=============================================================================
-void SALOME_ContainerManager::AddOmninamesParams(ostringstream& oss) const
+void SALOME_ContainerManager::AddOmninamesParams(std::ostringstream& oss) const
{
CORBA::String_var iorstr = _NS->getIORaddr();
oss << "ORBInitRef NameService=";
*/
//=============================================================================
-string SALOME_ContainerManager::BuildTemporaryFileName() const
+std::string SALOME_ContainerManager::BuildTemporaryFileName() const
{
//build more complex file name to support multiple salome session
- string aFileName = Kernel_Utils::GetTmpFileName();
+ std::string aFileName = Kernel_Utils::GetTmpFileName();
#ifndef WIN32
aFileName += ".sh";
#else
return aFileName;
}
-string SALOME_ContainerManager::GetMPIZeroNode(string machine)
-{
- int status;
- string zeronode;
- string cmd;
- string tmpFile = BuildTemporaryFileName();
-
- cmd = "ssh " + machine + " mpirun -np 1 hostname > " + tmpFile;
-
- status = system(cmd.c_str());
- if( status == 0 ){
- ifstream fp(tmpFile.c_str(),ios::in);
- fp >> zeronode;
- }
-
- RmTmpFile(tmpFile);
-
- return zeronode;
-}
-
//=============================================================================
/*!
* Builds in a temporary file the script to be launched.
*/
//=============================================================================
-string
+std::string
SALOME_ContainerManager::BuildTempFileToLaunchRemoteContainer
-(const string& resource_name,
+(const std::string& resource_name,
const Engines::ContainerParameters& params) throw(SALOME_Exception)
{
int status;
_TmpFileName = BuildTemporaryFileName();
- ofstream tempOutputFile;
- tempOutputFile.open(_TmpFileName.c_str(), ofstream::out );
+ std::ofstream tempOutputFile;
+ tempOutputFile.open(_TmpFileName.c_str(), std::ofstream::out );
const ParserResourcesType& resInfo = _ResManager->GetImpl()->GetResourcesDescr(resource_name);
- tempOutputFile << "#! /bin/sh" << endl;
+ tempOutputFile << "#! /bin/sh" << std::endl;
// --- set env vars
- tempOutputFile << "export SALOME_trace=local" << endl; // mkr : 27.11.2006 : PAL13967 - Distributed supervision graphs - Problem with "SALOME_trace"
+ tempOutputFile << "export SALOME_trace=local" << std::endl; // mkr : 27.11.2006 : PAL13967 - Distributed supervision graphs - Problem with "SALOME_trace"
//tempOutputFile << "source " << resInfo.PreReqFilePath << endl;
// ! env vars
tempOutputFile << "mpirun -np ";
int nbproc;
- if ( (params.resource_params.nb_node <= 0) && (params.resource_params.nb_proc_per_node <= 0) )
+ if ( params.nb_proc <= 0 )
nbproc = 1;
- else if ( params.resource_params.nb_node == 0 )
- nbproc = params.resource_params.nb_proc_per_node;
- else if ( params.resource_params.nb_proc_per_node == 0 )
- nbproc = params.resource_params.nb_node;
else
- nbproc = params.resource_params.nb_node * params.resource_params.nb_proc_per_node;
+ nbproc = params.nb_proc;
std::ostringstream o;
tempOutputFile << _NS->ContainerName(params) << " -";
AddOmninamesParams(tempOutputFile);
- tempOutputFile << " &" << endl;
+ tempOutputFile << " &" << std::endl;
tempOutputFile.flush();
tempOutputFile.close();
#ifndef WIN32
// --- Build command
- string command;
+ std::string command;
if (resInfo.Protocol == rsh)
{
command = "rsh ";
- string commandRcp = "rcp ";
+ std::string commandRcp = "rcp ";
commandRcp += _TmpFileName;
commandRcp += " ";
commandRcp += resInfo.HostName;
else if (resInfo.Protocol == ssh)
{
command = "ssh ";
- string commandRcp = "scp ";
+ std::string commandRcp = "scp ";
commandRcp += _TmpFileName;
commandRcp += " ";
commandRcp += resInfo.HostName;
}
+std::string SALOME_ContainerManager::GetMPIZeroNode(const std::string machine, const std::string machinesFile)
+{
+ int status;
+ std::string zeronode;
+ std::string command;
+ std::string tmpFile = BuildTemporaryFileName();
+
+ if( getenv("LIBBATCH_NODEFILE") == NULL )
+ {
+ if (_isAppliSalomeDefined)
+ {
+ const ParserResourcesType& resInfo = _ResManager->GetImpl()->GetResourcesDescr(machine);
+
+ if (resInfo.Protocol == rsh)
+ command = "rsh ";
+ else if (resInfo.Protocol == ssh)
+ command = "ssh ";
+ else
+ throw SALOME_Exception("Unknown protocol");
+
+ if (resInfo.UserName != "")
+ {
+ command += "-l ";
+ command += resInfo.UserName;
+ command += " ";
+ }
+
+ command += resInfo.HostName;
+ command += " ";
+
+ if (resInfo.AppliPath != "")
+ command += resInfo.AppliPath; // path relative to user@machine $HOME
+ else
+ {
+ ASSERT(getenv("APPLI"));
+ command += getenv("APPLI"); // path relative to user@machine $HOME
+ }
+
+ command += "/runRemote.sh ";
+
+ ASSERT(getenv("NSHOST"));
+ command += getenv("NSHOST"); // hostname of CORBA name server
+
+ command += " ";
+ ASSERT(getenv("NSPORT"));
+ command += getenv("NSPORT"); // port of CORBA name server
+
+ command += " mpirun -np 1 hostname > " + tmpFile;
+ }
+ else
+ command = "mpirun -np 1 hostname > " + tmpFile;
+ }
+ else
+ command = "mpirun -np 1 -machinefile " + machinesFile + " hostname > " + tmpFile;
+
+ status = system(command.c_str());
+ if( status == 0 ){
+ std::ifstream fp(tmpFile.c_str(),std::ios::in);
+ while(fp >> zeronode);
+ }
+
+ RmTmpFile(tmpFile);
+
+ return zeronode;
+}
+
+std::string SALOME_ContainerManager::machinesFile(const int nbproc)
+{
+ std::string tmp;
+ std::string nodesFile = getenv("LIBBATCH_NODEFILE");
+ std::string machinesFile = Kernel_Utils::GetTmpFileName();
+ std::ifstream fpi(nodesFile.c_str(),std::ios::in);
+ std::ofstream fpo(machinesFile.c_str(),std::ios::out);
+
+ _numInstanceMutex.lock();
+
+ for(int i=0;i<_nbprocUsed;i++)
+ fpi >> tmp;
+
+ for(int i=0;i<nbproc;i++)
+ if( fpi >> tmp )
+ fpo << tmp << std::endl;
+ else
+ throw SALOME_Exception("You ask more processes than batch session have allocated!");
+
+ _nbprocUsed += nbproc;
+ fpi.close();
+ fpo.close();
+
+ _numInstanceMutex.unlock();
+
+ return machinesFile;
+
+}
+
+bool
+SALOME_ContainerManager::checkPaCOParameters(Engines::ContainerParameters & params, std::string resource_selected)
+{
+ bool result = true;
+
+ // Step 1 : check ContainerParameters
+ // Check container_name, has to be defined
+ if (std::string(params.container_name.in()) == "")
+ {
+ INFOS("[checkPaCOParameters] You must define a container_name to launch a PaCO++ container");
+ result = false;
+ }
+ // Check parallelLib
+ std::string parallelLib = params.parallelLib.in();
+ if (parallelLib != "Mpi" && parallelLib != "Dummy")
+ {
+ INFOS("[checkPaCOParameters] parallelLib is not correctly defined");
+ INFOS("[checkPaCOParameters] you can chosse between: Mpi and Dummy");
+ INFOS("[checkPaCOParameters] you entered: " << parallelLib);
+ result = false;
+ }
+ // Check nb_proc
+ if (params.nb_proc <= 0)
+ {
+ INFOS("[checkPaCOParameters] You must define a nb_proc > 0");
+ result = false;
+ }
+
+ // Step 2 : check resource_selected
+ Engines::ResourceDefinition_var resource_definition = _ResManager->GetResourceDefinition(resource_selected.c_str());
+ std::string protocol = resource_definition->protocol.in();
+ std::string username = resource_definition->username.in();
+ std::string applipath = resource_definition->applipath.in();
+
+ if (protocol == "" || username == "" || applipath == "")
+ {
+ INFOS("[checkPaCOParameters] resource selected is not well defined");
+ INFOS("[checkPaCOParameters] resource name: " << resource_definition->name.in());
+ INFOS("[checkPaCOParameters] resource hostname: " << resource_definition->hostname.in());
+ INFOS("[checkPaCOParameters] resource protocol: " << protocol);
+ INFOS("[checkPaCOParameters] resource username: " << username);
+ INFOS("[checkPaCOParameters] resource applipath: " << applipath);
+ result = false;
+ }
+
+ return result;
+}
#ifdef WITH_PACO_PARALLEL
+
//=============================================================================
/*! CORBA Method:
- * Find or Start a suitable PaCO++ Parallel Container in a list of machines.
- * \param params Machine Parameters required for the container
+ * Start a suitable PaCO++ Parallel Container in a list of machines.
+ * \param params Container Parameters required for the container
* \return CORBA container reference.
*/
//=============================================================================
Engines::Container_ptr
-SALOME_ContainerManager::StartPaCOPPContainer(const Engines::ContainerParameters& params_const)
+SALOME_ContainerManager::StartPaCOPPContainer(const Engines::ContainerParameters& params_const,
+ std::string resource_selected)
{
CORBA::Object_var obj;
PaCO::InterfaceManager_var container_proxy;
Engines::Container_ptr ret = Engines::Container::_nil();
- Engines::MachineParameters params(params_const);
-
- // Step 1 : Try to find a suitable container
- // Currently not as good as could be since
- // we have to verified the number of nodes of the container
- // if a user tell that.
- ret = FindContainer(params, params.computerList);
- if(CORBA::is_nil(ret)) {
- // Step 2 : Starting a new parallel container !
- INFOS("[StartParallelContainer] Starting a PaCO++ parallel container");
-
- // Step 3 : Choose a computer
- std::string theMachine = _ResManager->FindFirst(params.computerList);
- //If the machine name is localhost use the real name
- if(theMachine == "localhost")
- theMachine=Kernel_Utils::GetHostname();
-
- if(theMachine == "") {
- INFOS("[StartParallelContainer] !!!!!!!!!!!!!!!!!!!!!!!!!!");
- INFOS("[StartParallelContainer] No possible computer found");
- INFOS("[StartParallelContainer] !!!!!!!!!!!!!!!!!!!!!!!!!!");
- return ret;
- }
- INFOS("[StartParallelContainer] on machine : " << theMachine);
- params.hostname = CORBA::string_dup(theMachine.c_str());
+ Engines::ContainerParameters params(params_const);
+ params.resource_params.name = CORBA::string_dup(resource_selected.c_str());
- // Step 4 : starting parallel container proxy
- Engines::MachineParameters params_proxy(params);
- std::string command_proxy;
- SALOME_ContainerManager::actual_launch_machine_t proxy_machine;
+ // Step 0 : Check parameters
+ if (!checkPaCOParameters(params, resource_selected))
+ {
+ INFOS("[StartPaCOPPContainer] check parameters failed ! see logs...");
+ return ret;
+ }
+
+ // Step 1 : Starting a new parallel container !
+ INFOS("[StartPaCOPPContainer] Starting a PaCO++ parallel container");
+ INFOS("[StartPaCOPPContainer] on resource : " << resource_selected);
+
+ // Step 2 : Get a MachineFile for the parallel container
+ std::string machine_file_name = _ResManager->getMachineFile(resource_selected,
+ params.nb_proc,
+ params.parallelLib.in());
+
+ if (machine_file_name == "")
+ {
+ INFOS("[StartPaCOPPContainer] Machine file generation failed");
+ return ret;
+ }
+
+ // Step 3 : starting parallel container proxy
+ std::string command_proxy("");
+ std::string proxy_machine;
+ try
+ {
+ command_proxy = BuildCommandToLaunchPaCOProxyContainer(params, machine_file_name, proxy_machine);
+ }
+ catch(const SALOME_Exception & ex)
+ {
+ INFOS("[StartPaCOPPContainer] Exception in BuildCommandToLaunchPaCOContainer");
+ INFOS(ex.what());
+ return ret;
+ }
+ obj = LaunchPaCOProxyContainer(command_proxy, params, proxy_machine);
+ if (CORBA::is_nil(obj))
+ {
+ INFOS("[StartPaCOPPContainer] LaunchPaCOContainer for proxy returns NIL !");
+ return ret;
+ }
+ container_proxy = PaCO::InterfaceManager::_narrow(obj);
+ MESSAGE("[StartPaCOPPContainer] PaCO container proxy is launched");
+
+ // Step 4 : starting parallel container nodes
+ std::string command_nodes("");
+ SALOME_ContainerManager::actual_launch_machine_t nodes_machines;
+ try
+ {
+ command_nodes = BuildCommandToLaunchPaCONodeContainer(params, machine_file_name, nodes_machines, proxy_machine);
+ }
+ catch(const SALOME_Exception & ex)
+ {
+ INFOS("[StarPaCOPPContainer] Exception in BuildCommandToLaunchPaCONodeContainer");
+ INFOS(ex.what());
+ return ret;
+ }
+
+ std::string container_generic_node_name = std::string(params.container_name.in()) + std::string("Node");
+ bool result = LaunchPaCONodeContainer(command_nodes, params, container_generic_node_name, nodes_machines);
+ if (!result)
+ {
+ INFOS("[StarPaCOPPContainer] LaunchPaCONodeContainer failed !");
+ // Il faut tuer le proxy
try
{
- command_proxy = BuildCommandToLaunchParallelContainer("SALOME_ParallelContainerProxy", params_proxy, proxy_machine);
+ Engines::Container_var proxy = Engines::Container::_narrow(container_proxy);
+ proxy->Shutdown();
}
- catch(const SALOME_Exception & ex)
+ catch (...)
{
- INFOS("[StartParallelContainer] Exception in BuildCommandToLaunchParallelContainer");
- INFOS(ex.what());
- return ret;
+ INFOS("[StarPaCOPPContainer] Exception catched from proxy Shutdown...");
}
- params_proxy.nb_proc = 0; // LaunchParallelContainer uses this value to know if it launches the proxy or the nodes
- obj = LaunchParallelContainer(command_proxy, params_proxy, _NS->ContainerName(params_proxy), proxy_machine);
- if (CORBA::is_nil(obj))
+ return ret;
+ }
+
+ // Step 4 : connecting nodes and the proxy to actually create a parallel container
+ for (int i = 0; i < params.nb_proc; i++)
+ {
+ std::ostringstream tmp;
+ tmp << i;
+ std::string proc_number = tmp.str();
+ std::string container_node_name = container_generic_node_name + proc_number;
+
+ std::string theNodeMachine(nodes_machines[i]);
+ std::string containerNameInNS = _NS->BuildContainerNameForNS(container_node_name.c_str(), theNodeMachine.c_str());
+ obj = _NS->Resolve(containerNameInNS.c_str());
+ if (CORBA::is_nil(obj))
{
- INFOS("[StartParallelContainer] LaunchParallelContainer for proxy returns NIL !");
+ INFOS("[StarPaCOPPContainer] CONNECTION FAILED From Naming Service !");
+ INFOS("[StarPaCOPPContainer] Container name is " << containerNameInNS);
return ret;
}
- try
+ try
{
- container_proxy = PaCO::InterfaceManager::_narrow(obj);
+ MESSAGE("[StarPaCOPPContainer] Deploying node : " << container_node_name);
+ PaCO::InterfaceParallel_var node = PaCO::InterfaceParallel::_narrow(obj);
+ node->deploy();
+ MESSAGE("[StarPaCOPPContainer] node " << container_node_name << " is deployed");
}
catch(CORBA::SystemException& e)
{
- INFOS("[StartParallelContainer] Exception in _narrow after LaunchParallelContainer for proxy !");
+ INFOS("[StarPaCOPPContainer] Exception in deploying node : " << containerNameInNS);
INFOS("CORBA::SystemException : " << e);
return ret;
}
catch(CORBA::Exception& e)
{
- INFOS("[StartParallelContainer] Exception in _narrow after LaunchParallelContainer for proxy !");
+ INFOS("[StarPaCOPPContainer] Exception in deploying node : " << containerNameInNS);
INFOS("CORBA::Exception" << e);
return ret;
}
catch(...)
{
- INFOS("[StartParallelContainer] Exception in _narrow after LaunchParallelContainer for proxy !");
+ INFOS("[StarPaCOPPContainer] Exception in deploying node : " << containerNameInNS);
INFOS("Unknown exception !");
return ret;
}
- if (CORBA::is_nil(container_proxy))
- {
- INFOS("[StartParallelContainer] PaCO::InterfaceManager::_narrow returns NIL !");
- return ret;
- }
+ }
- // Step 5 : starting parallel container nodes
- std::string command_nodes;
- Engines::MachineParameters params_nodes(params);
- SALOME_ContainerManager::actual_launch_machine_t nodes_machines;
- try
- {
- command_nodes = BuildCommandToLaunchParallelContainer("SALOME_ParallelContainerNode", params_nodes, nodes_machines, proxy_machine[0]);
- }
- catch(const SALOME_Exception & ex)
- {
- INFOS("[StartParallelContainer] Exception in BuildCommandToLaunchParallelContainer");
- INFOS(ex.what());
- return ret;
- }
- std::string container_generic_node_name = _NS->ContainerName(params) + "Node";
- obj = LaunchParallelContainer(command_nodes, params_nodes, container_generic_node_name, nodes_machines);
- if (CORBA::is_nil(obj))
+ // Step 5 : starting parallel container
+ try
+ {
+ MESSAGE ("[StarPaCOPPContainer] Starting parallel object");
+ container_proxy->start();
+ MESSAGE ("[StarPaCOPPContainer] Parallel object is started");
+ ret = Engines::Container::_narrow(container_proxy);
+ }
+ catch(CORBA::SystemException& e)
+ {
+ INFOS("Caught CORBA::SystemException. : " << e);
+ }
+ catch(PortableServer::POA::ServantAlreadyActive&)
+ {
+ INFOS("Caught CORBA::ServantAlreadyActiveException");
+ }
+ catch(CORBA::Exception&)
+ {
+ INFOS("Caught CORBA::Exception.");
+ }
+ catch(std::exception& exc)
+ {
+ INFOS("Caught std::exception - "<<exc.what());
+ }
+ catch(...)
+ {
+ INFOS("Caught unknown exception.");
+ }
+ return ret;
+}
+
+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
+ Engines::ResourceDefinition_var resource_definition =
+ _ResManager->GetResourceDefinition(params.resource_params.name);
+
+ // 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 environnement
+ std::string log_type("");
+ char * get_val = getenv("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(getenv("NSHOST"));
+ ASSERT(getenv("NSPORT"));
+
+ command << resource_definition->protocol.in();
+ command << " -l ";
+ command << resource_definition->username.in();
+ command << " " << hostname;
+ command << " " << resource_definition->applipath.in();
+ command << "/runRemote.sh ";
+ command << getenv("NSHOST") << " "; // hostname of CORBA name server
+ command << getenv("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
+ Engines::ResourceDefinition_var resource_definition =
+ _ResManager->GetResourceDefinition(params.resource_params.name);
+
+ // Log environnement
+ std::string log_type("");
+ char * get_val = getenv("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++)
{
- INFOS("[StartParallelContainer] LaunchParallelContainer for nodes returns NIL !");
- // Il faut tuer le proxy
- try
+ // 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()))
{
- Engines::Container_var proxy = Engines::Container::_narrow(container_proxy);
- proxy->Shutdown();
+ MESSAGE("[BuildCommandToLaunchPaCONodeContainer] remote machine case detected !");
+ remote_execution = true;
}
- catch (...)
+
+ // 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)
{
- INFOS("[StartParallelContainer] Exception catched from proxy Shutdown...");
+ ASSERT(getenv("NSHOST"));
+ ASSERT(getenv("NSPORT"));
+
+ command_node_stream << resource_definition->protocol.in();
+ command_node_stream << " -l ";
+ command_node_stream << resource_definition->username.in();
+ command_node_stream << " " << hostname;
+ command_node_stream << " " << resource_definition->applipath.in();
+ command_node_stream << "/runRemote.sh ";
+ command_node_stream << getenv("NSHOST") << " "; // hostname of CORBA name server
+ command_node_stream << getenv("NSPORT") << " "; // port of CORBA name server
}
- return ret;
- }
- // Step 6 : connecting nodes and the proxy to actually create a parallel container
- for (int i = 0; i < params.nb_proc; i++)
- {
- std::ostringstream tmp;
- tmp << i;
- std::string proc_number = tmp.str();
- std::string container_node_name = container_generic_node_name + proc_number;
+ 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);
- std::string theNodeMachine(nodes_machines[i]);
- std::string containerNameInNS = _NS->BuildContainerNameForNS(container_node_name.c_str(), theNodeMachine.c_str());
- obj = _NS->Resolve(containerNameInNS.c_str());
- if (CORBA::is_nil(obj))
- {
- INFOS("[StartParallelContainer] CONNECTION FAILED From Naming Service !");
- INFOS("[StartParallelContainer] Container name is " << containerNameInNS);
- return ret;
- }
- try
- {
- MESSAGE("[StartParallelContainer] Deploying node : " << container_node_name);
- PaCO::InterfaceParallel_var node = PaCO::InterfaceParallel::_narrow(obj);
- node->deploy();
- MESSAGE("[StartParallelContainer] node " << container_node_name << " is deployed");
- }
- catch(CORBA::SystemException& e)
- {
- INFOS("[StartParallelContainer] Exception in deploying node : " << containerNameInNS);
- INFOS("CORBA::SystemException : " << e);
- return ret;
- }
- catch(CORBA::Exception& e)
- {
- INFOS("[StartParallelContainer] Exception in deploying node : " << containerNameInNS);
- INFOS("CORBA::Exception" << e);
- return ret;
- }
- catch(...)
- {
- INFOS("[StartParallelContainer] Exception in deploying node : " << containerNameInNS);
- INFOS("Unknown exception !");
- return ret;
- }
+ command_nodes << command_node_begin << command_node_stream.str() << command_node_end;
+ vect_machine.push_back(hostname);
}
+ }
- // Step 7 : starting parallel container
- try
- {
- MESSAGE ("[StartParallelContainer] Starting parallel object");
- container_proxy->start();
- MESSAGE ("[StartParallelContainer] Parallel object is started");
- ret = Engines::Container::_narrow(container_proxy);
- }
- catch(CORBA::SystemException& e)
+ 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()))
{
- INFOS("Caught CORBA::SystemException. : " << e);
+ MESSAGE("[BuildCommandToLaunchPaCONodeContainer] remote machine case detected !");
+ remote_execution = true;
}
- catch(PortableServer::POA::ServantAlreadyActive&)
+
+ // 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;
+
+ std::string protocol = resource_definition->protocol.in();
+ if (protocol == "rsh")
+ command_remote_stream << "rcp ";
+ else
+ command_remote_stream << "scp ";
+ command_remote_stream << machine_file_name << " ";
+ command_remote_stream << resource_definition->username.in() << "@";
+ command_remote_stream << hostname << ":" << resource_definition->applipath.in();
+ command_remote_stream << "/" << machine_file_name.substr(last+1);
+
+ int status = system(command_remote_stream.str().c_str());
+ if (status == -1)
{
- INFOS("Caught CORBA::ServantAlreadyActiveException");
+ INFOS("copy of the MPI machine file failed ! - sorry !");
+ return "";
}
- catch(CORBA::Exception&)
+
+ // 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)
{
- INFOS("Caught CORBA::Exception.");
+ ASSERT(getenv("NSHOST"));
+ ASSERT(getenv("NSPORT"));
+
+ command_nodes << resource_definition->protocol.in();
+ command_nodes << " -l ";
+ command_nodes << resource_definition->username.in();
+ command_nodes << " " << hostname;
+ command_nodes << " " << resource_definition->applipath.in();
+ command_nodes << "/runRemote.sh ";
+ command_nodes << getenv("NSHOST") << " "; // hostname of CORBA name server
+ command_nodes << getenv("NSPORT") << " "; // port of CORBA name server
}
- catch(std::exception& exc)
+
+ if (std::string(resource_definition->mpiImpl.in()) == "lam")
{
- INFOS("Caught std::exception - "<<exc.what());
+ command_nodes << "mpiexec -ssi boot ";
+ command_nodes << "-machinefile " << machine_file_name << " ";
+ command_nodes << "-n " << params.nb_proc;
}
- catch(...)
+ else
{
- INFOS("Caught unknown exception.");
+ 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 ret;
+ return command_nodes.str();
}
-#else
-//=============================================================================
-/*! CORBA Method:
- * Find or Start a suitable PaCO++ Parallel Container in a list of machines.
- * \param params Machine Parameters required for the container
- * \return CORBA container reference.
- */
-//=============================================================================
-Engines::Container_ptr
-SALOME_ContainerManager::StartPaCOPPContainer(const Engines::ContainerParameters& params)
+
+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)
{
- Engines::Container_ptr ret = Engines::Container::_nil();
- INFOS("[StartParallelContainer] is disabled !");
- INFOS("[StartParallelContainer] recompile SALOME Kernel to enable parallel extension");
- return ret;
+ 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 + "_";
+ logFilename += std::string(getenv("USER")) + ".log";
+ end = " > " + logFilename + " 2>&1 & ";
+ }
}
-#endif
-#ifndef WITH_PACO_PARALLEL
CORBA::Object_ptr
-SALOME_ContainerManager::LaunchParallelContainer(const std::string& command,
- const Engines::ContainerParameters& params,
- const std::string& name,
- SALOME_ContainerManager::actual_launch_machine_t & vect_machine)
+SALOME_ContainerManager::LaunchPaCOProxyContainer(const std::string& command,
+ const Engines::ContainerParameters& params,
+ const std::string & hostname)
{
- CORBA::Object_ptr obj = CORBA::Object::_nil();
- return obj;
+ PaCO::InterfaceManager_ptr container_proxy = PaCO::InterfaceManager::_nil();
+
+ MESSAGE("[LaunchPaCOProxyContainer] Launch command");
+ int status = system(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 = TIME_OUT_TO_LAUNCH_CONT;
+ 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();
}
-#else
+
//=============================================================================
/*! This method launches the parallel container.
* It will may be placed on the ressources manager.
* \return CORBA container reference
*/
//=============================================================================
-CORBA::Object_ptr
-SALOME_ContainerManager::LaunchParallelContainer(const std::string& command,
+bool
+SALOME_ContainerManager::LaunchPaCONodeContainer(const std::string& command,
const Engines::ContainerParameters& params,
const std::string& name,
SALOME_ContainerManager::actual_launch_machine_t & vect_machine)
{
- CORBA::Object_ptr obj = CORBA::Object::_nil();
- std::string containerNameInNS;
- int count = TIME_OUT_TO_LAUNCH_CONT;
-
- INFOS("[LaunchParallelContainer] Begin");
+ INFOS("[LaunchPaCONodeContainer] Launch command");
int status = system(command.c_str());
if (status == -1) {
- INFOS("[LaunchParallelContainer] failed : system command status -1");
- return obj;
+ INFOS("[LaunchPaCONodeContainer] failed : system command status -1");
+ return false;
}
else if (status == 217) {
- INFOS("[LaunchParallelContainer] failed : system command status 217");
- return obj;
+ INFOS("[LaunchPaCONodeContainer] failed : system command status 217");
+ return false;
}
- if (params.nb_proc == 0)
+ 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++)
{
- std::string theMachine(vect_machine[0]);
- // Proxy We have launch a proxy
- containerNameInNS = _NS->BuildContainerNameForNS((char*) name.c_str(), theMachine.c_str());
- INFOS("[LaunchParallelContainer] Waiting for Parallel Container proxy " << containerNameInNS << " on " << theMachine);
- while (CORBA::is_nil(obj) && count)
- {
-#ifndef WIN32
+ 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 = TIME_OUT_TO_LAUNCH_CONT;
+ while (CORBA::is_nil(obj) && count) {
sleep(1) ;
-#else
- Sleep(1000);
-#endif
count-- ;
obj = _NS->Resolve(containerNameInNS.c_str());
}
- }
- else
- {
- INFOS("[LaunchParallelContainer] launching the nodes of the parallel container");
- // We are waiting all the nodes
- for (int i = 0; i < params.nb_proc; i++)
+ if (CORBA::is_nil(obj))
{
- 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;
- containerNameInNS = _NS->BuildContainerNameForNS((char*) container_node_name.c_str(), theMachine.c_str());
- INFOS("[LaunchParallelContainer] Waiting for Parallel Container node " << containerNameInNS << " on " << theMachine);
- while (CORBA::is_nil(obj) && count) {
-#ifndef WIN32
- sleep(1) ;
-#else
- Sleep(1000);
-#endif
- count-- ;
- obj = _NS->Resolve(containerNameInNS.c_str());
- }
- if (CORBA::is_nil(obj))
- {
- INFOS("[LaunchParallelContainer] Launch of node failed (or not found) !");
- return obj;
- }
+ INFOS("[LaunchPaCONodeContainer] Launch of node failed (or not found) !");
+ return false;
}
}
- if (CORBA::is_nil(obj))
- INFOS("[LaunchParallelContainer] failed");
-
- return obj;
+ return true;
}
-#endif
-#ifndef WITH_PACO_PARALLEL
-string
-SALOME_ContainerManager::BuildCommandToLaunchParallelContainer(const std::string& exe_name,
- const Engines::ContainerParameters& params,
- SALOME_ContainerManager::actual_launch_machine_t & vect_machine,
- const std::string proxy_hostname)
-{
- return "";
-}
#else
-//=============================================================================
-/*! Creates a command line that the container manager uses to launch
- * a parallel container.
- */
-//=============================================================================
-string
-SALOME_ContainerManager::BuildCommandToLaunchParallelContainer(const std::string& exe_name,
- const Engines::ContainerParameters& params,
- SALOME_ContainerManager::actual_launch_machine_t & vect_machine,
- const std::string proxy_hostname)
-{
- // This method knows the differences between the proxy and the nodes.
- // nb_proc is not used in the same way if it is a proxy or
- // a node.
-
- //command = "gdb --args ";
- //command = "valgrind --tool=memcheck --log-file=val_log ";
- //command += real_exe_name;
-
- // Step 0 : init some variables...
- std::string parallelLib(CORBA::string_dup(params.parallelLib));
- std::string real_exe_name = exe_name + parallelLib;
- std::string machine_file_name("");
- bool remote = false;
- bool is_a_proxy = false;
- std::string hostname(CORBA::string_dup(params.hostname));
-
- std::ostringstream tmp_string;
- CORBA::Long nb_nodes = params.nb_proc;
- tmp_string << nb_nodes;
- std::string nbproc = tmp_string.str();
-
- Engines::MachineParameters_var rtn = new Engines::MachineParameters();
- rtn->container_name = params.container_name;
- rtn->hostname = params.hostname;
- rtn->OS = params.OS;
- rtn->mem_mb = params.mem_mb;
- rtn->cpu_clock = params.cpu_clock;
- rtn->nb_proc_per_node = params.nb_proc_per_node;
- rtn->nb_node = params.nb_node;
- rtn->nb_proc = params.nb_proc;
- rtn->isMPI = params.isMPI;
-
- // Step 1 : local or remote launch ?
- if (hostname != std::string(Kernel_Utils::GetHostname()) )
- {
- MESSAGE("[BuildCommandToLaunchParallelContainer] remote machine case detected !");
- remote = true;
- }
-
- // Step 2 : proxy or nodes launch ?
- std::string::size_type loc_proxy = exe_name.find("Proxy");
- if( loc_proxy != string::npos ) {
- is_a_proxy = true;
- }
-
- // Step 3 : Depending of the parallelLib, getting the machine file
- // ParallelLib Dummy has is own machine for this method
- if (remote)
- {
- if (is_a_proxy)
- {
- machine_file_name = _ResManager->getMachineFile(hostname,
- 1,
- parallelLib);
- }
- else
- {
- machine_file_name = _ResManager->getMachineFile(hostname,
- params.nb_proc,
- parallelLib);
- }
- if (machine_file_name == "")
- {
- INFOS("[BuildCommandToLaunchParallelContainer] Error machine_file was not generated for machine " << hostname);
- throw SALOME_Exception("Error machine_file was not generated");
- }
- MESSAGE("[BuildCommandToLaunchParallelContainer] machine_file_name is : " << machine_file_name);
- }
-
- // Step 4 : Log type choosen by the user
- std::string log_env("");
- char * get_val = getenv("PARALLEL_LOG");
- if (get_val)
- log_env = get_val;
- std::string command_begin("");
- std::string command_end("");
- if(log_env == "xterm")
- {
- command_begin = "/usr/X11R6/bin/xterm -e \"export LD_LIBRARY_PATH=$LD_LIBRARY_PATH; export PATH=$PATH;";
- command_end = "\"&";
- }
- else if(log_env == "xterm_debug")
- {
- command_begin = "/usr/X11R6/bin/xterm -e \"export LD_LIBRARY_PATH=$LD_LIBRARY_PATH; export PATH=$PATH;";
- command_end = "; cat \" &";
- }
- else
- {
- // default into a file...
- std::string logFilename = "/tmp/" + _NS->ContainerName(params) + "_" + hostname;
- if (is_a_proxy)
- logFilename += "_Proxy_";
- else
- logFilename += "_Node_";
- logFilename += std::string(getenv("USER")) + ".log";
- command_end = " > " + logFilename + " 2>&1 & ";
- }
- // Step 5 : Building the command
- std::string command("");
- if (parallelLib == "Dummy")
- {
- if (is_a_proxy)
- {
- std::string command_remote("");
- if (remote)
- {
- std::string machine_name;
- std::ifstream machine_file(machine_file_name.c_str());
- std::getline(machine_file, machine_name);
- MESSAGE("[BuildCommandToLaunchParallelContainer] machine file name extracted is " << machine_name)
-
- // We want to launch a command like :
- // ssh -l user machine distantPath/runRemote.sh hostNS portNS
- const ParserResourcesType& resInfo = _ResManager->GetImpl()->GetResourcesList(machine_name);
- if (resInfo.Protocol == rsh)
- command_remote = "rsh ";
- else
- command_remote = "ssh ";
- command_remote += "-l ";
- command_remote += resInfo.UserName;
- command_remote += " ";
- command_remote += machine_name;
- command_remote += " ";
- command_remote += resInfo.AppliPath; // path relative to user@machine $HOME
- command_remote += "/runRemote.sh ";
- ASSERT(getenv("NSHOST"));
- command_remote += getenv("NSHOST"); // hostname of CORBA name server
- command_remote += " ";
- ASSERT(getenv("NSPORT"));
- command_remote += getenv("NSPORT"); // port of CORBA name server
- command_remote += " ";
-
- hostname = machine_name;
- }
-
- command = real_exe_name;
- command += " " + _NS->ContainerName(rtn);
- command += " " + parallelLib;
- command += " " + hostname;
- command += " " + nbproc;
- command += " -";
- AddOmninamesParams(command);
-
- command = command_begin + command_remote + command + command_end;
- vect_machine.push_back(hostname);
- }
- else
- {
- std::ifstream * machine_file = NULL;
- if (remote)
- machine_file = new std::ifstream(machine_file_name.c_str());
- for (int i= 0; i < nb_nodes; i++)
- {
- std::string command_remote("");
- if (remote)
- {
- std::string machine_name;
- std::getline(*machine_file, machine_name);
- MESSAGE("[BuildCommandToLaunchParallelContainer] machine file name extracted is " << machine_name)
-
- // We want to launch a command like :
- // ssh -l user machine distantPath/runRemote.sh hostNS portNS
- const ParserResourcesType& resInfo = _ResManager->GetImpl()->GetResourcesList(machine_name);
- if (resInfo.Protocol == rsh)
- command_remote = "rsh ";
- else
- command_remote = "ssh ";
- command_remote += "-l ";
- command_remote += resInfo.UserName;
- command_remote += " ";
- command_remote += machine_name;
- command_remote += " ";
- command_remote += resInfo.AppliPath; // path relative to user@machine $HOME
- command_remote += "/runRemote.sh ";
- ASSERT(getenv("NSHOST"));
- command_remote += getenv("NSHOST"); // hostname of CORBA name server
- command_remote += " ";
- ASSERT(getenv("NSPORT"));
- command_remote += getenv("NSPORT"); // port of CORBA name server
- command_remote += " ";
-
- hostname = machine_name;
- }
-
- std::ostringstream tmp;
- tmp << i;
- std::string proc_number = tmp.str();
-
- std::string command_tmp("");
- command_tmp += real_exe_name;
- command_tmp += " " + _NS->ContainerName(rtn);
- command_tmp += " " + parallelLib;
- command_tmp += " " + proxy_hostname;
- command_tmp += " " + proc_number;
- command_tmp += " -";
- AddOmninamesParams(command_tmp);
-
- // On change _Node_ par _Nodex_ pour avoir chaque noeud
- // sur un fichier
- std::string command_end_tmp = command_end;
- std::string::size_type loc_node = command_end_tmp.find("_Node_");
- if (loc_node != std::string::npos)
- command_end_tmp.insert(loc_node+5, proc_number);
- command += command_begin + command_remote + command_tmp + command_end_tmp;
- vect_machine.push_back(hostname);
- }
- if (machine_file)
- delete machine_file;
- }
- }
- else if (parallelLib == "Mpi")
- {
- // Step 0: if remote we have to copy the file
- // to the first machine of the file
- std::string remote_machine("");
- if (remote)
- {
- std::ifstream * machine_file = NULL;
- machine_file = new std::ifstream(machine_file_name.c_str());
- // Get first word of the line
- // For MPI implementation the first word is the
- // machine name
- std::getline(*machine_file, remote_machine, ' ');
- machine_file->close();
- MESSAGE("[BuildCommandToLaunchParallelContainer] machine file name extracted is " << remote_machine)
-
- // We want to launch a command like :
- // scp mpi_machine_file user@machine:Path
- std::string command_remote("");
- const ParserResourcesType& resInfo = _ResManager->GetImpl()->GetResourcesList(remote_machine);
- if (resInfo.Protocol == rsh)
- command_remote = "rcp ";
- else
- command_remote = "scp ";
-
- command_remote += machine_file_name;
- command_remote += " ";
- command_remote += resInfo.UserName;
- command_remote += "@";
- command_remote += remote_machine;
- command_remote += ":";
- command_remote += machine_file_name;
-
- int status = system(command_remote.c_str());
- if (status == -1)
- {
- INFOS("copy of the mpi machine file failed !");
- return "";
- }
- }
-
- if (is_a_proxy)
- {
- std::string command_remote("");
- if (remote)
- {
- // We want to launch a command like :
- // ssh -l user machine distantPath/runRemote.sh hostNS portNS
- const ParserResourcesType& resInfo = _ResManager->GetImpl()->GetResourcesList(remote_machine);
- if (resInfo.Protocol == rsh)
- command_remote = "rsh ";
- else
- command_remote = "ssh ";
- command_remote += "-l ";
- command_remote += resInfo.UserName;
- command_remote += " ";
- command_remote += remote_machine;
- command_remote += " ";
- command_remote += resInfo.AppliPath; // path relative to user@machine $HOME
- command_remote += "/runRemote.sh ";
- ASSERT(getenv("NSHOST"));
- command_remote += getenv("NSHOST"); // hostname of CORBA name server
- command_remote += " ";
- ASSERT(getenv("NSPORT"));
- command_remote += getenv("NSPORT"); // port of CORBA name server
- command_remote += " ";
-
- hostname = remote_machine;
- }
-
- // We use Dummy proxy for MPI parallel containers
- real_exe_name = exe_name + "Dummy";
- command = real_exe_name;
- command += " " + _NS->ContainerName(rtn);
- command += " Dummy";
- command += " " + hostname;
- command += " " + nbproc;
- command += " -";
- AddOmninamesParams(command);
-
- command = command_begin + command_remote + command + command_end;
- vect_machine.push_back(hostname);
- }
- else
- {
- std::string command_remote("");
- if (remote)
- {
- const ParserResourcesType& resInfo = _ResManager->GetImpl()->GetResourcesList(remote_machine);
- if (resInfo.Protocol == rsh)
- command_remote = "rsh ";
- else
- command_remote = "ssh ";
- command_remote += "-l ";
- command_remote += resInfo.UserName;
- command_remote += " ";
- command_remote += remote_machine;
- command_remote += " ";
-
- std::string new_real_exe_name("");
- new_real_exe_name += resInfo.AppliPath; // path relative to user@machine $HOME
- new_real_exe_name += "/runRemote.sh ";
- ASSERT(getenv("NSHOST"));
- new_real_exe_name += getenv("NSHOST"); // hostname of CORBA name server
- new_real_exe_name += " ";
- ASSERT(getenv("NSPORT"));
- new_real_exe_name += getenv("NSPORT"); // port of CORBA name server
- new_real_exe_name += " ";
+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;
+}
- real_exe_name = new_real_exe_name + real_exe_name;
- hostname = remote_machine;
- }
+std::string
+SALOME_ContainerManager::BuildCommandToLaunchPaCOProxyContainer(const Engines::ContainerParameters& params,
+ std::string machine_file_name,
+ std::string & proxy_hostname)
+{
+ return "";
+}
- const ParserResourcesType& resInfo = _ResManager->GetImpl()->GetResourcesList(hostname);
- if (resInfo.mpi == lam)
- {
- command = "mpiexec -ssi boot ";
- if (resInfo.Protocol == rsh)
- command += "rsh ";
- else
- command += "ssh ";
- command += "-machinefile " + machine_file_name + " ";
- command += "-n " + nbproc + " ";
- command += real_exe_name;
- command += " " + _NS->ContainerName(rtn);
- command += " " + parallelLib;
- command += " " + proxy_hostname;
- command += " -";
- AddOmninamesParams(command);
- }
- else
- {
- command = "mpirun -np " + nbproc + " ";
- command += real_exe_name;
- command += " " + _NS->ContainerName(rtn);
- command += " " + parallelLib;
- command += " " + proxy_hostname;
- command += " -";
- AddOmninamesParams(command);
- }
+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)
+{
+}
- command = command_begin + command_remote + command + command_end;
- for (int i= 0; i < nb_nodes; i++)
- vect_machine.push_back(proxy_hostname);
- }
- }
- else
- {
- std::string message("Unknown parallelLib : " + parallelLib);
- throw SALOME_Exception(message.c_str());
- }
+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;
+}
- MESSAGE("Parallel launch is: " << command);
- return command;
+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