Skip to content

Commit

Permalink
thread tuning
Browse files Browse the repository at this point in the history
  • Loading branch information
Cristy committed Jan 2, 2024
1 parent 959549a commit fb0af62
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 14 deletions.
2 changes: 1 addition & 1 deletion magick/resize.c
Original file line number Diff line number Diff line change
Expand Up @@ -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++)
{
Expand Down
10 changes: 6 additions & 4 deletions magick/resource.c
Original file line number Diff line number Diff line change
Expand Up @@ -1401,11 +1401,10 @@ MagickExport MagickBooleanType ResourceComponentGenesis(void)
MagickSizeType
memory;

ssize_t
i;

ssize_t
files,
i,
number_threads,
pages,
pagesize;

Expand Down Expand Up @@ -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)
{
Expand Down
15 changes: 6 additions & 9 deletions magick/thread-private.h
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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)
Expand Down Expand Up @@ -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
}
Expand Down

0 comments on commit fb0af62

Please sign in to comment.