Adding support of number of thread for the mesher

This commit is contained in:
Yoann Audouin 2022-09-13 09:48:51 +02:00
parent 9c3bd8e9d1
commit a71af09b16
5 changed files with 27 additions and 14 deletions

View File

@ -222,7 +222,7 @@ void NETGENPlugin_NETGEN_3D::FillParameters(const NETGENPlugin_Hypothesis* hyp,
aParams.meshsizefilename = hyp->GetMeshSizeFile(); aParams.meshsizefilename = hyp->GetMeshSizeFile();
#else #else
// const char* // const char*
aParams.meshsizefilename = hyp->GetMeshSizeFile().empty() ? 0 : hyp->GetMeshSizeFile().c_str(); aParams.meshsizefilename = hyp->GetMeshSizeFile();
#endif #endif
#ifdef NETGEN_V6 #ifdef NETGEN_V6
aParams.closeedgefac = 2; aParams.closeedgefac = 2;
@ -353,6 +353,7 @@ int NETGENPlugin_NETGEN_3D::RemoteCompute(SMESH_Mesh& aMesh,
+ shape_file.string() + " " + shape_file.string() + " "
+ param_file.string() + " " + param_file.string() + " "
+ element_orientation_file.string() + " " + element_orientation_file.string() + " "
+ std::to_string(aMesh.GetMesherNbThreads()) + " "
+ new_element_file.string() + " " + new_element_file.string() + " "
+ std::to_string(0) + " " + std::to_string(0) + " "
+ output_mesh_file.string() + + output_mesh_file.string() +

View File

@ -129,8 +129,8 @@ void set_netgen_parameters(netgen_params& aParams)
#ifdef NETGEN_V6 #ifdef NETGEN_V6
//netgen::mparam.nthreads = std::thread::hardware_concurrency(); //netgen::mparam.nthreads = std::thread::hardware_concurrency();
netgen::mparam.nthreads = 2; netgen::mparam.nthreads = aParams.nbThreads;
//netgen::mparam.parallel_meshing = false; netgen::mparam.parallel_meshing = aParams.nbThreads > 1;
if ( getenv( "SALOME_NETGEN_DISABLE_MULTITHREADING" )) if ( getenv( "SALOME_NETGEN_DISABLE_MULTITHREADING" ))
@ -165,7 +165,7 @@ void set_netgen_parameters(netgen_params& aParams)
#else #else
// const char* // const char*
netgen::mparam.meshsizefilename= aParams.meshsizefilename ? 0 : aParams.meshsizefilename.c_str(); netgen::mparam.meshsizefilename= aParams.meshsizefilename.empty() ? 0 : aParams.meshsizefilename.c_str();
#endif #endif
} }
@ -187,7 +187,8 @@ int netgen3d(const std::string input_mesh_file,
const std::string element_orientation_file, const std::string element_orientation_file,
const std::string new_element_file, const std::string new_element_file,
bool output_mesh, 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(); auto time0 = std::chrono::high_resolution_clock::now();
// Importing mesh // Importing mesh
@ -216,6 +217,8 @@ int netgen3d(const std::string input_mesh_file,
auto time3 = std::chrono::high_resolution_clock::now(); auto time3 = std::chrono::high_resolution_clock::now();
elapsed = std::chrono::duration_cast<std::chrono::nanoseconds>(time3-time2); elapsed = std::chrono::duration_cast<std::chrono::nanoseconds>(time3-time2);
std::cout << "Time for import_netgen_param: " << elapsed.count() * 1e-9 << std::endl; 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; std::cout << "Meshing with netgen3d" << std::endl;
int ret = netgen3d_internal(myShape, *myMesh, myParams, 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; return true;
} }

View File

@ -62,7 +62,8 @@ int netgen3d(const std::string input_mesh_file,
const std::string element_orienation_file, const std::string element_orienation_file,
const std::string new_element_file, const std::string new_element_file,
bool output_mesh, 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 //TODO: Tmp function replace by real error handling
int error(int error_type, std::string msg); int error(int error_type, std::string msg);

View File

@ -81,6 +81,9 @@ struct netgen_params{
// Params from NETGEN2D // Params from NETGEN2D
bool has_LengthFromEdges_hyp=false; bool has_LengthFromEdges_hyp=false;
// Number of threads for the mesher
int nbThreads;
}; };
void print_netgen_params(netgen_params& aParams); void print_netgen_params(netgen_params& aParams);

View File

@ -163,7 +163,8 @@ void test_netgen3d(){
"element_orient.dat", "element_orient.dat",
"new_element.dat", "new_element.dat",
true, true,
"box_with3D.med"); "box_with3D.med",
1);
// TODO: Check result // TODO: Check result
} }
@ -178,11 +179,12 @@ void test_netgen3d(){
*/ */
int main(int argc, char *argv[]){ 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"<<std::endl; std::cout << "Error in number of argument"<<std::endl;
std::cout << "Syntax:"<<std::endl; std::cout << "Syntax:"<<std::endl;
std::cout << "run_mesher MESHER INPUT_MESH_FILE SHAPE_FILE HYPO_FILE" << std::endl; std::cout << "run_mesher MESHER INPUT_MESH_FILE SHAPE_FILE HYPO_FILE" << std::endl;
std::cout << " ELEM_ORIENT_FILE NEW_ELEMENT_FILE OUTPUT_MESH_FILE" << std::endl; std::cout << " ELEM_ORIENT_FILE NB_THREADS" << std::endl;
std::cout << " NEW_ELEMENT_FILE OUTPUT_MESH_FILE" << std::endl;
std::cout << std::endl; std::cout << std::endl;
std::cout << "Args:" << std::endl; std::cout << "Args:" << std::endl;
std::cout << " MESHER: mesher to use from (NETGEN3D, NETGEN2D)" << std::endl; std::cout << " MESHER: mesher to use from (NETGEN3D, NETGEN2D)" << std::endl;
@ -190,6 +192,7 @@ int main(int argc, char *argv[]){
std::cout << " SHAPE_FILE: STEP file containing the shape to mesh" << std::endl; std::cout << " SHAPE_FILE: STEP file containing the shape to mesh" << std::endl;
std::cout << " HYPO_FILE: Ascii file containint the list of parameters" << std::endl; std::cout << " HYPO_FILE: Ascii file containint the list of parameters" << std::endl;
std::cout << " ELEM_ORIENT_FILE: binary file containing the list of element from INPUT_MESH_FILE associated to the shape and their orientation" << std::endl; std::cout << " ELEM_ORIENT_FILE: binary file containing the list of element from INPUT_MESH_FILE associated to the shape and their orientation" << std::endl;
std::cout << " NB_THREADS: Number of thread to use for the mesher" << std::endl;
std::cout << " NEW_ELEMENT_FILE: (out) contains elements and nodes added by the meshing" << std::endl; std::cout << " NEW_ELEMENT_FILE: (out) contains elements and nodes added by the meshing" << std::endl;
std::cout << " OUTPUT_MESH: If !=0 will export mesh into OUTPUT_MESH_FILE " << std::endl; std::cout << " OUTPUT_MESH: If !=0 will export mesh into OUTPUT_MESH_FILE " << std::endl;
std::cout << " OUTPUT_MESH_FILE: MED File containing the mesh after the run of the mesher" << std::endl; std::cout << " OUTPUT_MESH_FILE: MED File containing the mesh after the run of the mesher" << std::endl;
@ -200,9 +203,10 @@ int main(int argc, char *argv[]){
std::string shape_file=argv[3]; std::string shape_file=argv[3];
std::string hypo_file=argv[4]; std::string hypo_file=argv[4];
std::string element_orientation_file=argv[5]; std::string element_orientation_file=argv[5];
std::string new_element_file=argv[6]; int nbThreads=std::stoi(argv[6]);
bool output_mesh = std::stoi(argv[7]) != 0; std::string new_element_file=argv[7];
std::string output_mesh_file=argv[8]; bool output_mesh = std::stoi(argv[8]) != 0;
std::string output_mesh_file=argv[9];
if (mesher=="test"){ if (mesher=="test"){
std::cout << "Running tests" << std::endl; std::cout << "Running tests" << std::endl;
@ -218,7 +222,8 @@ int main(int argc, char *argv[]){
element_orientation_file, element_orientation_file,
new_element_file, new_element_file,
output_mesh, output_mesh,
output_mesh_file); output_mesh_file,
nbThreads);
auto end = std::chrono::high_resolution_clock::now(); auto end = std::chrono::high_resolution_clock::now();
auto elapsed = std::chrono::duration_cast<std::chrono::nanoseconds>(end - begin); auto elapsed = std::chrono::duration_cast<std::chrono::nanoseconds>(end - begin);
std::cout << "Time elapsed: " << elapsed.count()*1e-9 << std::endl; std::cout << "Time elapsed: " << elapsed.count()*1e-9 << std::endl;