Switchin to QProcess instead of sytem for remote compute

This commit is contained in:
Yoann Audouin 2022-09-15 14:06:22 +02:00
parent 2e8bc3b2b0
commit 57061f40af
2 changed files with 37 additions and 10 deletions

View File

@ -17,9 +17,12 @@
# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
# #
INCLUDE(UseQtExt)
# --- options --- # --- options ---
# additional include directories # additional include directories
INCLUDE_DIRECTORIES( INCLUDE_DIRECTORIES(
${QT_INCLUDES}
${KERNEL_INCLUDE_DIRS} ${KERNEL_INCLUDE_DIRS}
${GUI_INCLUDE_DIRS} ${GUI_INCLUDE_DIRS}
${GEOM_INCLUDE_DIRS} ${GEOM_INCLUDE_DIRS}
@ -35,6 +38,7 @@ INCLUDE_DIRECTORIES(
# additional preprocessor / compiler flags # additional preprocessor / compiler flags
ADD_DEFINITIONS( ADD_DEFINITIONS(
${QT_DEFINITIONS}
${OMNIORB_DEFINITIONS} ${OMNIORB_DEFINITIONS}
${OpenCASCADE_DEFINITIONS} ${OpenCASCADE_DEFINITIONS}
${BOOST_DEFINITIONS} ${BOOST_DEFINITIONS}
@ -66,6 +70,7 @@ SET(_link_LIBRARIES
VTK::CommonCore VTK::CommonCore
VTK::CommonDataModel VTK::CommonDataModel
SalomeIDLNETGENPLUGIN SalomeIDLNETGENPLUGIN
Qt5::Core
) )
# --- headers --- # --- headers ---

View File

@ -69,6 +69,9 @@
#include <vector> #include <vector>
#include <map> #include <map>
#include <QString>
#include <QProcess>
#include <cstdlib> #include <cstdlib>
#include <boost/filesystem.hpp> #include <boost/filesystem.hpp>
namespace fs = boost::filesystem; namespace fs = boost::filesystem;
@ -350,6 +353,7 @@ int NETGENPlugin_NETGEN_3D::RemoteCompute(SMESH_Mesh& aMesh,
fs::path("bin")/ fs::path("bin")/
fs::path("salome")/ fs::path("salome")/
fs::path("NETGENPlugin_Runner"); fs::path("NETGENPlugin_Runner");
cmd = run_mesher_exe.string() + cmd = run_mesher_exe.string() +
" NETGEN3D " + mesh_file.string() + " " " NETGEN3D " + mesh_file.string() + " "
+ shape_file.string() + " " + shape_file.string() + " "
@ -357,19 +361,36 @@ int NETGENPlugin_NETGEN_3D::RemoteCompute(SMESH_Mesh& aMesh,
+ element_orientation_file.string() + " " + element_orientation_file.string() + " "
+ std::to_string(aMesh.GetMesherNbThreads()) + " " + std::to_string(aMesh.GetMesherNbThreads()) + " "
+ new_element_file.string() + " " + new_element_file.string() + " "
+ "NONE" + + "NONE";
" >> " + log_file.string();
//std::cout << "Running command: " << std::endl;
//std::cout << cmd << std::endl;
// Writing command in log // Writing command in log
{ {
std::ofstream flog(log_file.string()); std::ofstream flog(log_file.string());
flog << cmd << endl; flog << cmd << endl;
flog << endl;
} }
// TODO: Replace system by something else to handle redirection for windows //std::cout << "Running command: " << std::endl;
int ret = system(cmd.c_str()); //std::cout << cmd << std::endl;
// Building arguments for QProcess
QString program = run_mesher_exe.c_str();
QStringList arguments;
arguments << "NETGEN3D";
arguments << mesh_file.c_str();
arguments << shape_file.c_str();
arguments << param_file.c_str();
arguments << element_orientation_file.c_str();
arguments << std::to_string(aMesh.GetMesherNbThreads()).c_str();
arguments << new_element_file.c_str();
arguments << "NONE";
QString out_file = log_file.c_str();
QProcess myProcess;
myProcess.setStandardOutputFile(out_file);
myProcess.start(program, arguments);
myProcess.waitForFinished();
int ret = myProcess.exitStatus();
auto time5 = std::chrono::high_resolution_clock::now(); auto time5 = std::chrono::high_resolution_clock::now();
elapsed = std::chrono::duration_cast<std::chrono::nanoseconds>(time5-time4); elapsed = std::chrono::duration_cast<std::chrono::nanoseconds>(time5-time4);
std::cout << "Time for exec of run_mesher: " << elapsed.count() * 1e-9 << std::endl; std::cout << "Time for exec of run_mesher: " << elapsed.count() * 1e-9 << std::endl;
@ -377,8 +398,9 @@ int NETGENPlugin_NETGEN_3D::RemoteCompute(SMESH_Mesh& aMesh,
// TODO: better error handling (display log ?) // TODO: better error handling (display log ?)
if(ret != 0){ if(ret != 0){
// Run crahed // Run crahed
std::cerr << "Issue with command: " << std::endl; std::cout << "Issue with command: " << std::endl;
std::cerr << cmd << std::endl; std::cout << "See log for more detail: " << log_file.string() << std::endl;
std::cout << cmd << std::endl;
return false; return false;
} }