From 946ce605816bdb3ed3ce26f3d65e04f7b1ba23dc Mon Sep 17 00:00:00 2001 From: rahuel Date: Tue, 5 Jun 2007 07:51:58 +0000 Subject: [PATCH] improvement for batch on ccrt --- bin/launchConfigureParser.py | 14 + bin/runSalome.py | 9 +- idl/SALOME_ContainerManager.idl | 10 + resources/CatalogResources.xml.in | 67 ++-- salome_adm/unix/config_files/check_mpi.m4 | 10 +- src/Container/Makefile.am | 6 +- src/Container/SALOME_ContainerManager.cxx | 124 ++++++- src/Container/SALOME_ContainerManager.hxx | 18 +- src/LifeCycleCORBA/SALOME_LifeCycleCORBA.cxx | 17 +- .../SALOME_ResourcesManager.cxx | 350 ++++++++++++++++++ .../SALOME_ResourcesManager.hxx | 18 + 11 files changed, 597 insertions(+), 46 deletions(-) diff --git a/bin/launchConfigureParser.py b/bin/launchConfigureParser.py index ac9b89fd9..112908c02 100755 --- a/bin/launchConfigureParser.py +++ b/bin/launchConfigureParser.py @@ -48,6 +48,7 @@ key_nam = "key" interp_nam = "interp" except_nam = "noexcepthandler" terminal_nam = "terminal" +batch_nam = "batch" # values in XML configuration file giving specific module parameters ( section) # which are stored in opts with key _ (eg SMESH_plugins) @@ -307,6 +308,13 @@ def CreateOptionParser (theAdditionalOptions=[]): dest="gui", help=help_str) + help_str = "Launch in Batch Mode. (Without GUI on batch machine)" + o_b = optparse.Option("-b", + "--batch", + action="store_true", + dest="batch", + help=help_str) + help_str = "Launch in GUI mode [default]." o_g = optparse.Option("-g", "--gui", @@ -489,6 +497,7 @@ def CreateOptionParser (theAdditionalOptions=[]): # All options opt_list = [o_t,o_g, # GUI/Terminal o_d,o_o, # Desktop + o_b, # Batch o_l,o_f, # Use logger or log-file o_u, # Execute python scripts o_r, # Configuration XML file @@ -671,9 +680,14 @@ def get_env(theAdditionalOptions=[], appname="SalomeApp"): # GUI/Terminal, Desktop, Splash, STUDY_HDF args["session_gui"] = False + args[batch_nam] = False args["study_hdf"] = None + print 'launchConfigureParser cmd_opts',cmd_opts if cmd_opts.gui is not None: args[gui_nam] = cmd_opts.gui + if cmd_opts.batch is not None: + args[batch_nam] = True + print 'launchConfigureParser args[',batch_nam,']',args[batch_nam] if args[gui_nam]: args["session_gui"] = True if cmd_opts.desktop is not None: diff --git a/bin/runSalome.py b/bin/runSalome.py index 1aa76c4c6..886ada9f8 100755 --- a/bin/runSalome.py +++ b/bin/runSalome.py @@ -149,6 +149,10 @@ def set_env(args, modules_list, modules_root_dir): python_version="python%d.%d" % sys.version_info[0:2] modules_root_dir_list = [] + os.putenv('SALOME_BATCH','0') + if args["batch"] : + os.putenv('SALOME_BATCH','1') + print 'SALOME_BATCH :',os.getenv('SALOME_BATCH') if args["gui"] : modules_list = modules_list[:] + ["GUI"] modules_list = modules_list[:] + ["KERNEL"] @@ -712,7 +716,7 @@ def startSalome(args, modules_list, modules_root_dir): # attente de la disponibilite du Container C++ local dans le Naming Service # - if ('cppContainer' in args['standalone']) | (args["gui"] == 0): + if ('cppContainer' in args['standalone']) : myServer=ContainerCPPServer(args) myServer.run() clt.waitNSPID("/Containers/" + theComputer + "/FactoryServer",myServer.PID) @@ -859,6 +863,7 @@ def useSalome(args, modules_list, modules_root_dir): i = 0 while i < len( toimport ) : if toimport[ i ] == 'killall': + clt.showNS() killAllPorts() import sys sys.exit(0) @@ -967,6 +972,8 @@ def no_main(): def main(): """Salome launch as a main application""" import sys + print "runSalome running on ",os.getenv('HOSTNAME') + print os.environ.itervalues args, modules_list, modules_root_dir = get_config() kill_salome(args) save_config = True diff --git a/idl/SALOME_ContainerManager.idl b/idl/SALOME_ContainerManager.idl index cdd128f72..487d11b9b 100644 --- a/idl/SALOME_ContainerManager.idl +++ b/idl/SALOME_ContainerManager.idl @@ -46,6 +46,7 @@ struct MachineParameters */ typedef sequence MachineList; typedef sequence CompoList; + typedef sequence FilesToExportList; /*! exception thrown if a computer is not found in the catalog @@ -68,6 +69,15 @@ struct MachineParameters in ResPolicy policy, in CompoList componentList ); + Container GiveContainer( in MachineParameters params, + in ResPolicy policy, + in CompoList componentList ); + + long batchSalomeJob( in string fileToExecute , + in FilesToExportList filesToExport , + in long NumberOfProcessors , + in MachineParameters params ) ; + string FindFirst(in MachineList possibleComputers); MachineList GetFittingResources( in MachineParameters params, diff --git a/resources/CatalogResources.xml.in b/resources/CatalogResources.xml.in index c83cafac5..874d32492 100644 --- a/resources/CatalogResources.xml.in +++ b/resources/CatalogResources.xml.in @@ -1,48 +1,43 @@ - - - - - - - - - + + + + + + + - - - - - - - - - + + + + + + + - - - - - - - - - + + + + + + + - - - - - - - - - + + + + + + + + + + diff --git a/salome_adm/unix/config_files/check_mpi.m4 b/salome_adm/unix/config_files/check_mpi.m4 index 57b796b72..914a47949 100644 --- a/salome_adm/unix/config_files/check_mpi.m4 +++ b/salome_adm/unix/config_files/check_mpi.m4 @@ -24,6 +24,10 @@ AC_DEFUN([CHECK_MPI],[ AC_REQUIRE([AC_PROG_CC])dnl +AC_ARG_WITH(mpi_lib, + [AC_HELP_STRING([--with-mpi_lib=DIR],[directory path of MPICH lib installation])], + MPILIBREQUESTED="$withval") + AC_ARG_WITH(mpi, [AC_HELP_STRING([--with-mpi=DIR],[root directory path of MPICH installation])], MPIREQUESTED="yes",MPIREQUESTED="no") @@ -51,6 +55,10 @@ if test x"$MPIREQUESTED" = xyes; then fi fi + if test x"$MPILIBREQUESTED" != x; then + MPI_LIBS="-L$MPILIBREQUESTED" + fi + CPPFLAGS_old="$CPPFLAGS" CPPFLAGS="$MPI_INCLUDES $CPPFLAGS" AC_CHECK_HEADER(mpi.h,WITHMPI="yes",WITHMPI="no") @@ -69,7 +77,7 @@ if test x"$MPIREQUESTED" = xyes; then if test "$WITHMPI" = "yes";then mpi_ok=yes - MPI_LIBS="$MPI_LIBS -lmpi" + MPI_LIBS="$MPI_LIBS -lmpi -lmpio -lmpiCC" else mpi_ok=no fi diff --git a/src/Container/Makefile.am b/src/Container/Makefile.am index a41b9009b..3aa895380 100644 --- a/src/Container/Makefile.am +++ b/src/Container/Makefile.am @@ -64,6 +64,7 @@ COMMON_CPPFLAGS=\ @MPI_INCLUDES@ \ @CAS_CPPFLAGS@ @CAS_CXXFLAGS@ \ @QT_MT_INCLUDES@ \ + -I$(srcdir)/../Batch \ -I$(srcdir)/../Basics \ -I$(srcdir)/../SALOMELocalTrace \ -I$(srcdir)/../NamingService \ @@ -84,6 +85,7 @@ COMMON_LIBS =\ ../Utils/libOpUtil.la \ ../SALOMELocalTrace/libSALOMELocalTrace.la \ ../Basics/libSALOMEBasics.la \ + ../Batch/libSalomeBatch.la \ $(top_builddir)/idl/libSalomeIDLKernel.la\ @MPI_LIBS@ \ @CORBA_LIBS@ @@ -133,7 +135,8 @@ SALOME_Container_CPPFLAGS =\ SALOME_Container_LDADD =\ libSalomeContainer.la \ $(COMMON_LIBS) \ - ../Basics/libSALOMEBasics.la + ../Basics/libSALOMEBasics.la \ + ../Batch/libSalomeBatch.la SALOME_ContainerManagerServer_SOURCES =\ @@ -146,4 +149,5 @@ SALOME_ContainerManagerServer_LDADD =\ libSalomeContainer.la \ $(COMMON_LIBS) \ ../Basics/libSALOMEBasics.la + ../Batch/libSalomeBatch.la diff --git a/src/Container/SALOME_ContainerManager.cxx b/src/Container/SALOME_ContainerManager.cxx index 0bbea7465..0acec7e1c 100644 --- a/src/Container/SALOME_ContainerManager.cxx +++ b/src/Container/SALOME_ContainerManager.cxx @@ -26,11 +26,16 @@ #endif #include #include "Utils_CorbaException.hxx" +#include "Batch_Date.hxx" #define TIME_OUT_TO_LAUNCH_CONT 21 using namespace std; +vector SALOME_ContainerManager::_batchLaunchedContainers; + +vector::iterator SALOME_ContainerManager::_batchLaunchedContainersIter; + const char *SALOME_ContainerManager::_ContainerManagerNameInNS = "/ContainerManager"; @@ -154,10 +159,6 @@ SALOME_ContainerManager:: FindOrStartContainer(const Engines::MachineParameters& params, const Engines::MachineList& possibleComputers) { - long id; - string containerNameInNS; - char idc[3*sizeof(long)]; - Engines::Container_ptr ret = FindContainer(params,possibleComputers); if(!CORBA::is_nil(ret)) return ret; @@ -293,6 +294,106 @@ StartContainer(const Engines::MachineParameters& params, return StartContainer(params,possibleComputers,policy); } +//============================================================================= +/*! CORBA Method: + * Give a suitable Container in a list of machines + * \param params Machine Parameters required for the container + * \param possibleComputers list of machines usable for start + */ +//============================================================================= + +Engines::Container_ptr +SALOME_ContainerManager:: +GiveContainer(const Engines::MachineParameters& params, + Engines::ResPolicy policy, + const Engines::CompoList& componentList) +{ + if(strcmp(getenv("SALOME_BATCH"),"1")==0) + { + if(_batchLaunchedContainers.empty()) + fillBatchLaunchedContainers(); + return *(_batchLaunchedContainersIter++); + } + return StartContainer(params,policy,componentList); +} + + +//============================================================================= +/*! CORBA Method: + * Submit a batch job on a cluster and returns the JobId + * \param fileToExecute : .py/.exe/.sh/... to execute on the batch cluster + * \param filesToExport : to export on the batch cluster + * \param NumberOfProcessors : Number of processors needed on the batch cluster + * \param params : Constraints for the choice of the batch cluster + */ +//============================================================================= +long SALOME_ContainerManager::batchSalomeJob( + const char * fileToExecute , + const Engines::FilesToExportList& filesToExport , + const long NumberOfProcessors , + const Engines::MachineParameters& params) +{ + BEGIN_OF("SALOME_ContainerManager::batchSalomeJob"); + // Determination provisoire de l'extension .py + // Il faudra une classe dans Utils pour gerer les Path FileNames et Extensions + int lenf = strlen( fileToExecute ) ; + if ( strcmp( &fileToExecute[lenf-3] ,".py" ) == NULL ) { + int i = lenf-1 ; + while ( i >= 0 && fileToExecute[i] != '/' ) { + i -= 1 ; + } + char * FileNameToExecute = new char[lenf-4-i] ; + strncpy(FileNameToExecute , &fileToExecute[i+1] , lenf-4-i) ; + string fileNameToExecute =string( FileNameToExecute ) ; + delete FileNameToExecute ; + SCRUTE(fileNameToExecute) ; +// Le /tmp n'est pas le meme d'un noeud a un autre ===> + //string DirForTmpFiles = string("/tmp/")+string(getenv("USER"))+string("/") ; + string DirForTmpFiles = string(getenv("HOME"))+string("/Batch/") ; + Batch::Date date = Batch::Date(time(0)) ; + std::string thedate = date.str() ; + int lend = thedate.size() ; + i = 0 ; + while ( i < lend ) { + if ( thedate[i] == '/' || thedate[i] == '-' || thedate[i] == ':' ) { + thedate[i] = '_' ; + } + i++ ; + } + SCRUTE(thedate); + DirForTmpFiles += thedate ; + SCRUTE(DirForTmpFiles) ; + // Problemes avec ResourcesManager ... + // Solution pour l'instant : + // 31.05.107 : hostname : tantal + // Alias : tantale.ccc.cea.fr + Engines::CompoList aCompoList ; + Engines::MachineList aMachineList = *GetFittingResources( params , aCompoList ) ; + SCRUTE(aMachineList[0]) ; + std::string aCluster = FindFirst( aMachineList) ; + SCRUTE(aCluster) ; + //Creation of /tmp/$USER/date_hh_mn_ss/ and copy of FileNameToExecute + // and of filesToExport in that directory + _ResManager->CopyFileNamesToExecute(aCluster,DirForTmpFiles,fileToExecute,filesToExport) ; + //Creation of /tmp/$USER/date_hh_mn_ss/runSalome_'FileNameToExecute'_Batch.sh + string runSalome_Batch = _ResManager->BuildCmdrunSalomeBatch(aCluster,DirForTmpFiles,fileNameToExecute) ; + SCRUTE(runSalome_Batch) ; + //Creation of /tmp/$USER/date_hh_mn_ss/'FileNameToExecute'_Batch.sh + string FileNameToExecute_Batch = _ResManager->BuildCmdFileNameToExecute_Batch(aCluster,NumberOfProcessors,DirForTmpFiles,fileNameToExecute) ; + SCRUTE(FileNameToExecute_Batch) ; + //Creation of /tmp/$USER/date_hh_mn_ss/'FileNameToExecute'_bsub.sh + string FileNameToExecute_bsub = _ResManager->BuildCmdFileNameToExecute_bsub(aCluster,DirForTmpFiles,fileNameToExecute) ; + SCRUTE(FileNameToExecute_bsub) ; + //Launch of /tmp/$USER/date_hh_mn_ss/'FileNameToExecute'_bsub.sh on theCluster + string sshCommand = _ResManager->CmdToExecute_bsub(aCluster,DirForTmpFiles,fileNameToExecute) ; + SCRUTE(sshCommand) ; + } + else { + MESSAGE("SALOME_ContainerManager::batchSalomeJob unknown extension " << fileToExecute); + } + END_OF("SALOME_ContainerManager::batchSalomeJob"); +} + //============================================================================= /*! * @@ -405,3 +506,18 @@ Engines::MachineParameters* SALOME_ContainerManager::GetMachineParameters(const { return _ResManager->GetMachineParameters(hostname); } + +void SALOME_ContainerManager::fillBatchLaunchedContainers() +{ + _batchLaunchedContainers.clear(); + _NS->Change_Directory("/Containers"); + vector vec = _NS->list_directory_recurs(); + for(vector::iterator iter = vec.begin();iter!=vec.end();iter++){ + CORBA::Object_var obj=_NS->Resolve((*iter).c_str()); + Engines::Container_ptr cont=Engines::Container::_narrow(obj); + if(!CORBA::is_nil(cont)){ + _batchLaunchedContainers.push_back(cont); + } + } + _batchLaunchedContainersIter=_batchLaunchedContainers.begin(); +} diff --git a/src/Container/SALOME_ContainerManager.hxx b/src/Container/SALOME_ContainerManager.hxx index 42f727c12..4bacf2c34 100644 --- a/src/Container/SALOME_ContainerManager.hxx +++ b/src/Container/SALOME_ContainerManager.hxx @@ -64,8 +64,18 @@ public: Engines::Container_ptr StartContainer(const Engines::MachineParameters& params, - Engines::ResPolicy policy, - const Engines::CompoList& componentList); + Engines::ResPolicy policy, + const Engines::CompoList& componentList); + + Engines::Container_ptr + GiveContainer(const Engines::MachineParameters& params, + Engines::ResPolicy policy, + const Engines::CompoList& componentList); + + long batchSalomeJob(const char * fileToExecute , + const Engines::FilesToExportList& filesToExport , + const long NumberOfProcessors , + const Engines::MachineParameters& params); Engines::MachineList * GetFittingResources(const Engines::MachineParameters& params, @@ -89,11 +99,15 @@ protected: FindContainer(const Engines::MachineParameters& params, const char *theMachine); + void fillBatchLaunchedContainers(); + long GetIdForContainer(void); long _id; SALOME_ResourcesManager *_ResManager; SALOME_NamingService *_NS; + static std::vector _batchLaunchedContainers; + static std::vector::iterator _batchLaunchedContainersIter; }; #endif diff --git a/src/LifeCycleCORBA/SALOME_LifeCycleCORBA.cxx b/src/LifeCycleCORBA/SALOME_LifeCycleCORBA.cxx index ab84068df..8c8de44a2 100644 --- a/src/LifeCycleCORBA/SALOME_LifeCycleCORBA.cxx +++ b/src/LifeCycleCORBA/SALOME_LifeCycleCORBA.cxx @@ -228,6 +228,21 @@ Engines::Component_ptr SALOME_LifeCycleCORBA::FindOrLoad_Component(const char *containerName, const char *componentName) { + if(strcmp(getenv("SALOME_BATCH"),"1")==0) + { + MESSAGE("SALOME_LifeCycleCORBA::FindOrLoad_Component BATCH " << containerName << " " << componentName ) ; + _NS->Change_Directory("/Containers"); + CORBA::Object_ptr obj=_NS->Resolve(containerName); + Engines::Container_var cont=Engines::Container::_narrow(obj); + bool isLoadable = cont->load_component_Library(componentName); + if (!isLoadable) return Engines::Component::_nil(); + + Engines::Component_ptr myInstance = + cont->create_component_instance(componentName, 0); + return myInstance; + } + MESSAGE("SALOME_LifeCycleCORBA::FindOrLoad_Component INTERACTIF " << containerName << " " << componentName ) ; + //#if 0 // --- Check if Component Name is known in ModuleCatalog if (! isKnownComponentClass(componentName)) @@ -264,7 +279,7 @@ SALOME_LifeCycleCORBA::FindOrLoad_Component(const char *containerName, // SCRUTE(params->isMPI); free(stContainer); return FindOrLoad_Component(params,componentName); - + //#endif } //============================================================================= diff --git a/src/ResourcesManager/SALOME_ResourcesManager.cxx b/src/ResourcesManager/SALOME_ResourcesManager.cxx index 72073dbfa..fee097901 100644 --- a/src/ResourcesManager/SALOME_ResourcesManager.cxx +++ b/src/ResourcesManager/SALOME_ResourcesManager.cxx @@ -509,6 +509,356 @@ SALOME_ResourcesManager::BuildCommandToLaunchRemoteContainer return command; } +//============================================================================= +/*! + * Copy FileNameToExecute and filesToExport in DirForTmpFiles of machine + */ +//============================================================================= +void SALOME_ResourcesManager::CopyFileNamesToExecute(const std::string& machine, + const std::string& DirForTmpFiles , + const std::string& PathFileNameToExecute , + const Engines::FilesToExportList& filesToExport) { + BEGIN_OF("SALOME_ResourcesManager::CopyFileNamesToExecute"); + const ParserResourcesType& resInfo = _resourcesList[machine]; + if (resInfo.Protocol == rsh) + { + string commandRcp; + commandRcp = "rsh "; + commandRcp += resInfo.Alias; + commandRcp += " mkdir -p "; + commandRcp += DirForTmpFiles ; + system(commandRcp.c_str()); + + commandRcp = "rcp "; + commandRcp += PathFileNameToExecute; + commandRcp += " "; + commandRcp += resInfo.Alias; + commandRcp += ":"; + commandRcp += DirForTmpFiles ; + system(commandRcp.c_str()); + + int i ; + for ( i = 0 ; i < filesToExport.length() ; i++ ) { + commandRcp = "rcp "; + commandRcp += filesToExport[i] ; + commandRcp += " "; + commandRcp += resInfo.Alias; + commandRcp += ":"; + commandRcp += DirForTmpFiles ; + system(commandRcp.c_str()); + } + } + + else if (resInfo.Protocol == ssh) + { + string commandSsh; + commandSsh = "ssh "; + commandSsh += resInfo.Alias; + commandSsh += " \"mkdir -p "; + commandSsh += DirForTmpFiles ; + commandSsh += "\"" ; + SCRUTE(commandSsh.c_str()); + system(commandSsh.c_str()); + + commandSsh = "scp "; + commandSsh += PathFileNameToExecute ; + commandSsh += " "; + commandSsh += resInfo.Alias; + commandSsh += ":"; + commandSsh += DirForTmpFiles ; + SCRUTE(commandSsh); + system(commandSsh.c_str()); + + int i ; + for ( i = 0 ; i < filesToExport.length() ; i++ ) { + commandSsh = "scp "; + commandSsh += filesToExport[i] ; + commandSsh += " "; + commandSsh += resInfo.Alias; + commandSsh += ":"; + commandSsh += DirForTmpFiles ; + SCRUTE(commandSsh); + system(commandSsh.c_str()); + } + } + else + throw SALOME_Exception("Unknown protocol"); + + END_OF("SALOME_ResourcesManager::CopyFileNamesToExecute"); +} + +//============================================================================= +/*! + * builds the shell to create for runSalome Batch on a Cluster : + * #! /bin/sh -f + * source preReqFilePath + * export PYTHONPATH=/$HOME/Batch/date_hh_mn_ss:$PYTHONPATH + * if test $SLURM_PROCID = 0; then + * runSalome --terminal --batch --modules=ListOfModules --standalone=registry,study,moduleCatalog --execute='FileNameToExecute',killall --killall + * else + * sleep 10 + * export SALOME_BATCH="1" + * SALOME_Container "YACS_Server_"${SLURM_PROCID} + * fi + * + * with preReqFilePath of CatalogResource for Salome environnement + * with ListOfModules of CatalogResource + * with FileNameToExecute as python script to execute + */ +//============================================================================= +std::string SALOME_ResourcesManager::BuildCmdrunSalomeBatch( + const std::string& machine, + const std::string& DirForTmpFiles , + const std::string& FileNameToExecute ) { + BEGIN_OF("SALOME_ResourcesManager::BuildCmdrunSalomeBatch"); + _TmpFileName = BuildTemporaryFileName(); + ofstream tempOutputFile; + tempOutputFile.open(_TmpFileName.c_str(), ofstream::out ); + const ParserResourcesType& resInfo = _resourcesList[machine]; + resInfo.Print() ; + tempOutputFile << "#! /bin/sh -f" << endl ; + tempOutputFile << "source " ; + tempOutputFile << resInfo.AppliPath << endl ; + tempOutputFile << "export PYTHONPATH=" ; + tempOutputFile << DirForTmpFiles ; + tempOutputFile << ":$PYTHONPATH" << endl ; + tempOutputFile << "if test $SLURM_PROCID = 0; then" << endl ; + tempOutputFile << " runSalome --terminal --batch --modules=" ; + int i ; + for ( i = 0 ; i < resInfo.ModulesList.size() ; i++ ) { + tempOutputFile << resInfo.ModulesList[i] ; + if ( i != resInfo.ModulesList.size()-1 ) + tempOutputFile << "," ; + } + tempOutputFile << " --standalone=registry,study,moduleCatalog --execute=" ; + tempOutputFile << FileNameToExecute ; + tempOutputFile << ",killall --killall" << endl ; + tempOutputFile << "else" << endl ; + tempOutputFile << " sleep 10" << endl ; + tempOutputFile << " export SALOME_BATCH='1'" << endl ; + tempOutputFile << " SALOME_Container 'YACS_Server_'${SLURM_PROCID}" << endl ; + tempOutputFile << "fi" << endl ; + tempOutputFile.flush(); + tempOutputFile.close(); + chmod(_TmpFileName.c_str(), 0x1ED); + SCRUTE(_TmpFileName.c_str()) ; + + if (resInfo.Protocol == rsh) + { + string commandRcp; + commandRcp = "rcp "; + commandRcp += _TmpFileName; + commandRcp += " "; + commandRcp += resInfo.Alias; + commandRcp += ":"; + commandRcp += DirForTmpFiles ; + commandRcp += "/runSalome_" ; + commandRcp += FileNameToExecute ; + commandRcp += "_Batch.sh" ; + system(commandRcp.c_str()); + RmTmpFile(); + return commandRcp; + } + + else if (resInfo.Protocol == ssh) + { + string commandSsh; + commandSsh = "scp "; + commandSsh += _TmpFileName; + commandSsh += " "; + commandSsh += resInfo.Alias; + commandSsh += ":"; + commandSsh += DirForTmpFiles ; + commandSsh += "/runSalome_" ; + commandSsh += FileNameToExecute ; + commandSsh += "_Batch.sh" ; + system(commandSsh.c_str()); + SCRUTE(commandSsh); + RmTmpFile(); + return commandSsh; + } + else + throw SALOME_Exception("Unknown protocol"); + + END_OF("SALOME_ResourcesManager::BuildCmdrunSalomeBatch"); + return string(""); +} + +//============================================================================= +/*! + * builds the shell to create for runSalome Batch on a Cluster : + * #! /bin/sh -f + * #BSUB -n NumberOfProcessors + * #BSUB -o runSalome.log%J + * mpirun -srun /$HOME/Batch/date_hh_mn_ss/runSalome_'FileNameToExecute'_Batch.sh + * with NumberOfProcessors from params + * with FileNameToExecute as python script to execute + */ +//============================================================================= +std::string SALOME_ResourcesManager::BuildCmdFileNameToExecute_Batch( + const std::string& machine, + const long NumberOfProcessors, + const std::string& DirForTmpFiles , + const std::string& FileNameToExecute ) { + BEGIN_OF("SALOME_ResourcesManager::BuildCmdFileNameToExecute_Batch"); + _TmpFileName = BuildTemporaryFileName(); + ofstream tempOutputFile; + tempOutputFile.open(_TmpFileName.c_str(), ofstream::out ); + const ParserResourcesType& resInfo = _resourcesList[machine]; + resInfo.Print() ; + tempOutputFile << "#! /bin/sh -f" << endl ; + tempOutputFile << "#BSUB -n " ; + tempOutputFile << NumberOfProcessors << endl ; + tempOutputFile << "#BSUB -o runSalome.log%J" << endl ; + tempOutputFile << "mpirun -srun " ; + tempOutputFile << DirForTmpFiles ; + tempOutputFile << "/runSalome_" ; + tempOutputFile << FileNameToExecute ; + tempOutputFile << "_Batch.sh" << endl ; + tempOutputFile.flush(); + tempOutputFile.close(); + chmod(_TmpFileName.c_str(), 0x1ED); + SCRUTE(_TmpFileName.c_str()) ; + + string commandRcp; + if (resInfo.Protocol == rsh) + { + commandRcp = "rcp "; + commandRcp += _TmpFileName; + commandRcp += " "; + commandRcp += resInfo.Alias; + commandRcp += ":"; + commandRcp += DirForTmpFiles ; + commandRcp += "/" ; + commandRcp += FileNameToExecute ; + commandRcp += "_Batch.sh" ; + system(commandRcp.c_str()); + } + + else if (resInfo.Protocol == ssh) + { + commandRcp = "scp "; + commandRcp += _TmpFileName; + commandRcp += " "; + commandRcp += resInfo.Alias; + commandRcp += ":"; + commandRcp += DirForTmpFiles ; + commandRcp += "/" ; + commandRcp += FileNameToExecute ; + commandRcp += "_Batch.sh" ; + system(commandRcp.c_str()); + } + else + throw SALOME_Exception("Unknown protocol"); + + SCRUTE(commandRcp); + RmTmpFile(); + END_OF("SALOME_ResourcesManager::BuildCmdFileNameToExecute_Batch"); + + return commandRcp; +} + +//============================================================================= +/*! + * builds the shell to create for runSalome Batch on a Cluster : + * #! /bin/sh -f + * bsub < /$HOME/Batch/date_hh_mn_ss/'FileNameToExecute'_Batch.sh & + * with preReqFilePath of CatalogResource for Salome environnement + * with ListOfModules of CatalogResource + * with FileNameToExecute as python script to execute + */ +//============================================================================= +std::string SALOME_ResourcesManager::BuildCmdFileNameToExecute_bsub( + const std::string& machine, + const std::string& DirForTmpFiles , + const std::string& FileNameToExecute ) { + BEGIN_OF("SALOME_ResourcesManager::BuildCmdFileNameToExecute_bsub"); + _TmpFileName = BuildTemporaryFileName(); + ofstream tempOutputFile; + tempOutputFile.open(_TmpFileName.c_str(), ofstream::out ); + const ParserResourcesType& resInfo = _resourcesList[machine]; + resInfo.Print() ; + tempOutputFile << "#! /bin/sh -f" << endl ; + tempOutputFile << "bsub < " ; + tempOutputFile << DirForTmpFiles ; + tempOutputFile << "/" ; + tempOutputFile << FileNameToExecute ; + tempOutputFile << "_Batch.sh &" << endl ; + tempOutputFile.flush(); + tempOutputFile.close(); + chmod(_TmpFileName.c_str(), 0x1ED); + SCRUTE(_TmpFileName.c_str()) ; + + string commandRcp; + if (resInfo.Protocol == rsh) + { + commandRcp = "rcp "; + commandRcp += _TmpFileName; + commandRcp += " "; + commandRcp += resInfo.Alias; + commandRcp += ":"; + commandRcp += DirForTmpFiles ; + commandRcp += "/" ; + commandRcp += FileNameToExecute ; + commandRcp += "_bsub.sh" ; + system(commandRcp.c_str()); + } + + else if (resInfo.Protocol == ssh) + { + commandRcp = "scp "; + commandRcp += _TmpFileName; + commandRcp += " "; + commandRcp += resInfo.Alias; + commandRcp += ":"; + commandRcp += DirForTmpFiles ; + commandRcp += "/" ; + commandRcp += FileNameToExecute ; + commandRcp += "_bsub.sh" ; + system(commandRcp.c_str()); + } + else + throw SALOME_Exception("Unknown protocol"); + + SCRUTE(commandRcp); + RmTmpFile(); + END_OF("SALOME_ResourcesManager::BuildCmdFileNameToExecute_bsub"); + + return commandRcp; +} + +//============================================================================= +/*! + * builds the rsh/ssh command for submitting of a batch job : + * ssh tantale.ccc.cea.fr /$HOME/Batch/date_hh_mn_ss/'FileNameToExecute'_bsub.sh + * with FileNameToExecute as python script to execute + */ +//============================================================================= +std::string SALOME_ResourcesManager::CmdToExecute_bsub( + const std::string& machine, + const std::string& DirForTmpFiles , + const std::string& FileNameToExecute ) { + BEGIN_OF("SALOME_ResourcesManager::CmdToExecute_bsub"); + const ParserResourcesType& resInfo = _resourcesList[machine]; + string command; + resInfo.Print() ; + + if (resInfo.Protocol == rsh) + command = "rsh " ; + else if (resInfo.Protocol == ssh) + command = "ssh "; + command += resInfo.Alias; + command += " \"tcsh " ; + command += DirForTmpFiles ; + command += "/" ; + command += FileNameToExecute ; + command += "_bsub.sh\"" ; + system(command.c_str()); + SCRUTE(command.c_str()) ; + END_OF("SALOME_ResourcesManager::CmdToExecute_bsub"); + + return command; +} //============================================================================= /*! diff --git a/src/ResourcesManager/SALOME_ResourcesManager.hxx b/src/ResourcesManager/SALOME_ResourcesManager.hxx index 5cd696156..b4a8e5cb1 100644 --- a/src/ResourcesManager/SALOME_ResourcesManager.hxx +++ b/src/ResourcesManager/SALOME_ResourcesManager.hxx @@ -76,6 +76,24 @@ class RESOURCESMANAGER_EXPORT SALOME_ResourcesManager (const std::string& machine, const Engines::MachineParameters& params, const long id); + void CopyFileNamesToExecute(const std::string& machine, + const std::string& DirForTmpFiles , + const std::string& PathFileNameToExecute , + const Engines::FilesToExportList& filesToExport) ; + std::string BuildCmdrunSalomeBatch(const std::string& machine, + const std::string& DirForTmpFiles , + const std::string& FileNameToExecute ) ; + std::string BuildCmdFileNameToExecute_Batch(const std::string& machine, + const long NumberOfProcessors, + const std::string& DirForTmpFiles , + const std::string& FileNameToExecute ) ; + std::string BuildCmdFileNameToExecute_bsub(const std::string& machine, + const std::string& DirForTmpFiles , + const std::string& FileNameToExecute ) ; + std::string CmdToExecute_bsub(const std::string& machine, + const std::string& DirForTmpFiles , + const std::string& FileNameToExecute ) ; + std::string BuildCommandToLaunchLocalContainer (const Engines::MachineParameters& params, const long id); -- 2.39.2