Page 1 of 1

How do I use all CPU cores?

Posted: 2011-01-03T13:55:34-07:00
by bossturbo
I wish to incorporate IM in a program I am about to write and during some pre-integration trials I have found the following. I ran a simple mogrify command to resize 263 high res jpegs to thumbnails which took ~1min 13sec. Using another commandline program it took ~17sec.

Here is the command I used:
mogrify -path tn -thumbnail 200x133 *.jpg

It seems that it's only using 1 core instead of all 6 (in task manager mogrify is only using 17% of CPU). Am I doing something wrong?

more information:
using the ImageMagick-6.6.6-10-Q16-windows-x64-dll.exe downloaded from the IM site
Both programs were run at a DOS prompt on a Windows 7 64-bit 6-core pc.

Thanks,
-brian

Re: How do I use all CPU cores?

Posted: 2011-01-03T18:51:09-07:00
by magick
Add -define jpeg:size=200x133 to your mogrify command line.

ImageMagick uses a single thread to read an image but multiple threads for image processing algorithms such as resizing. To verify, resize a large image and check your task manager:
  • convert logo: -resize 1000% null:

Re: How do I use all CPU cores?

Posted: 2011-01-04T16:16:52-07:00
by bossturbo
When i do a lengthy operation on just one photo as per your suggestion, it still shows ~17% CPU in task manager.

However, when I added the -define jpeg:size=200x133 to my mogrify command line it sped it up dramatically to about 17 sec processing time. Can you explain why this switch makes that much difference? I read what I could about it, but couldn't find out why. Again, it still shows about 17% CPU, but it's obviously a LOT faster and using around 100% CPU.

Thanks for your help!!
-brian

Re: How do I use all CPU cores?

Posted: 2011-01-04T18:25:11-07:00
by magick
The define is a hint to the JPEG reader to return an image size equal or close to the requested size. This only works with JPEG due to its DCT coefficients.

CPU usage may be under utilized due to the size of your image. If there is not enough memory, pixels are cached to disk and there is a tradeoff between CPU utilization and I/O. See http://www.imagemagick.org/script/architecture.php to understand this trade off.

Although, ImageMagick was not specifically tuned for Linux, we generally see a performance increase for the same task under Linux as compared to Windows.

Re: How do I use all CPU cores?

Posted: 2011-01-04T20:23:04-07:00
by bossturbo
Thanks for the info and the great product. I look forward to using it!