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.
Related Information
Was this topic helpful?
Document Information
Modified date:
06 December 2018
UID
swg21313062