Crash when using OpenMP and Qt

Discussion in 'Mac Programming' started by mpcoder, Jun 23, 2010.

  1. mpcoder macrumors newbie

    Joined:
    Mar 21, 2009
    #1
    Hi,

    I'm trying to parallelize a number-crunching part of an application to make use of a quad-core architecture using OpenMP and GCC 4.2. But what I think the problem is that this application uses Qt for the GUI and I'm trying to fork the worker threads on a secondary thread created by Qt which causes the program to crash - but of this I'm not sure.

    I'm seriously on the dark here since it's my first time working with either Qt or OpenMP, (or C++ for that matter). Any sort of guidance is greatly appreciated.

    Thank you,

    JM
     
  2. chown33 macrumors 604

    Joined:
    Aug 9, 2009
    Location:
    Brobdingnag
  3. mpcoder thread starter macrumors newbie

    Joined:
    Mar 21, 2009
    #3
    Code:
    Exception Type:  EXC_BAD_ACCESS (SIGBUS)
    Exception Codes: KERN_PROTECTION_FAILURE at 0x0000000000000008
    Crashed Thread:  8
    
    Thread 0:
    0   libSystem.B.dylib             	0x94c54266 mach_msg_trap + 10
    1   libSystem.B.dylib             	0x94c5ba5c mach_msg + 72
    2   com.apple.CoreGraphics        	0x90e2bb37 _CGSTerminateWindowList + 214
    3   com.apple.CoreGraphics        	0x90e2b4b2 _CGSReleaseWindowList + 452
    4   com.apple.CoreGraphics        	0x90e2b2e6 CGSReleaseWindow + 370
    5   com.apple.HIToolbox           	0x91680705 DisposePlatformWindow + 91
    6   com.apple.HIToolbox           	0x917554ab WindowData::~WindowData() + 709
    7   com.apple.HIToolbox           	0x9175b7a1 HIViewWrapperDef::~HIViewWrapperDef() + 37
    8   com.apple.HIToolbox           	0x91605768 HIObject::HandleClassHIObjectEvent(OpaqueEventHandlerCallRef*, OpaqueEventRef*, void*) + 274
    9   com.apple.HIToolbox           	0x916055d3 HIObject::EventHook(OpaqueEventHandlerCallRef*, OpaqueEventRef*, void*) + 55
    10  com.apple.HIToolbox           	0x9160513d DispatchEventToHandlers(EventTargetRec*, OpaqueEventRef*, HandlerCallRec*) + 1181
    11  com.apple.HIToolbox           	0x9160457b SendEventToEventTargetInternal(OpaqueEventRef*, OpaqueEventTargetRef*, HandlerCallRec*) + 405
    12  com.apple.HIToolbox           	0x916043e0 SendEventToEventTargetWithOptions + 58
    13  com.apple.HIToolbox           	0x91643e22 HIObject::Destruct() + 186
    14  com.apple.HIToolbox           	0x9167f8a9 WindowData::Destruct() + 697
    15  com.apple.CoreFoundation      	0x976d0516 _CFRelease + 182
    16  QtGui                         	0x01d00769 qt_mac_destructWindow(OpaqueWindowPtr*) + 41
    17  QtGui                         	0x01d02f0d QWidget::destroy(bool, bool) + 557
    18  QtGui                         	0x01db87c1 QWidget::~QWidget() + 449
    19                                	0x0004f461 ParamsFileDialog::~ParamsFileDialog() + 77
    20                                	0x00012a80 NucleusEditor::segmentNuclei() + 406
    21                                	0x0004f32b NucleusEditor::qt_metacall(QMetaObject::Call, int, void**) + 2307
    22  QtCore                        	0x028fb4bb QMetaObject::activate(QObject*, QMetaObject const*, int, void**) + 523
    23  QtGui                         	0x01d5c754 QAction::triggered(bool) + 68
    24  QtGui                         	0x01d5ea0f QAction::activate(QAction::ActionEvent) + 159
    25  QtGui                         	0x01d3cac9 qt_mac_activate_action(OpaqueMenuRef*, unsigned int, QAction::ActionEvent, bool) + 153
    26  QtGui                         	0x01d3d129 qt_mac_menu_event(OpaqueEventHandlerCallRef*, OpaqueEventRef*, void*) + 617
    27  com.apple.HIToolbox           	0x9160513d DispatchEventToHandlers(EventTargetRec*, OpaqueEventRef*, HandlerCallRec*) + 1181
    28  com.apple.HIToolbox           	0x9160457b SendEventToEventTargetInternal(OpaqueEventRef*, OpaqueEventTargetRef*, HandlerCallRec*) + 405
    29  com.apple.HIToolbox           	0x91620ecc SendEventToEventTarget + 52
    30  com.apple.HIToolbox           	0x916551e7 SendHICommandEvent(unsigned long, HICommand const*, unsigned long, unsigned long, unsigned char, OpaqueEventTargetRef*, OpaqueEventTargetRef*, OpaqueEventRef**) + 411
    31  com.apple.HIToolbox           	0x9167b959 SendMenuCommandWithContextAndModifiers + 59
    32  com.apple.HIToolbox           	0x9167b914 SendMenuItemSelectedEvent + 134
    33  com.apple.HIToolbox           	0x9167b82a FinishMenuSelection(MenuData*, MenuData*, MenuResult*, MenuResult*, unsigned long, unsigned long, unsigned long, unsigned char) + 162
    34  com.apple.HIToolbox           	0x91658494 MenuSelectCore(MenuData*, Point, double, unsigned long, OpaqueMenuRef**, unsigned short*) + 640
    35  com.apple.HIToolbox           	0x916e7030 MenuSelect + 104
    36  QtGui                         	0x01cfbeca QApplicationPrivate::globalEventProcessor(OpaqueEventHandlerCallRef*, OpaqueEventRef*, void*) + 11898
    37  com.apple.HIToolbox           	0x9160513d DispatchEventToHandlers(EventTargetRec*, OpaqueEventRef*, HandlerCallRec*) + 1181
    38  com.apple.HIToolbox           	0x9160457b SendEventToEventTargetInternal(OpaqueEventRef*, OpaqueEventTargetRef*, HandlerCallRec*) + 405
    39  com.apple.HIToolbox           	0x91620ecc SendEventToEventTarget + 52
    40  com.apple.HIToolbox           	0x91633603 ToolboxEventDispatcherHandler(OpaqueEventHandlerCallRef*, OpaqueEventRef*, void*) + 2579
    41  com.apple.HIToolbox           	0x916054f6 DispatchEventToHandlers(EventTargetRec*, OpaqueEventRef*, HandlerCallRec*) + 2134
    42  com.apple.HIToolbox           	0x9160457b SendEventToEventTargetInternal(OpaqueEventRef*, OpaqueEventTargetRef*, HandlerCallRec*) + 405
    43  com.apple.HIToolbox           	0x91620ecc SendEventToEventTarget + 52
    44  QtGui                         	0x01d10e74 QEventDispatcherMac::processEvents(QFlags<QEventLoop::ProcessEventsFlag>) + 596
    45  QtCore                        	0x029d2801 QEventLoop::processEvents(QFlags<QEventLoop::ProcessEventsFlag>) + 65
    46  QtCore                        	0x029d2a2d QEventLoop::exec(QFlags<QEventLoop::ProcessEventsFlag>) + 189
    47  QtCore                        	0x029d4d9e QCoreApplication::exec() + 174
    48                                	0x000071f8 main + 426
    49                                	0x00005b96 start + 54
    
    Thread 1:
    0   libSystem.B.dylib             	0x94c54266 mach_msg_trap + 10
    1   libSystem.B.dylib             	0x94c5ba5c mach_msg + 72
    2   com.apple.CoreFoundation      	0x976cde7e CFRunLoopRunSpecific + 1790
    3   com.apple.CoreFoundation      	0x976ceb04 CFRunLoopRun + 84
    4   com.apple.DesktopServices     	0x95575e17 TSystemNotificationTask::SystemNotificationTaskProc(void*) + 123
    5   ...ple.CoreServices.CarbonCore	0x9727e057 PrivateMPEntryPoint + 56
    6   libSystem.B.dylib             	0x94c85155 _pthread_start + 321
    7   libSystem.B.dylib             	0x94c85012 thread_start + 34
    
    Thread 2:
    0   libSystem.B.dylib             	0x94c54266 mach_msg_trap + 10
    1   libSystem.B.dylib             	0x94c5ba5c mach_msg + 72
    2   com.apple.CoreFoundation      	0x976cde7e CFRunLoopRunSpecific + 1790
    3   com.apple.CoreFoundation      	0x976ceb04 CFRunLoopRun + 84
    4   com.apple.DesktopServices     	0x95575f90 TFSEventsNotificationTask::FSEventsNotificationTaskProc(void*) + 216
    5   ...ple.CoreServices.CarbonCore	0x9727e057 PrivateMPEntryPoint + 56
    6   libSystem.B.dylib             	0x94c85155 _pthread_start + 321
    7   libSystem.B.dylib             	0x94c85012 thread_start + 34
    
    Thread 3:
    0   libSystem.B.dylib             	0x94c5b44e __semwait_signal + 10
    1   libSystem.B.dylib             	0x94c85dcd pthread_cond_wait$UNIX2003 + 73
    2   ...ple.CoreServices.CarbonCore	0x9727fe7f TSWaitOnCondition + 126
    3   ...ple.CoreServices.CarbonCore	0x9725ecd2 TSWaitOnConditionTimedRelative + 202
    4   ...ple.CoreServices.CarbonCore	0x9727fafc MPWaitOnQueue + 208
    5   com.apple.DesktopServices     	0x95580f72 TNodeSyncTask::SyncTaskProc(void*) + 84
    6   ...ple.CoreServices.CarbonCore	0x9727e057 PrivateMPEntryPoint + 56
    7   libSystem.B.dylib             	0x94c85155 _pthread_start + 321
    8   libSystem.B.dylib             	0x94c85012 thread_start + 34
    
    Thread 4:
    0   libSystem.B.dylib             	0x94c849c6 kevent + 10
    1   libSystem.B.dylib             	0x94c85155 _pthread_start + 321
    2   libSystem.B.dylib             	0x94c85012 thread_start + 34
    
    Thread 5:
    0   libSystem.B.dylib             	0x94ca36fa select$DARWIN_EXTSN + 10
    1   libSystem.B.dylib             	0x94c85155 _pthread_start + 321
    2   libSystem.B.dylib             	0x94c85012 thread_start + 34
    
    Thread 6:
    0   libSystem.B.dylib             	0x94c542c6 semaphore_timedwait_signal_trap + 10
    1   libSystem.B.dylib             	0x94c862af _pthread_cond_wait + 1244
    2   libSystem.B.dylib             	0x94c87b33 pthread_cond_timedwait_relative_np + 47
    3   ...ple.CoreServices.CarbonCore	0x9725ecfe TSWaitOnConditionTimedRelative + 246
    4   ...ple.CoreServices.CarbonCore	0x9727fafc MPWaitOnQueue + 208
    5   com.apple.DesktopServices     	0x95582ebc TFolderSizeTask::FolderSizeTaskProc(void*) + 104
    6   ...ple.CoreServices.CarbonCore	0x9727e057 PrivateMPEntryPoint + 56
    7   libSystem.B.dylib             	0x94c85155 _pthread_start + 321
    8   libSystem.B.dylib             	0x94c85012 thread_start + 34
    
    Thread 7:
    0   libSystem.B.dylib             	0x94c542c6 semaphore_timedwait_signal_trap + 10
    1   libSystem.B.dylib             	0x94c862af _pthread_cond_wait + 1244
    2   libSystem.B.dylib             	0x94c87b33 pthread_cond_timedwait_relative_np + 47
    3   com.apple.Foundation          	0x91e73dbc -[NSCondition waitUntilDate:] + 236
    4   com.apple.Foundation          	0x91e73bd0 -[NSConditionLock lockWhenCondition:beforeDate:] + 144
    5   com.apple.Foundation          	0x91e73b35 -[NSConditionLock lockWhenCondition:] + 69
    6   com.apple.AppKit              	0x9429e6e8 -[NSUIHeartBeat _heartBeatThread:] + 753
    7   com.apple.Foundation          	0x91e2ddfd -[NSThread main] + 45
    8   com.apple.Foundation          	0x91e2d9a4 __NSThread__main__ + 308
    9   libSystem.B.dylib             	0x94c85155 _pthread_start + 321
    10  libSystem.B.dylib             	0x94c85012 thread_start + 34
    
    Thread 8 Crashed:
    0                                 	0x0000642a gomp_resolve_num_threads + 42
    1                                 	0x000064b1 GOMP_parallel_start + 17
    2                                 	0x00bb9e23 yousef_nucleus_seg::runBinarization() + 277
    3                                 	0x007008ae ftk::NuclearSegmentation::Binarize(bool) + 480
    4                                 	0x0004b654 ftk::ProjectProcessor::SegmentNuclei(int) + 774
    5                                 	0x0004bd57 ftk::ProjectProcessor::ProcessNext() + 167
    6                                 	0x00008435 ProcessThread::run() + 41
    7   QtCore                        	0x0291835b QThreadPrivate::start(void*) + 187
    8   libSystem.B.dylib             	0x94c85155 _pthread_start + 321
    9   libSystem.B.dylib             	0x94c85012 thread_start + 34
     
  4. Hansr macrumors 6502a

    Joined:
    Apr 1, 2007
    #4
    Are the items/objects being used derived from a thread safe class?

    What happens if you break down the problem and unit test only the MP part independent of Qt?
     
  5. mpcoder thread starter macrumors newbie

    Joined:
    Mar 21, 2009
    #5
    It works. The problem definitely is when forking OpenMP threads from a secondary QThread.
     
  6. Hansr macrumors 6502a

    Joined:
    Apr 1, 2007
    #6
    Did you define: QMAKE_CXXFLAGS += -fopenmp in your project's .pro file?

    Does the same happen if you fork the openmp thread off in the qt main thread instead of a secondary one?
     

Share This Page