Order of execution in Reduction Operation in OpenMP

喜夏-厌秋 提交于 2019-12-02 12:59:50

I think you'll find that OpenMP will only reduce on associative operations, such as + and * (or addition and multiplication if you prefer) which means that it can proceed oblivious to the order of evaluation of the component parts of the reduction expression across threads.

I strongly suggest that you proceed in the same way when using OpenMP, trying to either figure out or constrain the order of execution will at best turn your parallel program into a sequential one, at worst proceed to give you effectively random results.

I fail to understand your last sentence about numbers that are not powers of 2.

As @JimCownie has pointed out, operations such as + and * are not strictly associative on floating-point numbers. Construe my reference to associative operations in the first sentence to mean operations which are, when applied to real numbers, associative, but which, for reasons well understood by skilled practitioners of numerical computing on modern computers, fail to be associative when applied to floating-point numbers.

The order of reduction is not specified by the OpenMP standard.

The standard allows reductions on floating point numbers (using +, for instance), which is not associative. If you don't understand that you should go and read "What every computer scientist should know about floating-point arithmetic".

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!