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 );
short GetWorstElemMeasure();
void SetNbThreads(in short val );
short GetNbThreads();
void SetUseDelauney(in boolean toUse);
boolean GetUseDelauney();

View File

@ -148,6 +148,12 @@ class NETGEN_Algorithm(Mesh_Algorithm):
if self.Parameters(): self.params.SetGrowthRate(theRate)
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
# and initializes it with default parameters
# @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 << "checkchartboundary: " << aParams.checkchartboundary << 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 << "meshsizefilename: " << aParams.meshsizefilename << 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);
aParams.closeedgefac = std::stoi(line);
std::getline(myfile, line);
aParams.nbThreads = std::stoi(line);
std::getline(myfile, line);
aParams.has_local_size = std::stoi(line);
std::getline(myfile, 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.checkchartboundary << std::endl;
myfile << aParams.closeedgefac << std::endl;
myfile << aParams.nbThreads << std::endl;
myfile << aParams.has_local_size << std::endl;
myfile << aParams.meshsizefilename << 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()),
_elemSizeWeight (GetDefaultElemSizeWeight()),
_worstElemMeasure (GetDefaultWorstElemMeasure()),
_nbThreads (GetDefaultNbThreads()),
_surfaceCurvature (GetDefaultSurfaceCurvature()),
_useDelauney (GetDefaultUseDelauney()),
_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 <map>
#include <thread>
// Parameters for work of NETGEN
//
@ -125,6 +126,9 @@ public:
void SetCheckChartBoundary( bool toCheck );
bool GetCheckChartBoundary() const { return _checkChartBoundary; }
void SetNbThreads( int val );
int GetNbThreads() const { return _nbThreads; }
// the default values (taken from NETGEN 4.5 sources)
static Fineness GetDefaultFineness() { return Moderate; }
@ -145,6 +149,7 @@ public:
static bool GetDefaultCheckOverlapping() { return true; }
static bool GetDefaultCheckChartBoundary(){ return true; }
static bool GetDefaultFuseEdges() { return true; }
static int GetDefaultNbThreads() { return std::thread::hardware_concurrency(); }
// Persistence
virtual std::ostream & SaveTo (std::ostream & save);
@ -197,6 +202,9 @@ private:
//bool _blockFilling; -- not used by netgen
// (SALOME additions)
bool _fuseEdges;
// Parallelism parameters
int _nbThreads;
};
#endif

View File

@ -566,6 +566,30 @@ CORBA::Short NETGENPlugin_Hypothesis_i::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
//purpose :

View File

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

View File

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