IBM Support

OpenMP3.0 task queue does not support C++ try/throw/catch block

Technote (troubleshooting)


Problem(Abstract)

Throwing an exception in an OpenMP task causes a program to hang or produce a core dump.

Symptom

Program hangs or produces a core dump.

Compiling the following code sample will cause the program to hang or produce a core dump:

Command:

xlC_r -qmaxmem=-1 -lxlsmp -qsmp=omp -qthreaded test.c

Code sample:

/* test.c */

#include<stdio.h>
#include<omp.h>
#include<assert.h>

struct MyExcept {
       int task_id;
       int thread_id;
};

void mytask (int i)
{
       #pragma omp task firstprivate(i)
       {
              try {
                     MyExcept e;
                     //#pragma omp task shared(e)
                     e.task_id = i;
                     //#pragma omp task shared(e)
                     e.thread_id = omp_get_thread_num();
                     //#pragma omp taskwait
                     printf ("MyExcept(%d %d) thrown by task %d\n", e.task_id, e.thread_id, i);
                     throw e;
              }
              catch (MyExcept e) {
                     printf ("MyExcept(%d %d) caught by task %d\n", e.task_id, e.thread_id, i);
                     //#pragma omp task
                     assert (e.task_id==i);
                     assert (e.thread_id==omp_get_thread_num());
                     //#pragma omp taskwait
              }
              catch (...) {
                     printf ("other stuff caught\n");
              }
       }
}


int main()
{
       #pragma omp parallel
       {
              #pragma omp single
              for (int i=0; i<10; i++)
              {
                     mytask(i);
              }
              //#pragma omp taskwait
       }
       return 0;
}


Resolving the problem

Avoid throwing exceptions for try, catch, or throw block constructs in OpenMP task queues.

Related information

README Updates for XL C/C++
README Updates for XL C/C++ for Linux V10.1

Cross reference information
Segment Product Component Platform Version Edition
Software Development XL C/C++ for AIX
Software Development XL C/C++ for Linux

Document information

More support for: XL C/C++
Compiler

Software version: 10.1

Operating system(s): AIX, Linux

Reference #: 1313062

Modified date: 20 July 2009


Translate this page: