Salome HOME
Merge commit '9a170f0e1e02756cc5ea83e717a69ce72732f0b9'
[modules/smesh.git] / src / SMESH / SMESH_ParallelMesh.cxx
index 6d70e15a289e84aac197dbc3e8f8d949fb479530..9d61f6bd4c490d7f4bc3fdf3f7b17fa9bbe82193 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007-2023  CEA, EDF, OPEN CASCADE
+// Copyright (C) 2007-2024  CEA, EDF, OPEN CASCADE
 //
 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
   #include <windows.h>
 #endif
 
-#ifndef WIN32
 #include <boost/filesystem.hpp>
 namespace fs=boost::filesystem;
-#endif
 
 #ifndef WIN32
 #include <boost/asio.hpp>
@@ -43,12 +41,6 @@ namespace fs=boost::filesystem;
 
 #include <utilities.h>
 
-#ifdef _DEBUG_
-static int MYDEBUG = 1;
-#else
-static int MYDEBUG = 0;
-#endif
-
 SMESH_ParallelMesh::SMESH_ParallelMesh(int               theLocalId,
                        SMESH_Gen*        theGen,
                        bool              theIsEmbeddedMode,
@@ -58,21 +50,49 @@ SMESH_ParallelMesh::SMESH_ParallelMesh(int               theLocalId,
                                                                   theDocument)
 {
   MESSAGE("SMESH_ParallelMesh::SMESH_ParallelMesh(int localId)");
-#ifndef WIN32
-  _NbThreads = std::thread::hardware_concurrency();
-#else
-  _NbThreads = 0;
-#endif
   CreateTmpFolder();
 };
 
 SMESH_ParallelMesh::~SMESH_ParallelMesh()
+{
+  cleanup();
+};
+
+void SMESH_ParallelMesh::cleanup()
 {
   DeletePoolThreads();
-  if(!MYDEBUG)
+  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");
+
+  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;
+};
 
 
 //=============================================================================
@@ -82,11 +102,9 @@ SMESH_ParallelMesh::~SMESH_ParallelMesh()
 //=============================================================================
 void SMESH_ParallelMesh::CreateTmpFolder()
 {
-#ifndef WIN32
   // Temporary folder that will be used by parallel computation
   tmp_folder = fs::temp_directory_path()/fs::unique_path(fs::path("SMESH_%%%%-%%%%"));
   fs::create_directories(tmp_folder);
-#endif
 }
 //
 //=============================================================================
@@ -96,11 +114,71 @@ void SMESH_ParallelMesh::CreateTmpFolder()
 //=============================================================================
 void SMESH_ParallelMesh::DeleteTmpFolder()
 {
-#ifndef WIN32
+    MESSAGE("Deleting temporary folder" << tmp_folder.string());
     fs::remove_all(tmp_folder);
-#endif
 }
 
+//=============================================================================
+/*!
+ * \brief Get the number of Threads to be used for the pool of Threads
+ */
+//=============================================================================
+int SMESH_ParallelMesh::GetPoolNbThreads()
+{
+  int nbThreads = -1;
+
+  if(_method == ParallelismMethod::MultiThread){
+    nbThreads = _NbThreads;
+  }else if( _method == ParallelismMethod::MultiNode){
+    //TODO: Check of that is the right way
+    nbThreads = std::max(_nbProc, _nbNode*_nbProcPerNode);
+  } else {
+    throw SALOME_Exception("Unknown method "+std::to_string(_method));
+  }
+
+  return nbThreads;
+}
+
+//=============================================================================
+/*!
+ * \brief Set Number of thread for multithread run
+ */
+//=============================================================================
+void SMESH_ParallelMesh::SetNbThreads(long nbThreads)
+{
+  if(nbThreads < 1)
+    throw SALOME_Exception("Number of threads should be higher than 1");
+  _NbThreads=nbThreads;
+};
+
+//=============================================================================
+/*!
+ * \brief Get the element associated to the dimension of the parallelism
+ */
+//=============================================================================
+int SMESH_ParallelMesh::GetParallelElement()
+{
+  if (_paraDim==2){
+    return TopAbs_FACE;
+  }else{
+    return TopAbs_SOLID;
+  }
+};
+
+//=============================================================================
+/*!
+ * \brief Get the element associated to the dimension of the parallelism
+ */
+//=============================================================================
+int SMESH_ParallelMesh::GetDumpElement()
+{
+  if (_paraDim==2){
+    return TopAbs_EDGE;
+  }else{
+    return TopAbs_FACE;
+  }
+};
+
 bool SMESH_ParallelMesh::ComputeSubMeshes(
           SMESH_Gen* gen,
           SMESH_Mesh & aMesh,