[Qt-interest] [1/2 OT] ImageMagick, OpenMP and QThread [Mac OS X]?

Oliver.Knoll at comit.ch Oliver.Knoll at comit.ch
Wed Jan 27 16:37:31 CET 2010


Hi,

this is somewhat ImageMagick related (I am using the Magic++ API), but their discussion forum server is currently not reachable and maybe it /is/ QThread related after all. And I hope that some people here on this list have also experience with ImageMagick, and maybe even on a Mac (in case this is a Mac specific issue).

My application crashes when I want to create an ImageMagick "Image" within a QThread. This is the offending code:

  // within a QThread::run()
  QByteArray byteArray = buffer.buffer();
  Magick::Blob blob(byteArray.data(), byteArray.size());
  // crash here
  Magick::Image magickImage(blob);

Stack trace:

Thread 5 Crashed:
0   libMagickCore.2.dylib         	0x00000001003e781c gomp_resolve_num_threads + 28
1   libMagickCore.2.dylib         	0x00000001002929b5 AcquirePixelCache + 325
2   libMagickCore.2.dylib         	0x000000010033d406 AcquireImage + 358
3   libMagick++.2.dylib           	0x00000001002183a6 Magick::ImageRef::ImageRef() + 86
4   libMagick++.2.dylib           	0x0000000100210519 Magick::Image::Image(Magick::Blob const&) + 57
5   libUtils.1.0.0.dylib          	0x00000001001161c4
ImageTools::saveJPEG(QImage const&, QString const&, unsigned int, bool) + 64 (ImageTools.cpp:127) 
...

So the code crashes in some thread-related call: gomp_resolve_num_threads, within the MagicCore library. Does this ring a bell, anyone? 

After some googleing I think this function is related to http://openmp.org/wp/: "OpenMP is a portable, scalable model with a simple and flexible interface for developing parallel applications on platforms from the desktop to the supercomputer".


Are there known issues between QThread and this OpenMP?


The same code runs fine when called in the "main" thread, I have attached a small example which illustrates this problem (the above strack trace is from my actual GUI application though, but in both cases the crash happens when trying to create the Magick Image, given a Magick Blob).

I had the same code running fine on Windows XP before where I started developing, but since then the

- Qt version changed (currently 4.6.0 binary open source, "Cocoa")
- The ImageMagick version changed (installed via "Mac Ports", currently 6.5.8-0)
- The compiler obviously changed (standard g++ from Mac OS 10.6)

So naturally the culprit could be everywhere. :/

But is anyone out there successfully using ImageMagick from "within a QThread" on Mac OS X who could tell me "Off course, you have to enable the Foo switch"? 

I already tried enabling/disabling CONFIG += thread, but to no avail. I will try to upgrade to the latest ImageMagick 6.5.9 tonight, but I don't expect any major change there.

As mentioned I did install ImageMagick via "sudo port install ImageMagick", with all default settings (64 bit library, Intel, on iMac). Maybe there is some incompatible compiler flag (as compared with the binary Qt 4.6.0 "Cocoa" distribution)?

Also note that I am /not/ trying to access the ImageMagick API from different threads! All I am trying is to have a worker thread which uses ImageMagick exclusively (basically save a QImage as JPEG, with all the fancy whistles and bells that ImageMagick offers).


Thank you, 
  Oliver

p.s. I just found this http://lists.macosforge.org/pipermail/macports-tickets/2008-July/011518.html: "Also a ui_msg was added
 telling the user to set the OMP_NUM_THREADS environment variable to the number of available CPUs or cores on that machine."

Setting this OMP_NUM_THREADS environment variable might be interesting ... (but then again, why does the same code run within the "main" thread??)

p.p.s. I am aware that converting a QImage to a Magick image via a "PNG QByteArray / Blob" is not the most performant way - but it works for now and should be stable on any platform ;)
-- 
Oliver Knoll
Dipl. Informatik-Ing. ETH
COMIT AG - ++41 79 520 95 22
-------------- next part --------------
A non-text attachment was scrubbed...
Name: MagickBlob.zip
Type: application/x-zip-compressed
Size: 2588 bytes
Desc: MagickBlob.zip
Url : http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20100127/081a811a/attachment.bin 


More information about the Qt-interest-old mailing list