fix: handle multithreaded progress messages (CURA-781)
Esse commit está contido em:
@@ -337,8 +337,6 @@ void FffPolygonGenerator::slices2polygons(SliceDataStorage& storage, TimeKeeper&
|
||||
|
||||
void FffPolygonGenerator::processBasicWallsSkinInfill(SliceDataStorage& storage, unsigned int mesh_order_idx, std::vector<unsigned int>& mesh_order, ProgressStageEstimator& inset_skin_progress_estimate)
|
||||
{
|
||||
TimeKeeper time_keeper_parallel_test;
|
||||
|
||||
unsigned int mesh_idx = mesh_order[mesh_order_idx];
|
||||
SliceMeshStorage& mesh = storage.meshes[mesh_idx];
|
||||
size_t mesh_layer_count = mesh.layers.size();
|
||||
@@ -359,18 +357,25 @@ void FffPolygonGenerator::processBasicWallsSkinInfill(SliceDataStorage& storage,
|
||||
|
||||
|
||||
// walls
|
||||
time_keeper_parallel_test.restart();
|
||||
#pragma omp parallel for default(none) shared(mesh_layer_count, mesh) schedule(dynamic)
|
||||
int processed_layer_count = 0;
|
||||
#pragma omp parallel for default(none) shared(mesh_layer_count, mesh, inset_skin_progress_estimate, processed_layer_count) schedule(dynamic)
|
||||
for(unsigned int layer_number = 0; layer_number < mesh.layers.size(); layer_number++)
|
||||
{ MULTITHREAD_FOR_CATCH_EXCEPTION(
|
||||
{
|
||||
logDebug("Processing insets for layer %i of %i\n", layer_number, mesh_layer_count);
|
||||
processInsets(mesh, layer_number);
|
||||
//TODO: Fix progress update
|
||||
//double progress = inset_skin_progress_estimate.progress(layer_number);
|
||||
//Progress::messageProgress(Progress::Stage::INSET_SKIN, progress * 100, 100);
|
||||
)}
|
||||
handleMultithreadAbort();
|
||||
log("processInsets time elapsed %5.3fs.\n", time_keeper_parallel_test.restart());
|
||||
#ifdef _OPENMP
|
||||
if (omp_get_thread_num() == 0)
|
||||
#endif
|
||||
{ // progress estimation is done only in one thread so that no two threads message progress at the same time
|
||||
int _processed_layer_count;
|
||||
#pragma omp atomic read
|
||||
_processed_layer_count = processed_layer_count;
|
||||
double progress = inset_skin_progress_estimate.progress(_processed_layer_count);
|
||||
Progress::messageProgress(Progress::Stage::INSET_SKIN, progress * 100, 100);
|
||||
}
|
||||
#pragma omp atomic
|
||||
processed_layer_count++;
|
||||
}
|
||||
|
||||
ProgressEstimatorLinear* skin_estimator = new ProgressEstimatorLinear(mesh_layer_count);
|
||||
mesh_inset_skin_progress_estimator->nextStage(skin_estimator);
|
||||
@@ -401,25 +406,32 @@ void FffPolygonGenerator::processBasicWallsSkinInfill(SliceDataStorage& storage,
|
||||
mesh_max_bottom_layer_count = std::max(mesh_max_bottom_layer_count, mesh.getSettingAsCount("bottom_layers"));
|
||||
}
|
||||
|
||||
time_keeper_parallel_test.restart();
|
||||
#pragma omp parallel default(none) shared(mesh_layer_count, mesh, mesh_max_bottom_layer_count, process_infill)
|
||||
processed_layer_count = 0;
|
||||
#pragma omp parallel default(none) shared(mesh_layer_count, mesh, mesh_max_bottom_layer_count, process_infill, inset_skin_progress_estimate, processed_layer_count)
|
||||
{
|
||||
|
||||
#pragma omp for schedule(dynamic)
|
||||
for (unsigned int layer_number = 0; layer_number < mesh.layers.size(); layer_number++)
|
||||
{ MULTITHREAD_FOR_CATCH_EXCEPTION(
|
||||
{
|
||||
logDebug("Processing skins and infill layer %i of %i\n", layer_number, mesh_layer_count);
|
||||
if (!mesh.getSettingBoolean("magic_spiralize") || static_cast<int>(layer_number) < mesh_max_bottom_layer_count) //Only generate up/downskin and infill for the first X layers when spiralize is choosen.
|
||||
{
|
||||
processSkinsAndInfill(mesh, layer_number, process_infill);
|
||||
}
|
||||
//TODO: Fix progress update
|
||||
// double progress = inset_skin_progress_estimate.progress(layer_number);
|
||||
// Progress::messageProgress(Progress::Stage::INSET_SKIN, progress * 100, 100);
|
||||
)}
|
||||
#ifdef _OPENMP
|
||||
if (omp_get_thread_num() == 0)
|
||||
#endif
|
||||
{ // progress estimation is done only in one thread so that no two threads message progress at the same time
|
||||
int _processed_layer_count;
|
||||
#pragma omp atomic read
|
||||
_processed_layer_count = processed_layer_count;
|
||||
double progress = inset_skin_progress_estimate.progress(_processed_layer_count);
|
||||
Progress::messageProgress(Progress::Stage::INSET_SKIN, progress * 100, 100);
|
||||
}
|
||||
#pragma omp atomic
|
||||
processed_layer_count++;
|
||||
}
|
||||
}
|
||||
handleMultithreadAbort();
|
||||
log("processSkinsAndInfill time elapsed %5.3fs.\n", time_keeper_parallel_test.restart());
|
||||
}
|
||||
|
||||
void FffPolygonGenerator::processInfillMesh(SliceDataStorage& storage, unsigned int mesh_order_idx, std::vector<unsigned int>& mesh_order)
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
namespace cura
|
||||
{
|
||||
|
||||
// TODO: remove
|
||||
extern bool abort_execution;
|
||||
|
||||
#ifdef _OPENMP
|
||||
@@ -117,6 +118,7 @@ private:
|
||||
};
|
||||
#endif
|
||||
|
||||
// TODO: remove
|
||||
inline bool checkMultithreadAbort()
|
||||
{
|
||||
bool tmp_abort_execution;
|
||||
@@ -125,18 +127,21 @@ inline bool checkMultithreadAbort()
|
||||
return tmp_abort_execution;
|
||||
}
|
||||
|
||||
// TODO: remove
|
||||
inline void setMultithreadAbort()
|
||||
{
|
||||
#pragma omp atomic write
|
||||
abort_execution = true;
|
||||
}
|
||||
|
||||
// TODO: remove
|
||||
#ifdef _OPENMP
|
||||
void handleMultithreadAbort();
|
||||
#else
|
||||
inline void handleMultithreadAbort(){}
|
||||
#endif
|
||||
|
||||
// TODO: remove old code below
|
||||
#ifdef _OPENMP
|
||||
#define MULTITHREAD_FOR_CATCH_EXCEPTION(code) \
|
||||
if (checkMultithreadAbort()) \
|
||||
|
||||
Referência em uma Nova Issue
Bloquear um usuário