Multi-threaded ImageMagick
Posted: 2007-06-29T08:53:50-07:00
I found the following on the email list:
> processing, or does "multi-threading support" merely mean that the
> ImageMagick library is thread-safe?
The ImageMagick library is thread-safe. Currently to take advantage of
multiple-threads you would need to write custom code in Magick++,
MagickWand, or MagickCore. You of course could still take advantage of
multiple processors by firing off multiple command line utilities
simultaneously.
But it was a while ago. I have a situation where I am converting the pages of a PDF into PNG files. When I run this on my developer machine which has a 2GHz processor, it takes only 30-40 seconds to run a 7 page file. When I put this on the server which has 4-700MHz processors, the convert.exe only uses 25% of the total cpu, or 1 - 700 MHz CPU. I am using ImageMagick 6.2.9 09/14/06 Q16 via the command line to do this.
Is there anyway to make image magick use more than one processor? In the above email, it sounds like you could do it if you have multiple images to convert by just firing off mutiple instances of IM. But can you do this when just running one instance?
Thanks for your help!
-->UPDATED:
I found this paragraph on the web site:
"Threads of Execution
Many of ImageMagick's internal algorithms are threaded to take advantage of speed-ups offered by the dual and quad-core processor technologies. However, you are welcome to use ImageMagick algorithm in your threads of execution with the exception of the MagickCore AcquireImagePixels(), GetImagePixels(), SetImagePixels(), and SyncImagePixels() pixel cache methods. These methods are intended for one thread of execution only. To access the pixel cache with more than one thread of execution, use a cache view. We do this for the CompositeImage() method, for example. Suppose we want to composite a single image over a different image in each thread of execution. If we use AcquireImagePixels(), the results could be corrupt since multiple threads might be asking for different areas of the pixel cache simultaneously. Instead we use AcquireCacheView() which creates a unique view for each thread of execution ensuring our program behaves properly regardless of how many threads are invoked. The other program interfaces, such as the MagickWand API, are completely thread safe so there are no special precautions for threads of execution.
"
-->Does this mean that if the convert.exe program was able to take advantage of multiple processors it would have automatically...or does this require some user intervention to happen?
Thanks!
> processing, or does "multi-threading support" merely mean that the
> ImageMagick library is thread-safe?
The ImageMagick library is thread-safe. Currently to take advantage of
multiple-threads you would need to write custom code in Magick++,
MagickWand, or MagickCore. You of course could still take advantage of
multiple processors by firing off multiple command line utilities
simultaneously.
But it was a while ago. I have a situation where I am converting the pages of a PDF into PNG files. When I run this on my developer machine which has a 2GHz processor, it takes only 30-40 seconds to run a 7 page file. When I put this on the server which has 4-700MHz processors, the convert.exe only uses 25% of the total cpu, or 1 - 700 MHz CPU. I am using ImageMagick 6.2.9 09/14/06 Q16 via the command line to do this.
Is there anyway to make image magick use more than one processor? In the above email, it sounds like you could do it if you have multiple images to convert by just firing off mutiple instances of IM. But can you do this when just running one instance?
Thanks for your help!
-->UPDATED:
I found this paragraph on the web site:
"Threads of Execution
Many of ImageMagick's internal algorithms are threaded to take advantage of speed-ups offered by the dual and quad-core processor technologies. However, you are welcome to use ImageMagick algorithm in your threads of execution with the exception of the MagickCore AcquireImagePixels(), GetImagePixels(), SetImagePixels(), and SyncImagePixels() pixel cache methods. These methods are intended for one thread of execution only. To access the pixel cache with more than one thread of execution, use a cache view. We do this for the CompositeImage() method, for example. Suppose we want to composite a single image over a different image in each thread of execution. If we use AcquireImagePixels(), the results could be corrupt since multiple threads might be asking for different areas of the pixel cache simultaneously. Instead we use AcquireCacheView() which creates a unique view for each thread of execution ensuring our program behaves properly regardless of how many threads are invoked. The other program interfaces, such as the MagickWand API, are completely thread safe so there are no special precautions for threads of execution.
"
-->Does this mean that if the convert.exe program was able to take advantage of multiple processors it would have automatically...or does this require some user intervention to happen?
Thanks!