[SOLVED] Magick++ API / OpenMP - special setup? Only one core used

Magick++ is an object-oriented C++ interface to ImageMagick. Use this forum to discuss, make suggestions about, or report bugs concerning Magick++.
snibgo
Posts: 9397
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Magick++ API / OpenMP - special setup? Only one core used

Post by snibgo » 2017-10-01T13:05:42-07:00

Building your program (which I named resiz.cpp) on my laptop, Windows 8.1 with Cygwin, IM v6.9.3-7, I get:

Code: Select all

c:\cygwin64\home\Alan\ImageMagick-6.9.3-7\ImageMagick>%IMDEV%resiz rose:
OMP: cpus=8 threads=8
using MagickCore
My build command was:

Code: Select all

  c++ -o resiz.exe resiz.cpp -Wall -Wa,-march=corei7,-mtune=corei7 `pkg-config --cflags --libs Magick++`
After changing "#ifdef USE_MAGICK_PLUSPLUS" to "#if 1", and rebuilding, I get:

Code: Select all

c:\cygwin64\home\Alan\ImageMagick-6.9.3-7\ImageMagick>%IMDEV%resiz
OMP: cpus=8 threads=8
using Magick++
These are the results I would expect.
snibgo's IM pages: im.snibgo.com

User avatar
magick
Site Admin
Posts: 10690
Joined: 2003-05-31T11:32:55-07:00

Re: Magick++ API / OpenMP - special setup? Only one core used

Post by magick » 2017-10-01T15:38:47-07:00

Add Magick::ResourceLimits::thread(4); before you call resize(). Magick++ will then thread the resize algorithm. Or apply Magick++ best practices, call InitializeMagick(*argv); That sets the number of threads equal to the number of cores on your system.

whatdoido
Posts: 25
Joined: 2011-01-22T16:54:46-07:00
Authentication code: 8675308

Re: Magick++ API / OpenMP - special setup? Only one core used

Post by whatdoido » 2017-10-01T16:13:27-07:00

Confirmed as under investigation (why Magick++ defaults to 1 thread) with workaround of:

Code: Select all

Magick::ResourceLimits::thread(omp_get_max_threads())
to force threads, to match your underlying system as seen by OMP, under Magick++ resize operation.

https://github.com/ImageMagick/ImageMagick/issues/824

It may well be that explicitly calling ResourceLimits::threads() is required but its not in any of the docs I've seen - and it ignores the system policy for threads so seems like a bug.

Will wait on issue on github for further advice.

Thanks all.

User avatar
magick
Site Admin
Posts: 10690
Joined: 2003-05-31T11:32:55-07:00

Re: Magick++ API / OpenMP - special setup? Only one core used

Post by magick » 2017-10-01T17:51:42-07:00

Proper of initialization of Magick++ requires you call InitializeMagick(). If you do, the number of threads are set to the number of cores on your system.

whatdoido
Posts: 25
Joined: 2011-01-22T16:54:46-07:00
Authentication code: 8675308

Re: Magick++ API / OpenMP - special setup? Only one core used

Post by whatdoido » 2017-10-02T02:23:47-07:00

Appreciate the help on solving this .

However:
magick wrote:
2017-10-01T17:51:42-07:00
Proper of initialization of Magick++ requires you call InitializeMagick(). If you do, the number of threads are set to the number of cores on your system.
please update the documentation state this is MANDATORY and not just best practice or only required for Windows.

https://www.imagemagick.org/script/magick++.php
Note, under Windows (and possibly the Mac) it may be necessary to initialize the ImageMagick library prior to using the Magick++ library. This initialization is performed by passing the path to the ImageMagick DLLs (assumed to be in the same directory as your program) to the InitializeMagick() function call. This is commonly performed by providing the path to your program (argv[0]) as shown in the following example:


int main( int argc, char ** argv) {
InitializeMagick(*argv);
...
This initialization step is not required under Unix, Linux, Cygwin, or any other operating environment that supports the notion of installing ImageMagick in a known location.
Note the last sentence specifically stating "NOT required under Unix, Linux ..."

User avatar
magick
Site Admin
Posts: 10690
Joined: 2003-05-31T11:32:55-07:00

Re: [SOLVED] Magick++ API / OpenMP - special setup? Only one core used

Post by magick » 2017-10-02T04:02:04-07:00

Calling InitializeMagick() is not mandatory. Its just best practices. Notice your module worked without calling InitializeMagick(). Without it though, you need to perform your own initialization as required, e.g. set the number of threads you require.

Post Reply