-// Copyright (C) 2007-2022 CEA/DEN, EDF R&D, 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 DISABLE_PSMESH
#include <boost/filesystem.hpp>
namespace fs=boost::filesystem;
-#endif
-#ifndef DISABLE_PSMESH
+#ifndef WIN32
#include <boost/asio.hpp>
#endif
#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,
theDocument)
{
MESSAGE("SMESH_ParallelMesh::SMESH_ParallelMesh(int localId)");
-#ifndef DISABLE_PSMESH
- _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;
+};
//=============================================================================
//=============================================================================
void SMESH_ParallelMesh::CreateTmpFolder()
{
-#ifndef DISABLE_PSMESH
// 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
}
//
//=============================================================================
//=============================================================================
void SMESH_ParallelMesh::DeleteTmpFolder()
{
-#ifndef DISABLE_PSMESH
+ 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,