Adding nnthreads as parameter for netgen

This commit is contained in:
Yoann Audouin 2022-10-03 15:46:12 +02:00
parent 54a50107a5
commit 61e4da3b0d
9 changed files with 104 additions and 43 deletions

View File

@ -147,6 +147,9 @@ module NETGENPlugin
void SetWorstElemMeasure(in short val ); void SetWorstElemMeasure(in short val );
short GetWorstElemMeasure(); short GetWorstElemMeasure();
void SetNbThreads(in short val );
short GetNbThreads();
void SetUseDelauney(in boolean toUse); void SetUseDelauney(in boolean toUse);
boolean GetUseDelauney(); boolean GetUseDelauney();

View File

@ -148,6 +148,12 @@ class NETGEN_Algorithm(Mesh_Algorithm):
if self.Parameters(): self.params.SetGrowthRate(theRate) if self.Parameters(): self.params.SetGrowthRate(theRate)
pass pass
## Sets @c NbThreads parameter
# @param theRate new value of the @c NbThreads parameter
def SetNbThreads(self, theNumber):
if self.Parameters(): self.params.SetNbThreads(theNumber)
pass
## Creates meshing hypothesis according to the chosen algorithm type ## Creates meshing hypothesis according to the chosen algorithm type
# and initializes it with default parameters # and initializes it with default parameters
# @param which hypothesis type; can be either @ref SOLE (default) or @ref SIMPLE # @param which hypothesis type; can be either @ref SOLE (default) or @ref SIMPLE

View File

@ -59,6 +59,7 @@ void printNetgenParams(netgen_params& aParams){
std::cout << "checkoverlap: " << aParams.checkoverlap << std::endl; std::cout << "checkoverlap: " << aParams.checkoverlap << std::endl;
std::cout << "checkchartboundary: " << aParams.checkchartboundary << std::endl; std::cout << "checkchartboundary: " << aParams.checkchartboundary << std::endl;
std::cout << "closeedgefac: " << aParams.closeedgefac << std::endl; std::cout << "closeedgefac: " << aParams.closeedgefac << std::endl;
std::cout << "nbThreadMesher: " << aParams.nbThreads << std::endl;
std::cout << "has_local_size: " << aParams.has_local_size << std::endl; std::cout << "has_local_size: " << aParams.has_local_size << std::endl;
std::cout << "meshsizefilename: " << aParams.meshsizefilename << std::endl; std::cout << "meshsizefilename: " << aParams.meshsizefilename << std::endl;
std::cout << "has_maxelementvolume_hyp: " << aParams.has_maxelementvolume_hyp << std::endl; std::cout << "has_maxelementvolume_hyp: " << aParams.has_maxelementvolume_hyp << std::endl;
@ -119,6 +120,8 @@ void importNetgenParams(const std::string param_file, netgen_params& aParams){
std::getline(myfile, line); std::getline(myfile, line);
aParams.closeedgefac = std::stoi(line); aParams.closeedgefac = std::stoi(line);
std::getline(myfile, line); std::getline(myfile, line);
aParams.nbThreads = std::stoi(line);
std::getline(myfile, line);
aParams.has_local_size = std::stoi(line); aParams.has_local_size = std::stoi(line);
std::getline(myfile, line); std::getline(myfile, line);
aParams.meshsizefilename = line; aParams.meshsizefilename = line;
@ -160,6 +163,7 @@ void exportNetgenParams(const std::string param_file, netgen_params& aParams){
myfile << aParams.checkoverlap << std::endl; myfile << aParams.checkoverlap << std::endl;
myfile << aParams.checkchartboundary << std::endl; myfile << aParams.checkchartboundary << std::endl;
myfile << aParams.closeedgefac << std::endl; myfile << aParams.closeedgefac << std::endl;
myfile << aParams.nbThreads << std::endl;
myfile << aParams.has_local_size << std::endl; myfile << aParams.has_local_size << std::endl;
myfile << aParams.meshsizefilename << std::endl; myfile << aParams.meshsizefilename << std::endl;
myfile << aParams.has_maxelementvolume_hyp << std::endl; myfile << aParams.has_maxelementvolume_hyp << std::endl;

View File

@ -58,6 +58,7 @@ NETGENPlugin_Hypothesis::NETGENPlugin_Hypothesis (int hypId, SMESH_Gen * gen)
_nbVolOptSteps (GetDefaultNbVolOptSteps()), _nbVolOptSteps (GetDefaultNbVolOptSteps()),
_elemSizeWeight (GetDefaultElemSizeWeight()), _elemSizeWeight (GetDefaultElemSizeWeight()),
_worstElemMeasure (GetDefaultWorstElemMeasure()), _worstElemMeasure (GetDefaultWorstElemMeasure()),
_nbThreads (GetDefaultNbThreads()),
_surfaceCurvature (GetDefaultSurfaceCurvature()), _surfaceCurvature (GetDefaultSurfaceCurvature()),
_useDelauney (GetDefaultUseDelauney()), _useDelauney (GetDefaultUseDelauney()),
_checkOverlapping (GetDefaultCheckOverlapping()), _checkOverlapping (GetDefaultCheckOverlapping()),
@ -436,6 +437,20 @@ void NETGENPlugin_Hypothesis::SetCheckChartBoundary( bool theVal )
} }
} }
//=======================================================================
//function : SetNbThreads
//purpose :
//=======================================================================
void NETGENPlugin_Hypothesis::SetNbThreads( int theVal )
{
if (theVal != _nbThreads)
{
_nbThreads = theVal;
NotifySubMeshesHypothesisModification();
}
}
//============================================================================= //=============================================================================
/*! /*!
* *

View File

@ -35,6 +35,7 @@
#include "Utils_SALOME_Exception.hxx" #include "Utils_SALOME_Exception.hxx"
#include <map> #include <map>
#include <thread>
// Parameters for work of NETGEN // Parameters for work of NETGEN
// //
@ -125,6 +126,9 @@ public:
void SetCheckChartBoundary( bool toCheck ); void SetCheckChartBoundary( bool toCheck );
bool GetCheckChartBoundary() const { return _checkChartBoundary; } bool GetCheckChartBoundary() const { return _checkChartBoundary; }
void SetNbThreads( int val );
int GetNbThreads() const { return _nbThreads; }
// the default values (taken from NETGEN 4.5 sources) // the default values (taken from NETGEN 4.5 sources)
static Fineness GetDefaultFineness() { return Moderate; } static Fineness GetDefaultFineness() { return Moderate; }
@ -145,6 +149,7 @@ public:
static bool GetDefaultCheckOverlapping() { return true; } static bool GetDefaultCheckOverlapping() { return true; }
static bool GetDefaultCheckChartBoundary(){ return true; } static bool GetDefaultCheckChartBoundary(){ return true; }
static bool GetDefaultFuseEdges() { return true; } static bool GetDefaultFuseEdges() { return true; }
static int GetDefaultNbThreads() { return std::thread::hardware_concurrency(); }
// Persistence // Persistence
virtual std::ostream & SaveTo (std::ostream & save); virtual std::ostream & SaveTo (std::ostream & save);
@ -197,6 +202,9 @@ private:
//bool _blockFilling; -- not used by netgen //bool _blockFilling; -- not used by netgen
// (SALOME additions) // (SALOME additions)
bool _fuseEdges; bool _fuseEdges;
// Parallelism parameters
int _nbThreads;
}; };
#endif #endif

View File

@ -566,6 +566,30 @@ CORBA::Short NETGENPlugin_Hypothesis_i::GetWorstElemMeasure()
return (CORBA::Short) GetImpl()->GetWorstElemMeasure(); return (CORBA::Short) GetImpl()->GetWorstElemMeasure();
} }
//=======================================================================
//function : SetNbThreads
//purpose :
//=======================================================================
void NETGENPlugin_Hypothesis_i::SetNbThreads(CORBA::Short val )
{
if ( GetNbThreads() != val )
{
this->GetImpl()->SetNbThreads( val );
SMESH::TPythonDump() << _this() << ".SetNbThreads( " << SMESH::TVar(val) << " )";
}
}
//=======================================================================
//function : GetNbThreads
//purpose :
//=======================================================================
CORBA::Short NETGENPlugin_Hypothesis_i::GetNbThreads()
{
return (CORBA::Short) GetImpl()->GetNbThreads();
}
//======================================================================= //=======================================================================
//function : SetUseDelauney //function : SetUseDelauney
//purpose : //purpose :

View File

@ -113,6 +113,9 @@ class NETGENPLUGIN_EXPORT NETGENPlugin_Hypothesis_i:
void SetWorstElemMeasure(CORBA::Short val ); void SetWorstElemMeasure(CORBA::Short val );
CORBA::Short GetWorstElemMeasure(); CORBA::Short GetWorstElemMeasure();
void SetNbThreads(CORBA::Short val );
CORBA::Short GetNbThreads();
void SetUseDelauney(CORBA::Boolean toUse); void SetUseDelauney(CORBA::Boolean toUse);
CORBA::Boolean GetUseDelauney(); CORBA::Boolean GetUseDelauney();

View File

@ -602,14 +602,13 @@ void NETGENPlugin_Mesher::SetDefaultParameters()
#ifdef NETGEN_V6 #ifdef NETGEN_V6
mparams.nthreads = std::thread::hardware_concurrency(); mparams.nthreads = NETGENPlugin_Hypothesis::GetDefaultNbThreads();
if ( getenv( "SALOME_NETGEN_DISABLE_MULTITHREADING" )) if ( getenv( "SALOME_NETGEN_DISABLE_MULTITHREADING" ))
{ {
mparams.nthreads = 1; mparams.nthreads = 1;
mparams.parallel_meshing = false; mparams.parallel_meshing = false;
} }
#endif #endif
} }
@ -655,6 +654,7 @@ void NETGENPlugin_Mesher::SetParameters(const NETGENPlugin_Hypothesis* hyp)
#ifdef NETGEN_V6 #ifdef NETGEN_V6
// std::string // std::string
mparams.meshsizefilename = hyp->GetMeshSizeFile(); mparams.meshsizefilename = hyp->GetMeshSizeFile();
mparams.nthreads = hyp->GetNbThreads();
#else #else
// const char* // const char*
mparams.meshsizefilename= hyp->GetMeshSizeFile().empty() ? 0 : hyp->GetMeshSizeFile().c_str(); mparams.meshsizefilename= hyp->GetMeshSizeFile().empty() ? 0 : hyp->GetMeshSizeFile().c_str();

View File

@ -127,13 +127,11 @@ void NETGENPlugin_NETGEN_3D_Remote::fillParameters(const NETGENPlugin_Hypothesis
#ifdef NETGEN_V6 #ifdef NETGEN_V6
// std::string // std::string
aParams.meshsizefilename = hyp->GetMeshSizeFile(); aParams.meshsizefilename = hyp->GetMeshSizeFile();
aParams.closeedgefac = 2;
aParams.nbThreads = hyp->GetNbThreads();
#else #else
// const char* // const char*
aParams.meshsizefilename = hyp->GetMeshSizeFile(); aParams.meshsizefilename = hyp->GetMeshSizeFile();
#endif
#ifdef NETGEN_V6
aParams.closeedgefac = 2;
#else
aParams.closeedgefac = 0; aParams.closeedgefac = 0;
#endif #endif
} }