Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Imagemagick only uses one core

I am running an Ubuntu server with 8 cores. However imagemagick always only uses 1 single core.
Running identify -version returns:

Version: ImageMagick 6.6.9-7 2012-08-17 Q16 http://www.imagemagick.org
Copyright: Copyright (C) 1999-2011 ImageMagick Studio LLC
Features: OpenMP

So OpenMP which is apparently needed for multi threading is enabled.

Running a benchmark with -bench option (e.g. convert logo: -resize 500% -bench 10 logo.png) as described here returns

Performance: 10i 1.17647ips 14.390u 0.14166666666833332977:08.500

It does not return Performance[1] through Performance[8] as described in the manual which makes me wonder.

Any ideas how I can get imagemagick to use all 8 cores?

Update: Here is the strace output from an imagemagick call: http://pastebin.com/Q0gC3k09

like image 510
Horen Avatar asked Jul 15 '13 17:07

Horen


2 Answers

I was able to reproduce this behavior on Ubuntu 10.04. ImageMagick from apt-get seems to have the OpenMP feature, and configure with the -fopenmp flag, but the feature doesn't seem to be enabled. This can be verified by running the following line, and comparing the "FEATURES" list (if present) to the various configuration flags.

identify -list Configure | less

I was able to resolve this by following the article "Installing ImageMagick from Source on Ubuntu 8.04" which detailed the following process.

  • Remove ImageMagick
  • Install all the needed image/graphic dependency libraries through apt-get
  • Download
    • wget http://www.imagemagick.org/download/ImageMagick-6.8.6-6.tar.gz
  • Follow basic ./configure, make, & sudo make install steps
  • Export library path to /usr/local/lib

This seems to work as OpenMP is now present under "FEATURES" list, and when I execute convert logo: -resize 500% -bench 10 logo.png. I see the following

Performance[1]: 10i 0.750ips 1.000e 18.750u 0:13.330
Performance[2]: 10i 0.751ips 0.500e 18.660u 0:13.320
Performance[3]: 10i 0.738ips 0.496e 18.840u 0:13.550
Performance[4]: 10i 0.469ips 0.385e 19.560u 0:21.320

And these results match what I would expect.

like image 135
emcconville Avatar answered Jan 05 '23 01:01

emcconville


Some tests I made on my side but I not able to setup a real or virtualized multicore machine to reproduce. So I don't come with a real solution but more with a strategy to investigate because it really seems to be system dependent.

But at least I can say that:

  1. if you get the last ImageMagick source from http://www.imagemagick.org/script/install-source.php#unix, you should be able to rebuild IM for your system.

  2. if you want to be sure that your compiler handle the code as expected, you can do the following before calling "make", Edit the magick/studio.h file, found the line 143, you should see the following.

    #if defined(_OPENMP) && ((_OPENMP >= 200203) || defined(__OPENCC__))
    #  include <omp.h>
    #  define MAGICKCORE_OPENMP_SUPPORT  1
    #endif
    

    Modify those line to add a compiler diagnostic message:

    #if defined(_OPENMP) && ((_OPENMP >= 200203) || defined(__OPENCC__))
    #  include <omp.h>
    #  define MAGICKCORE_OPENMP_SUPPORT  1
    #  pragma message "MAGICKCORE_OPENMP_SUPPORT 1"
    #endif
    

    Now run the './configure' and after the 'make' command, you should see the message you added every time studio.h is used and BTW MAGICKCORE_OPEN_SUPPORT macro set to 1.

  3. MAGICKCORE_OPENMP_SUPPORT is the macro that IM use internally to enable/disable the preprocessing of the OpenMp directives, so if you see the message, all #pragma omp of the code will be process for real.

  4. If everything is ok until now try to perform the 'make install' command and check if your 'bench' command work better (multicore) with your own version of convert (/usr/local/bin/convert)

  5. if it's still not working, it means that it's not related to IM, but that openMP based program don't run correctly on your system. In that case you should consider the following question Why OpenMP program runs only in one thread, and check openMP support with a shorter program to build and run than IM !

like image 31
alexbuisson Avatar answered Jan 05 '23 01:01

alexbuisson