Order of execution in Reduction Operation in OpenMP

孤街浪徒 提交于 2019-12-20 06:17:40

问题


Is there a way to know the order of execution for a reduction operator in OpenMP? In other words, I would like to know how the threads execute reduction operation- is it left to right? What happens when there are numbers that are not power of 2?


回答1:


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.




回答2:


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".



来源:https://stackoverflow.com/questions/16306440/order-of-execution-in-reduction-operation-in-openmp

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