setting the number of IM threads on a task by task basis

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
NicolasRobidoux
Posts: 1944
Joined: 2010-08-28T11:16:00-07:00
Authentication code: 8675308
Location: Montreal, Canada

setting the number of IM threads on a task by task basis

Post by NicolasRobidoux »

Suppose that one has determined that, on one's machine, a certain convert task runs faster with OpenMP off, but that another convert task runs faster with, say, four threads.

How can one fix things so that both tasks run fast?

One way would be to have two differently compiled versions of ImageMagick floating around, using one for each task.

Now, what if three different key tasks have different ideal number of threads?

Dead simple solution

Assuming ImageMagick was compiled with OpenMP support, run the first task prefixing with the environment variable determining the number of threads set so that only 1 is used

Code: Select all

MAGICK_THREAD_LIMIT=1 convert small.png -resize 40x40^ -gravity center -extent 40x40 -quality 75 -sample 2x2 smallthumb.jpg
and do the same with the other task, setting it's number of threads to a different value

Code: Select all

MAGICK_THREAD_LIMIT=4 convert big.png -resize 40x40^ -gravity center -extent 40x40 -quality 75 -sample 2x2 bigthumb.jpg
Of course, if you have not taken the time to figure out the ideal number of threads for a task, or you are happy with the default, just leave the prefix out.
NicolasRobidoux
Posts: 1944
Joined: 2010-08-28T11:16:00-07:00
Authentication code: 8675308
Location: Montreal, Canada

Re: setting the number of IM threads on a task by task basis

Post by NicolasRobidoux »

Of course, if the operation takes long enough, you can figure out a good choice of number of cores by prefixing whatever operation with "-bench" (as in "convert -bench 10 big.jpg -resize ...").
Post Reply