1

Lawrence Livermore National Laboratory の Blaise Barney による OpenMP チュートリアルで、OpenMP を使用した並列プログラミングの学習を始めたばかりです。そこでは、多くの場所で、並列領域に分岐したり、並列領域から分岐したりすることは違法であると指定されていますが、少なくともその理由は少しわかりません。

誰かがその理由を説明できれば、OpenMP に慣れることは非常に役に立ちます。ありがとう!

4

1 に答える 1

2

A parallel region will require some set-up and take-down to operate correctly. For example, entering the region may require spawning threads, while exiting may require synchronization. The compiler generates the material "in the middle" of the parallel region with the assumption that this set-up and take-down have occurred.

If you were to branch into a parallel region, then you've skipped the set-up and it's hard to say what would actually happen. I.e., where would the threads be? Would you even be in the function call that, e.g., pthread was supposed to invoke for you?

And if you were to branch out, would you even be in the non-parallel section of your code? What if all the threads were to execute this section? What about race conditions?

So because the compiler must make assumptions of your behavior to generate parallel code correctly, you would do well to honor those assumptions.

于 2013-06-30T20:30:49.993 に答える