[Bf-blender-cvs] [081b0b6] master: Sculpt: Fix non openMP threads not set correct and use optimal omp threadcount for OSX - i empirically found that using HT just gives overhead, even possibly slowing things down - i propose other OS test this too again - switching threaded on/off did not restored single threaded case ( credits to Sergey )

Jens Verwiebe noreply at git.blender.org
Fri Mar 21 15:27:09 CET 2014


Commit: 081b0b6599af08566e49fe7f5b82ec8269e7fece
Author: Jens Verwiebe
Date:   Fri Mar 21 15:26:50 2014 +0100
https://developer.blender.org/rB081b0b6599af08566e49fe7f5b82ec8269e7fece

Sculpt: Fix non openMP threads not set correct and use optimal omp threadcount for OSX
- i empirically found that using HT just gives overhead, even possibly slowing things down
- i propose other OS test this too again
- switching threaded on/off did not restored single threaded case ( credits to Sergey )

===================================================================

M	source/blender/editors/sculpt_paint/sculpt.c

===================================================================

diff --git a/source/blender/editors/sculpt_paint/sculpt.c b/source/blender/editors/sculpt_paint/sculpt.c
index eac1853..0e72886 100644
--- a/source/blender/editors/sculpt_paint/sculpt.c
+++ b/source/blender/editors/sculpt_paint/sculpt.c
@@ -104,6 +104,20 @@
 #include <omp.h>
 #endif
 
+#if defined(__APPLE__)
+#include <sys/sysctl.h>
+
+/* how many cores not counting HT aka pysical cores */
+int system_physical_thread_count(void); // declaration here for simplification
+int system_physical_thread_count(void)
+{
+	int pcount;
+	size_t pcount_len;
+	sysctlbyname("hw.physicalcpu", &pcount, &pcount_len, NULL, 0);
+	return pcount;
+	}
+#endif // __APPLE__
+
 void ED_sculpt_get_average_stroke(Object *ob, float stroke[3])
 {
 	if (ob->sculpt->last_stroke_valid && ob->sculpt->average_stroke_counter > 0) {
@@ -3773,16 +3787,21 @@ static void sculpt_omp_start(Sculpt *sd, SculptSession *ss)
 	 * Justification: Empirically I've found that two threads per
 	 * processor gives higher throughput. */
 	if (sd->flags & SCULPT_USE_OPENMP) {
-		cache->num_threads = 2 * omp_get_num_procs();
-		omp_set_num_threads(cache->num_threads);
-	}
-	else
+#if defined(__APPLE__)
+		cache->num_threads = system_physical_thread_count();
+#else
+		cache->num_threads = omp_get_num_procs();
 #endif
-	{
-		(void)sd;
+	}
+      else {
 		cache->num_threads = 1;
 	}
-
+	omp_set_num_threads(cache->num_threads);
+#else
+	(void)sd;
+	cache->num_threads = 1;
+#endif
+	printf(" threads used: %d\n", cache->num_threads);
 	if (ss->multires) {
 		int i, gridsize, array_mem_size;
 		BKE_pbvh_node_get_grids(ss->pbvh, NULL, NULL, NULL, NULL,




More information about the Bf-blender-cvs mailing list