From: Yoann Audouin Date: Tue, 13 Sep 2022 07:48:51 +0000 (+0200) Subject: Adding support of number of thread for the mesher X-Git-Tag: V9_10_0b1~4^2~21 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=a71af09b16a712a987d182ca3533c5903076841d;p=plugins%2Fnetgenplugin.git Adding support of number of thread for the mesher --- diff --git a/src/NETGENPlugin/NETGENPlugin_NETGEN_3D.cxx b/src/NETGENPlugin/NETGENPlugin_NETGEN_3D.cxx index 45c8171..dbe1961 100644 --- a/src/NETGENPlugin/NETGENPlugin_NETGEN_3D.cxx +++ b/src/NETGENPlugin/NETGENPlugin_NETGEN_3D.cxx @@ -222,7 +222,7 @@ void NETGENPlugin_NETGEN_3D::FillParameters(const NETGENPlugin_Hypothesis* hyp, aParams.meshsizefilename = hyp->GetMeshSizeFile(); #else // const char* - aParams.meshsizefilename = hyp->GetMeshSizeFile().empty() ? 0 : hyp->GetMeshSizeFile().c_str(); + aParams.meshsizefilename = hyp->GetMeshSizeFile(); #endif #ifdef NETGEN_V6 aParams.closeedgefac = 2; @@ -353,6 +353,7 @@ int NETGENPlugin_NETGEN_3D::RemoteCompute(SMESH_Mesh& aMesh, + shape_file.string() + " " + param_file.string() + " " + element_orientation_file.string() + " " + + std::to_string(aMesh.GetMesherNbThreads()) + " " + new_element_file.string() + " " + std::to_string(0) + " " + output_mesh_file.string() + diff --git a/src/NETGENPlugin/netgen_mesher.cxx b/src/NETGENPlugin/netgen_mesher.cxx index 0f97a07..d5d1cf1 100644 --- a/src/NETGENPlugin/netgen_mesher.cxx +++ b/src/NETGENPlugin/netgen_mesher.cxx @@ -129,8 +129,8 @@ void set_netgen_parameters(netgen_params& aParams) #ifdef NETGEN_V6 //netgen::mparam.nthreads = std::thread::hardware_concurrency(); - netgen::mparam.nthreads = 2; - //netgen::mparam.parallel_meshing = false; + netgen::mparam.nthreads = aParams.nbThreads; + netgen::mparam.parallel_meshing = aParams.nbThreads > 1; if ( getenv( "SALOME_NETGEN_DISABLE_MULTITHREADING" )) @@ -165,7 +165,7 @@ void set_netgen_parameters(netgen_params& aParams) #else // const char* - netgen::mparam.meshsizefilename= aParams.meshsizefilename ? 0 : aParams.meshsizefilename.c_str(); + netgen::mparam.meshsizefilename= aParams.meshsizefilename.empty() ? 0 : aParams.meshsizefilename.c_str(); #endif } @@ -187,7 +187,8 @@ int netgen3d(const std::string input_mesh_file, const std::string element_orientation_file, const std::string new_element_file, bool output_mesh, - const std::string output_mesh_file) + const std::string output_mesh_file, + int nbThreads) { auto time0 = std::chrono::high_resolution_clock::now(); // Importing mesh @@ -216,6 +217,8 @@ int netgen3d(const std::string input_mesh_file, auto time3 = std::chrono::high_resolution_clock::now(); elapsed = std::chrono::duration_cast(time3-time2); std::cout << "Time for import_netgen_param: " << elapsed.count() * 1e-9 << std::endl; + // Setting number of threads for netgen + myParams.nbThreads = nbThreads; std::cout << "Meshing with netgen3d" << std::endl; int ret = netgen3d_internal(myShape, *myMesh, myParams, @@ -1033,4 +1036,4 @@ int netgen2d_internal(TopoDS_Shape &aShape, SMESH_Mesh& aMesh, netgen_params& aP return true; -} \ No newline at end of file +} diff --git a/src/NETGENPlugin/netgen_mesher.hxx b/src/NETGENPlugin/netgen_mesher.hxx index b51066c..996b1ac 100644 --- a/src/NETGENPlugin/netgen_mesher.hxx +++ b/src/NETGENPlugin/netgen_mesher.hxx @@ -62,7 +62,8 @@ int netgen3d(const std::string input_mesh_file, const std::string element_orienation_file, const std::string new_element_file, bool output_mesh, - const std::string output_mesh_file); + const std::string output_mesh_file, + int nbThreads); //TODO: Tmp function replace by real error handling int error(int error_type, std::string msg); diff --git a/src/NETGENPlugin/netgen_param.hxx b/src/NETGENPlugin/netgen_param.hxx index 7919837..0958931 100644 --- a/src/NETGENPlugin/netgen_param.hxx +++ b/src/NETGENPlugin/netgen_param.hxx @@ -81,6 +81,9 @@ struct netgen_params{ // Params from NETGEN2D bool has_LengthFromEdges_hyp=false; + + // Number of threads for the mesher + int nbThreads; }; void print_netgen_params(netgen_params& aParams); diff --git a/src/NETGENPlugin/run_mesher.cxx b/src/NETGENPlugin/run_mesher.cxx index ae9c7a6..a1a1fbc 100644 --- a/src/NETGENPlugin/run_mesher.cxx +++ b/src/NETGENPlugin/run_mesher.cxx @@ -163,7 +163,8 @@ void test_netgen3d(){ "element_orient.dat", "new_element.dat", true, - "box_with3D.med"); + "box_with3D.med", + 1); // TODO: Check result } @@ -178,11 +179,12 @@ void test_netgen3d(){ */ int main(int argc, char *argv[]){ - if(argc!=9||(argc==2 && (argv[1] == "-h" || argv[1]=="--help"))){ + if(argc!=10||(argc==2 && (strcmp(argv[1], "-h") == 0 || strcmp(argv[1], "--help")==0))){ std::cout << "Error in number of argument"<(end - begin); std::cout << "Time elapsed: " << elapsed.count()*1e-9 << std::endl;