Browse Source

Optimization: Parallelize the for loops over individual PrintObjects

Lukas Matena 1 year ago
parent
commit
37a088abac
1 changed files with 19 additions and 10 deletions
  1. 19 10
      src/libslic3r/Print.cpp

+ 19 - 10
src/libslic3r/Print.cpp

@@ -903,20 +903,29 @@ void Print::process()
     name_tbb_thread_pool_threads_set_locale();
 
     BOOST_LOG_TRIVIAL(info) << "Starting the slicing process." << log_memory_info();
-    for (PrintObject *obj : m_objects)
-        obj->make_perimeters();
-    for (PrintObject *obj : m_objects)
-        obj->infill();
-    for (PrintObject *obj : m_objects)
-        obj->ironing();
+
+    tbb::parallel_for(tbb::blocked_range<size_t>(0, m_objects.size(), 1), [this](const tbb::blocked_range<size_t> &range) {
+        for (size_t idx = range.begin(); idx < range.end(); ++idx) {
+            m_objects[idx]->make_perimeters();
+            m_objects[idx]->infill();
+            m_objects[idx]->ironing();
+        }
+    }, tbb::simple_partitioner());
+
+    // The following step writes to m_shared_regions, it should not run in parallel.
     for (PrintObject *obj : m_objects)
         obj->generate_support_spots();
     // check data from previous step, format the error message(s) and send alert to ui
+    // this also has to be done sequentially.
     alert_when_supports_needed();
-    for (PrintObject *obj : m_objects)
-        obj->generate_support_material();
-    for (PrintObject *obj : m_objects)
-        obj->estimate_curled_extrusions();
+
+    tbb::parallel_for(tbb::blocked_range<size_t>(0, m_objects.size(), 1), [this](const tbb::blocked_range<size_t> &range) {
+        for (size_t idx = range.begin(); idx < range.end(); ++idx) {
+            m_objects[idx]->generate_support_material();
+            m_objects[idx]->estimate_curled_extrusions();
+        }
+    }, tbb::simple_partitioner());
+
     if (this->set_started(psWipeTower)) {
         m_wipe_tower_data.clear();
         m_tool_ordering.clear();