How do I use all CPU cores?

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
User avatar
bossturbo
Posts: 3
Joined: 2011-01-03T12:32:19-07:00
Authentication code: 8675308

How do I use all CPU cores?

Post 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
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: How do I use all CPU cores?

Post 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:
User avatar
bossturbo
Posts: 3
Joined: 2011-01-03T12:32:19-07:00
Authentication code: 8675308

Re: How do I use all CPU cores?

Post 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
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: How do I use all CPU cores?

Post 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.
User avatar
bossturbo
Posts: 3
Joined: 2011-01-03T12:32:19-07:00
Authentication code: 8675308

Re: How do I use all CPU cores?

Post by bossturbo »

Thanks for the info and the great product. I look forward to using it!
Post Reply