From fb0af62d0f6e211bdb979f2084d589dc2391bc2b Mon Sep 17 00:00:00 2001 From: Cristy Date: Tue, 2 Jan 2024 12:29:58 -0500 Subject: [PATCH] thread tuning --- magick/resize.c | 2 +- magick/resource.c | 10 ++++++---- magick/thread-private.h | 15 ++++++--------- 3 files changed, 13 insertions(+), 14 deletions(-) diff --git a/magick/resize.c b/magick/resize.c index 2ebfefd75..d4aeef962 100644 --- a/magick/resize.c +++ b/magick/resize.c @@ -3149,7 +3149,7 @@ MagickExport Image *SampleImage(const Image *image,const size_t columns, sample_view=AcquireAuthenticCacheView(sample_image,exception); #if defined(MAGICKCORE_OPENMP_SUPPORT) #pragma omp parallel for schedule(static) shared(status) \ - magick_number_threads(image,sample_image,sample_image->rows,1) + magick_number_threads(image,sample_image,sample_image->rows,2) #endif for (y=0; y < (ssize_t) sample_image->rows; y++) { diff --git a/magick/resource.c b/magick/resource.c index df2a330b2..6dd009b25 100644 --- a/magick/resource.c +++ b/magick/resource.c @@ -1401,11 +1401,10 @@ MagickExport MagickBooleanType ResourceComponentGenesis(void) MagickSizeType memory; - ssize_t - i; - ssize_t files, + i, + number_threads, pages, pagesize; @@ -1502,7 +1501,10 @@ MagickExport MagickBooleanType ResourceComponentGenesis(void) (void) SetMagickResourceLimit(FileResource,StringToSizeType(limit,100.0)); limit=DestroyString(limit); } - (void) SetMagickResourceLimit(ThreadResource,GetOpenMPMaximumThreads()); + number_threads=(ssize_t) GetOpenMPMaximumThreads(); + if (number_threads > 1) + number_threads--; /* reserve core for OS */ + (void) SetMagickResourceLimit(ThreadResource,(size_t) number_threads); limit=GetEnvironmentValue("MAGICK_THREAD_LIMIT"); if (limit != (char *) NULL) { diff --git a/magick/thread-private.h b/magick/thread-private.h index 2715da71e..f9cc6849d 100644 --- a/magick/thread-private.h +++ b/magick/thread-private.h @@ -50,7 +50,7 @@ extern "C" { static inline int GetMagickNumberThreads(const Image *source, const Image *destination,const size_t chunk,int factor) { -#define WorkloadFactor (32 << factor) +#define WorkLoadFactor (64UL << factor) const CacheType destination_type = (CacheType) GetImagePixelCacheType(destination), @@ -62,15 +62,12 @@ static inline int GetMagickNumberThreads(const Image *source, /* Return number of threads dependent on cache type and work load. */ - if (factor == 0) - return(1); + number_threads=MagickMax(MagickMin(chunk/WorkLoadFactor, + GetMagickResourceLimit(ThreadResource)),1); if (((source_type != MemoryCache) && (source_type != MapCache)) || ((destination_type != MemoryCache) && (destination_type != MapCache))) - number_threads=(int) MagickMin(GetMagickResourceLimit(ThreadResource),2); - else - number_threads=(int) MagickMin((ssize_t) GetMagickResourceLimit( - ThreadResource),(ssize_t) (chunk)/WorkloadFactor); - return(MagickMax(number_threads,1)); + number_threads=MagickMin(number_threads,2); + return(number_threads); } static inline MagickThreadType GetMagickThreadId(void) @@ -161,7 +158,7 @@ static inline void SetOpenMPNested(const int value) omp_set_nested(value); #else static inline void SetOpenMPNested(const int magick_unused(value)) -{ +{ magick_unreferenced(value); #endif }