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

Oliver.Knoll at comit.ch Oliver.Knoll at comit.ch
Thu Jan 28 09:49:14 CET 2010


Knoll Oliver, ITS-CMT-SUI-SL-SFR-FIN-DEV wrote on Wednesday, January 27, 2010 4:52 PM:

> Knoll Oliver, ITS-CMT-SUI-SL-SFR-FIN-DEV wrote on Wednesday, January
> 27, 2010 4:38 PM: 
> 
>> ...
>> Are there known issues between QThread and this OpenMP?
> 
> Interesting:
> http://www.qtcentre.org/threads/20079-QThread-and-OpenMP-on-Mac-problem:

I have reduced my previous example to "QThread vs OpenMP" - it is http://sire.googlecode.com/svn-history/r639/corelib/branches/users/chryswoods/techdocs/test_openmp_and_qthread.cpp, as mentioned in above link).

It really seems to be a QThread vs OpenMP issue (so we can take ImageMagick out of the equation...), on Mac OS X.

This crashes on Mac OS 10.6.2 (with latest Apple patches applied):

#include <QThread>
#include <QDebug>

#ifdef _OPENMP
#include <omp.h>
#else
#define omp_get_num_threads() 1
#endif

class OpenMPWorker : public QThread {
public:
    OpenMPWorker() : QThread() {}
    ~OpenMPWorker() {}
protected:
    void run();
};

void OpenMPWorker::run() {
    qDebug() << "Before parallel...";
    qDebug() << omp_get_num_threads();

    #pragma omp parallel {
        qDebug() << "In parallel!";
        qDebug() << omp_get_num_threads();
        #pragma omp for
        for (int i=0; i<10; ++i) {
            qDebug() << i;
        }
    }
}

int main(int argc, const char **argv) {
    Q_UNUSED(argc)
    Q_UNUSED(argv)
    OpenMPWorker worker;

    worker.start();
    worker.wait();
    return 0;
}

Here is the *.pro:

TEMPLATE = app
CONFIG += console
CONFIG -= app_bundle

# this enables OpenMP in the g++ compiler
QMAKE_CXXFLAGS += -fopenmp
LIBS += -lgomp

SOURCES += main.cpp

See also attachement, ready to compile (qmake, make, ...).

As metioned in QtCentre I successfully compiled and ran it on an older Ubuntu 8.10 (I think...) with g++ 4.3.2 on a Pentium III laptop (yes, year 1999 - still running ;) And my original code (using ImageMagick) ran fine on Windows, compiled with the MS Visual Studio 2005 Express compiler. So I am afraid this is more an Apple g++/"gomp"/OS X issue rather than QThread. Nevertheless I will file a bug report to qt-bugs at interest.com later on...

Cheers,
  Oliver

p.s. Does anyone know how to pass along "configure flags", when installing / building with Mac Ports? Specifically I would like to build my ImageMagick with the '--disable-openmp' flag, as a workaround for my above problem. Maybe "Invoking Variants" is what I am looking after: http://guide.macports.org/#using.variants.invoking (so I just need to figure out what the "OpenMP" variant might look like :) 
-- 
Oliver Knoll
Dipl. Informatik-Ing. ETH
COMIT AG - ++41 79 520 95 22
-------------- next part --------------
A non-text attachment was scrubbed...
Name: OpenMPAndQThread.zip
Type: application/x-zip-compressed
Size: 1365 bytes
Desc: OpenMPAndQThread.zip
Url : http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20100128/3620966b/attachment.bin 


More information about the Qt-interest-old mailing list