From 1a80d1aa528ac4afdf2663d4b640519e2ed85a37 Mon Sep 17 00:00:00 2001 From: Krzysztof Kosi??ski Date: Tue, 27 Jul 2010 05:34:39 +0200 Subject: Add OpenMP IF clauses to filter templates, instead of modifying num_threads (bzr r9508.1.37) --- src/display/cairo-templates.h | 31 ++++++++++++++----------------- 1 file changed, 14 insertions(+), 17 deletions(-) (limited to 'src/display') diff --git a/src/display/cairo-templates.h b/src/display/cairo-templates.h index 900ca2d54..78fdff664 100644 --- a/src/display/cairo-templates.h +++ b/src/display/cairo-templates.h @@ -16,7 +16,7 @@ #include #include "preferences.h" // single-threaded operation if the number of pixels is below this threshold -#define OPENMP_THRESHOLD 2048 +static const int OPENMP_THRESHOLD = 2048; #endif #include @@ -70,7 +70,6 @@ void ink_cairo_surface_blend(cairo_surface_t *in1, cairo_surface_t *in2, cairo_s #if HAVE_OPENMP Inkscape::Preferences *prefs = Inkscape::Preferences::get(); int num_threads = prefs->getIntLimited("/options/threading/numthreads", omp_get_num_procs(), 1, 256); - if (limit < OPENMP_THRESHOLD) num_threads = 1; // do not spawn threads for very small surfaces #endif // The number of code paths here is evil. @@ -78,14 +77,14 @@ void ink_cairo_surface_blend(cairo_surface_t *in1, cairo_surface_t *in2, cairo_s if (bpp2 == 4) { if (fast_path) { #if HAVE_OPENMP - #pragma omp parallel for num_threads(num_threads) + #pragma omp parallel for if(limit > OPENMP_THRESHOLD) num_threads(num_threads) #endif for (int i = 0; i < limit; ++i) { *(out_data + i) = blend(*(in1_data + i), *(in2_data + i)); } } else { #if HAVE_OPENMP - #pragma omp parallel for num_threads(num_threads) + #pragma omp parallel for if(limit > OPENMP_THRESHOLD) num_threads(num_threads) #endif for (int i = 0; i < h; ++i) { guint32 *in1_p = in1_data + i * stride1/4; @@ -100,7 +99,7 @@ void ink_cairo_surface_blend(cairo_surface_t *in1, cairo_surface_t *in2, cairo_s } else { // bpp2 == 1 #if HAVE_OPENMP - #pragma omp parallel for num_threads(num_threads) + #pragma omp parallel for if(limit > OPENMP_THRESHOLD) num_threads(num_threads) #endif for (int i = 0; i < h; ++i) { guint32 *in1_p = in1_data + i * stride1/4; @@ -118,7 +117,7 @@ void ink_cairo_surface_blend(cairo_surface_t *in1, cairo_surface_t *in2, cairo_s if (bpp2 == 4) { // bpp1 == 1 #if HAVE_OPENMP - #pragma omp parallel for num_threads(num_threads) + #pragma omp parallel for if(limit > OPENMP_THRESHOLD) num_threads(num_threads) #endif for (int i = 0; i < h; ++i) { guint8 *in1_p = reinterpret_cast(in1_data) + i * stride1; @@ -135,7 +134,7 @@ void ink_cairo_surface_blend(cairo_surface_t *in1, cairo_surface_t *in2, cairo_s // bpp1 == 1 && bpp2 == 1 if (fast_path) { #if HAVE_OPENMP - #pragma omp parallel for num_threads(num_threads) + #pragma omp parallel for if(limit > OPENMP_THRESHOLD) num_threads(num_threads) #endif for (int i = 0; i < limit; ++i) { guint8 *in1_p = reinterpret_cast(in1_data) + i; @@ -148,7 +147,7 @@ void ink_cairo_surface_blend(cairo_surface_t *in1, cairo_surface_t *in2, cairo_s } } else { #if HAVE_OPENMP - #pragma omp parallel for num_threads(num_threads) + #pragma omp parallel for if(limit > OPENMP_THRESHOLD) num_threads(num_threads) #endif for (int i = 0; i < h; ++i) { guint8 *in1_p = reinterpret_cast(in1_data) + i * stride1; @@ -199,7 +198,6 @@ void ink_cairo_surface_filter(cairo_surface_t *in, cairo_surface_t *out, Filter #if HAVE_OPENMP Inkscape::Preferences *prefs = Inkscape::Preferences::get(); int num_threads = prefs->getIntLimited("/options/threading/numthreads", omp_get_num_procs(), 1, 256); - if (limit < OPENMP_THRESHOLD) num_threads = 1; // do not spawn threads for very small surfaces #endif if (bppin == 4) { @@ -207,14 +205,14 @@ void ink_cairo_surface_filter(cairo_surface_t *in, cairo_surface_t *out, Filter // bppin == 4, bppout == 4 if (fast_path) { #if HAVE_OPENMP - #pragma omp parallel for num_threads(num_threads) + #pragma omp parallel for if(limit > OPENMP_THRESHOLD) num_threads(num_threads) #endif for (int i = 0; i < limit; ++i) { *(out_data + i) = filter(*(in_data + i)); } } else { #if HAVE_OPENMP - #pragma omp parallel for num_threads(num_threads) + #pragma omp parallel for if(limit > OPENMP_THRESHOLD) num_threads(num_threads) #endif for (int i = 0; i < h; ++i) { guint32 *in_p = in_data + i * stridein/4; @@ -229,7 +227,7 @@ void ink_cairo_surface_filter(cairo_surface_t *in, cairo_surface_t *out, Filter // bppin == 4, bppout == 1 // we use this path with COLORMATRIX_LUMINANCETOALPHA #if HAVE_OPENMP - #pragma omp parallel for num_threads(num_threads) + #pragma omp parallel for if(limit > OPENMP_THRESHOLD) num_threads(num_threads) #endif for (int i = 0; i < h; ++i) { guint32 *in_p = in_data + i * stridein/4; @@ -246,7 +244,7 @@ void ink_cairo_surface_filter(cairo_surface_t *in, cairo_surface_t *out, Filter // Note: there is no path for bppin == 1, bppout == 4 because it is useless if (fast_path) { #if HAVE_OPENMP - #pragma omp parallel for num_threads(num_threads) + #pragma omp parallel for if(limit > OPENMP_THRESHOLD) num_threads(num_threads) #endif for (int i = 0; i < limit; ++i) { guint8 *in_p = reinterpret_cast(in_data) + i; @@ -257,7 +255,7 @@ void ink_cairo_surface_filter(cairo_surface_t *in, cairo_surface_t *out, Filter } } else { #if HAVE_OPENMP - #pragma omp parallel for num_threads(num_threads) + #pragma omp parallel for if(limit > OPENMP_THRESHOLD) num_threads(num_threads) #endif for (int i = 0; i < h; ++i) { guint8 *in_p = reinterpret_cast(in_data) + i * stridein; @@ -301,12 +299,11 @@ void ink_cairo_surface_synthesize(cairo_surface_t *out, cairo_rectangle_t const int limit = w * h; Inkscape::Preferences *prefs = Inkscape::Preferences::get(); int num_threads = prefs->getIntLimited("/options/threading/numthreads", omp_get_num_procs(), 1, 256); - if (limit < OPENMP_THRESHOLD) num_threads = 1; // do not spawn threads for very small surfaces #endif if (bppout == 4) { #if HAVE_OPENMP - #pragma omp parallel for num_threads(num_threads) + #pragma omp parallel for if(limit > OPENMP_THRESHOLD) num_threads(num_threads) #endif for (int i = out_area.y; i < h; ++i) { guint32 *out_p = reinterpret_cast(out_data + i * strideout); @@ -318,7 +315,7 @@ void ink_cairo_surface_synthesize(cairo_surface_t *out, cairo_rectangle_t const } else { // bppout == 1 #if HAVE_OPENMP - #pragma omp parallel for num_threads(num_threads) + #pragma omp parallel for if(limit > OPENMP_THRESHOLD) num_threads(num_threads) #endif for (int i = out_area.y; i < h; ++i) { guint8 *out_p = out_data + i * strideout; -- cgit v1.2.3