2

I added openMp code to some serial code in a simulator applicaton, when I run a program that uses this application the program exits unexpectedly with the output "The thread 'Win32 Thread' (0x1828) has exited with code 1 (0x1)", this happens in the parallel region where I added the OpenMp code, here's a code sample:

#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
            }

        }
    }

The scheduling was static before I made it dynamic, after I added dynamic with a chunk size of 1 the application proceeded a little further before it exited, can this be an indication of what is happening inside the parallel region? thanks

4

1 回答 1

0

当我读到它时,我更像是一个 Fortran 程序员而不是 C/C++,你的私有变量 curr_proc_info 在它第一次出现在对 pop_runnable_method 的调用中之前没有被声明(或定义?)。但是私有变量在进入并行区域时是未定义的。

我还认为您对 exception_occurred 的共享有点可疑,因为它表明任何线程都应该注意到任何线程上的异常,而不仅仅是注意到它的线程。当然,这可能是你的意图。

干杯

标记

于 2010-01-10T15:25:38.430 回答