Page 2 of 2

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

Posted: 2017-10-01T13:05:42-07:00
by snibgo
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.

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

Posted: 2017-10-01T15:38:47-07:00
by magick
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.

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

Posted: 2017-10-01T16:13:27-07:00
by whatdoido
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.

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

Posted: 2017-10-01T17:51:42-07:00
by magick
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.

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

Posted: 2017-10-02T02:23:47-07:00
by whatdoido
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 ..."

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

Posted: 2017-10-02T04:02:04-07:00
by magick
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.