2

シミュレータ アプリケーションの一部のシリアル コードに openMp コードを追加しました。このアプリケーションを使用するプログラムを実行すると、プログラムが「The thread 'Win32 Thread' (0x1828) has exited with code 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 で動的を追加した後、アプリケーションは終了する前に少し進みました。これは、並列領域内で何が起こっているかを示している可能性がありますか? ありがとう

4

1 に答える 1

0

私がそれを読んだとき、私は C/C++ よりも Fortran プログラマーに近いので、プライベート変数 curr_proc_info は pop_runnable_method への呼び出しで最初に現れる前に宣言 (または定義?) されていません。ただし、プライベート変数は、並列領域へのエントリでは未定義です。

また、例外が通知されたスレッドだけでなく、任意のスレッドの例外が任意のスレッドによって通知される必要があることを示唆しているため、 exception_occurred の共有は少し怪しいと思います。もちろん、それはあなたの意図かもしれません。

乾杯

マーク

于 2010-01-10T15:25:38.430 に答える