Fix T40510, revert openmp thread count to how it was in
authorAntony Riakiotakis <kalast@gmail.com>
Sat, 7 Jun 2014 22:13:28 +0000 (01:13 +0300)
committerAntony Riakiotakis <kalast@gmail.com>
Sat, 7 Jun 2014 22:39:02 +0000 (01:39 +0300)
2.70 for non Apple systems.

Also refactored the code that restores the previous openmp thread count.
The logic here was weird, mostly due to all the commit madness with
Apple openmp support. The restored thread count though should not depend
on the on/off state of threaded sculpting (since it has to do with
systems other than sculpting only). For OSX threads are restored to the
system thread count but Jens should recheck here.

source/blender/blenlib/BLI_threads.h
source/blender/editors/sculpt_paint/sculpt.c

index 1c9e75d950a517ef16490e833d85fadbf7bbff34..74291ca305e9f6b1e8490b431bb32baf9b623aa4 100644 (file)
@@ -74,8 +74,6 @@ void BLI_end_threaded_malloc(void);
 int     BLI_system_thread_count(void); /* gets the number of threads the system can make use of */
 void    BLI_system_num_threads_override_set(int num);
 int     BLI_system_num_threads_override_get(void);
-
-int     BLI_system_thread_count_omp(void);
        
 /* Global Mutex Locks
  * 
index abbb8dd55ce7006b146117752a51f1489ec928c2..9324656309bb6699ddfa9aaf0b897b8980ff27eb 100644 (file)
@@ -178,7 +178,7 @@ typedef struct StrokeCache {
        float initial_mouse[2];
 
        /* Pre-allocated temporary storage used during smoothing */
-       int num_threads, max_threads;
+       int num_threads, init_num_threads;
        float (**tmpgrid_co)[3], (**tmprow_co)[3];
        float **tmpgrid_mask, **tmprow_mask;
 
@@ -3624,6 +3624,12 @@ static void sculpt_omp_start(Sculpt *sd, SculptSession *ss)
        StrokeCache *cache = ss->cache;
 
 #ifdef _OPENMP
+
+#if defined(__APPLE__)
+       cache->init_num_threads = BLI_system_thread_count();
+#else
+       cache->init_num_threads = omp_get_max_threads();
+#endif
        /* If using OpenMP then create a number of threads two times the
         * number of processor cores.
         * Justification: Empirically I've found that two threads per
@@ -3632,13 +3638,12 @@ static void sculpt_omp_start(Sculpt *sd, SculptSession *ss)
 #if defined(__APPLE__)
                cache->num_threads = system_physical_thread_count();
 #else
-               cache->num_threads = omp_get_num_procs();
+               cache->num_threads = 2 * omp_get_num_procs();
 #endif
        }
        else {
                cache->num_threads = 1;
        }
-       cache->max_threads = omp_get_max_threads();
        omp_set_num_threads(cache->num_threads);
 #else
        (void)sd;
@@ -3671,8 +3676,9 @@ static void sculpt_omp_start(Sculpt *sd, SculptSession *ss)
 static void sculpt_omp_done(SculptSession *ss)
 {
 #ifdef _OPENMP
-       omp_set_num_threads(ss->cache->max_threads);
+       omp_set_num_threads(ss->cache->init_num_threads);
 #endif
+
        if (ss->multires) {
                int i;
 
@@ -4500,11 +4506,6 @@ static void sculpt_stroke_done(const bContext *C, struct PaintStroke *UNUSED(str
                WM_event_add_notifier(C, NC_OBJECT | ND_DRAW, ob);
        }
 
-#ifdef _OPENMP
-       if (!(sd->flags & SCULPT_USE_OPENMP))
-               omp_set_num_threads(BLI_system_thread_count()); /* set back to original logical corecount */
-#endif
-
        sculpt_brush_exit_tex(sd);
 }