Can C++ attributes be used to replace OpenMP pragmas?

风流意气都作罢 提交于 2020-02-03 04:06:51

问题


C++ attributes provide a convenient and standardized way to markup code with extra information to give to the compiler and/or other tools.

Using OpenMP involves adding a lot of #pragma omp... lines into the source (such as to mark a loop for parallel processing). These #pragma lines seem to be excellent candidates for a facility such as generalized attributes.

For example, #pragma omp parallel for might become [[omp::parallel(for)]].

The often inaccurate cppreference.com uses such an attribute as an example here, which confirms it has at least been considered (by someone).

Is there a mapping of OpenMP pragmas to C++ attributes currently available and supported by any/all of the major compilers? If not, are there any plans underway to create one?


回答1:


This is definitely a possibility and it's even something the OpenMP language committee is looking at. Take a look at OpenMP Technical Report 8 (https://www.openmp.org/wp-content/uploads/openmp-TR8.pdf) page 36, where a syntax for using OpenMP via attributes is proposed. Inclusion in TR8 doesn't guarantee its inclusion in version 5.1, but it shows that it's being discussed. This syntax is largely based on the work done in the original proposal for C++ attributes.

If you have specific feedback on this, I'd encourage you to provide feedback on this via the OpenMP forum (http://forum.openmp.org/forum/viewforum.php?f=26).



来源:https://stackoverflow.com/questions/37016119/can-c-attributes-be-used-to-replace-openmp-pragmas

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