我在模拟器应用程序中将openMp代码添加到某些串行代码中,当我运行使用此应用程序的程序时,程序意外退出并输出“线程'Win32线程'(0x1828)已退出代码1(0x1) “,这发生在我添加了OpenMp代码的并行区域, 这是一个代码示例:
#pragma omp parallel for private (curr_proc_info, current_writer, method_h) shared (exceptionOccured) schedule(dynamic, 1)
for (i = 0 ; i < method_process_num ; i++)
{
current_writer = 0;
// we need to add protection before we can dequeue a method from the methods queue,
#pragma omp critical(dequeueMethod)
method_h = pop_runnable_method(curr_proc_info, current_writer);
if(method_h !=0 && exceptionOccured == false){
try {
method_h->semantics();
}
catch( const sc_report& ex ) {
::std::cout << "\n" << ex.what() << ::std::endl;
m_error = true;
exceptionOccured = true; // we cannot jump outside the loop, so instead of return we use a flag and return somewhere else
}
}
}
在我将其设置为动态之前,调度是静态的,在我添加了一个块大小为1的动态后,应用程序在退出之前进一步前进了一点,这是否表明并行区域内发生了什么? 谢谢
答案 0 :(得分:0)
当我读到它,而且我更像是一个Fortran程序员而不是C / C ++时,你的私有变量curr_proc_info在它首次出现在pop_runnable_method的调用之前没有声明(或定义?)。但是在进入并行区域时私有变量是未定义的。
我还认为你对exception_occurred的共享有点可疑,因为它表明任何线程都应该注意到任何线程上的异常,而不仅仅是注意到它的线程。当然,这可能是你的意图。
干杯
标记