IBM Support

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

Troubleshooting


Problem

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.

[{"Product":{"code":"SSJT9L","label":"XL C\/C++"},"Business Unit":{"code":"BU054","label":"Systems w\/TPS"},"Component":"Compiler","Platform":[{"code":"PF002","label":"AIX"},{"code":"PF016","label":"Linux"}],"Version":"10.1","Edition":"","Line of Business":{"code":"LOB08","label":"Cognitive Systems"}},{"Product":{"code":"SSGH3R","label":"XL C\/C++ for AIX"},"Business Unit":{"code":"BU058","label":"IBM Infrastructure w\/TPS"},"Component":" ","Platform":[{"code":"","label":""}],"Version":"","Edition":"","Line of Business":{"code":"LOB08","label":"Cognitive Systems"}},{"Product":{"code":"SSXVZZ","label":"XL C\/C++ for Linux"},"Business Unit":{"code":"BU058","label":"IBM Infrastructure w\/TPS"},"Component":" ","Platform":[{"code":"","label":""}],"Version":"","Edition":"","Line of Business":{"code":"LOB57","label":"Power"}}]

Document Information

Modified date:
06 December 2018

UID

swg21313062