From: YOANN AUDOUIN Date: Thu, 7 Sep 2023 08:25:11 +0000 (+0200) Subject: Adding walltime for multinode + keeping temporary folder with environement variable X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=9cefcee9ddfafe416308414984b8034a042de533;p=modules%2Fsmesh.git Adding walltime for multinode + keeping temporary folder with environement variable --- diff --git a/idl/SMESH_Mesh.idl b/idl/SMESH_Mesh.idl index 81c472b79..8ef9a454b 100644 --- a/idl/SMESH_Mesh.idl +++ b/idl/SMESH_Mesh.idl @@ -1128,6 +1128,9 @@ module SMESH string GetWcKey(); void SetWcKey(in string wcKey); + + string GetWalltime(); + void SetWalltime(in string walltime); }; }; diff --git a/src/SMESH/SMESH_Gen.cxx b/src/SMESH/SMESH_Gen.cxx index f5bff5058..deab14abc 100644 --- a/src/SMESH/SMESH_Gen.cxx +++ b/src/SMESH/SMESH_Gen.cxx @@ -453,6 +453,9 @@ bool SMESH_Gen::parallelComputeSubMeshes( aMesh.GetMeshDS()->Modified(); + // Cleanup done here as in Python the destructor is not called + aParMesh.cleanup(); + return ret; #endif }; diff --git a/src/SMESH/SMESH_ParallelMesh.cxx b/src/SMESH/SMESH_ParallelMesh.cxx index ef75ab21f..237dad6be 100644 --- a/src/SMESH/SMESH_ParallelMesh.cxx +++ b/src/SMESH/SMESH_ParallelMesh.cxx @@ -43,12 +43,6 @@ namespace fs=boost::filesystem; #include -#ifdef _DEBUG_ -static int MYDEBUG = 1; -#else -static int MYDEBUG = 0; -#endif - SMESH_ParallelMesh::SMESH_ParallelMesh(int theLocalId, SMESH_Gen* theGen, bool theIsEmbeddedMode, @@ -62,12 +56,47 @@ SMESH_ParallelMesh::SMESH_ParallelMesh(int theLocalId, }; SMESH_ParallelMesh::~SMESH_ParallelMesh() +{ + cleanup(); +}; + +void SMESH_ParallelMesh::cleanup() { DeletePoolThreads(); - if(!MYDEBUG) + std::cout << "Keeping tmp folder" << keepingTmpFolfer() << std::endl; + if(!keepingTmpFolfer()) + { + MESSAGE("Set SMESH_KEEP_TMP to > 0 to keep temporary folders") DeleteTmpFolder(); + } }; +//============================================================================= +/*! + * \brief Checking if we should keep the temporary folder + * They are kept if the variable SMESH_KEEP_TMP is set to higher than 0 + */ +//============================================================================= +bool SMESH_ParallelMesh::keepingTmpFolfer() +{ + const char* envVar = std::getenv("SMESH_KEEP_TMP"); + std::cout << "smesh_keep_tmp: " << envVar << std::endl; + + if (envVar && (envVar[0] != '\0')) + { + try + { + const long long numValue = std::stoll(envVar); + return numValue > 0; + } + catch(const std::exception& e) + { + std::cerr << e.what() << '\n'; + } + } + + return false; +}; //============================================================================= @@ -92,6 +121,7 @@ void SMESH_ParallelMesh::CreateTmpFolder() void SMESH_ParallelMesh::DeleteTmpFolder() { #ifndef WIN32 + MESSAGE("Deleting temporary folder" << tmp_folder.string()); fs::remove_all(tmp_folder); #endif } diff --git a/src/SMESH/SMESH_ParallelMesh.hxx b/src/SMESH/SMESH_ParallelMesh.hxx index 7deb3210c..a531bdb85 100644 --- a/src/SMESH/SMESH_ParallelMesh.hxx +++ b/src/SMESH/SMESH_ParallelMesh.hxx @@ -46,7 +46,7 @@ class SMESH_EXPORT SMESH_ParallelMesh: public SMESH_Mesh bool theIsEmbeddedMode, SMESHDS_Document* theDocument); - virtual ~SMESH_ParallelMesh(); + ~SMESH_ParallelMesh(); // Locking mechanism void Lock() override {_my_lock.lock();}; @@ -66,9 +66,11 @@ class SMESH_EXPORT SMESH_ParallelMesh: public SMESH_Mesh int GetPoolNbThreads(); // Temporary folder + bool keepingTmpFolfer(); void CreateTmpFolder(); void DeleteTmpFolder(); boost::filesystem::path GetTmpFolder() {return tmp_folder;}; + void cleanup(); // bool IsParallel() override {return true;}; @@ -97,6 +99,9 @@ class SMESH_EXPORT SMESH_ParallelMesh: public SMESH_Mesh std::string GetWcKey() {return _wcKey;}; void SetWcKey(std::string wcKey) {_wcKey = wcKey;}; + std::string GetWalltime() {return _walltime;}; + void SetWalltime(std::string walltime) {_walltime = walltime;}; + // Parallel computation bool ComputeSubMeshes( SMESH_Gen* gen, @@ -131,5 +136,6 @@ class SMESH_EXPORT SMESH_ParallelMesh: public SMESH_Mesh int _nbNode = 1; std::string _resource = ""; std::string _wcKey = "P11N0:SALOME"; + std::string _walltime = "01:00:00"; }; #endif diff --git a/src/SMESH_I/SMESH_ParallelMesh_i.cxx b/src/SMESH_I/SMESH_ParallelMesh_i.cxx index c816311b4..6e8bad1a6 100644 --- a/src/SMESH_I/SMESH_ParallelMesh_i.cxx +++ b/src/SMESH_I/SMESH_ParallelMesh_i.cxx @@ -188,3 +188,21 @@ char* SMESH_ParallelMesh_i::GetWcKey(){ void SMESH_ParallelMesh_i::SetWcKey(const char* wcKey){ DownCast()->SetWcKey(std::string(wcKey)); } + +//============================================================================= +/*! + * \brief Get the walltime to use on ressource + */ +//============================================================================= +char* SMESH_ParallelMesh_i::GetWalltime(){ + return CORBA::string_dup(DownCast()->GetWalltime().c_str()); +} + +//============================================================================= +/*! + * \brief Set the walltime to use on ressource + */ +//============================================================================= +void SMESH_ParallelMesh_i::SetWalltime(const char* walltime){ + DownCast()->SetWalltime(std::string(walltime)); +} diff --git a/src/SMESH_I/SMESH_ParallelMesh_i.hxx b/src/SMESH_I/SMESH_ParallelMesh_i.hxx index 5386dc7bb..51ae0c93f 100644 --- a/src/SMESH_I/SMESH_ParallelMesh_i.hxx +++ b/src/SMESH_I/SMESH_ParallelMesh_i.hxx @@ -71,6 +71,9 @@ class SMESH_I_EXPORT SMESH_ParallelMesh_i: char* GetWcKey(); void SetWcKey(const char* wcKey); + char* GetWalltime(); + void SetWalltime(const char* walltime); + private: ::SMESH_ParallelMesh* DownCast(); }; diff --git a/src/SMESH_SWIG/mesher_launcher.py b/src/SMESH_SWIG/mesher_launcher.py index f29e4b5a7..65de14925 100644 --- a/src/SMESH_SWIG/mesher_launcher.py +++ b/src/SMESH_SWIG/mesher_launcher.py @@ -22,7 +22,6 @@ """ File to run mesher from command line """ -#TODO: Make the execution path independant (output files are written in current directory) from os import environ, path import sys import subprocess as sp @@ -157,6 +156,7 @@ def run_pylauncher(args): job_params.resource_required.nb_proc = args.nb_proc job_params.resource_required.nb_proc_per_node = args.nb_proc_per_node job_params.resource_required.nb_node = args.nb_node + job_params.maximum_duration = args.walltime # job_params.pre_command = pre_command # command to run on frontal # script to run in batch mode @@ -241,6 +241,13 @@ def run_pylauncher(args): launcher.getJobResults(job_id, "") # Delete remote working dir + del_tmp_folder = True + try: + val = int(environ.get("SMESH_KEEP_TMP", "0")) + del_tmp_folder = val > 0 + except Exception as e: + del_tmp_folder = True + launcher.clearJobWorkingDir(job_id) def def_arg(): @@ -291,6 +298,9 @@ def def_arg(): default=1, type=int, help="Number of node") + run_param.add_argument("--walltime", + default="01:00:00", + help="walltime for job submission HH:MM:SS (default 01:00:00)") run_param.add_argument("--wc-key", default="P11N0:SALOME", help="wc-key for job submission (default P11N0:SALOME)") diff --git a/src/SMESH_SWIG/smeshBuilder.py b/src/SMESH_SWIG/smeshBuilder.py index 5fe13bd85..781137a69 100644 --- a/src/SMESH_SWIG/smeshBuilder.py +++ b/src/SMESH_SWIG/smeshBuilder.py @@ -7755,6 +7755,14 @@ class MNParallelismSettings(ParallelismSettings): """ Get Number of Node """ return self._mesh.mesh.GetWcKey() + def SetWalltime(self, walltime): + """ Set the number of Node for multinode """ + self._mesh.mesh.SetWalltime(walltime) + + def GetWalltime(self): + """ Get Number of Node """ + return self._mesh.mesh.GetWalltime() + def __str__(self): """ str conversion """ string = "\nParameter for MultiNode parallelism:\n" @@ -7763,6 +7771,7 @@ class MNParallelismSettings(ParallelismSettings): string += "NbProcPerNode: {}\n".format(self.GetNbProcPerNode()) string += "NbNode: {}\n".format(self.GetNbNode()) string += "WcKey: {}\n".format(self.GetWcKey()) + string += "Walltime: {}\n".format(self.GetWalltime()) return string