OpenMP® Forum

Discussion on the OpenMP specification run by the OpenMP ARB. OpenMP and the OpenMP logo are registered trademarks of the OpenMP Architecture Review Board in the United States and other countries. All rights reserved.

From the 2.7.2 text it isn't obvious to me where exactly in the C/C++ grammar should #pragma omp declare simd be specified or what should happen if it is a function declaration with multiple declared functions.What is supposed to happen for#pragma omp declare simd int foo (int), bar (), baz (double);? Shall it be handled as if there were 3 separate function declarations, with 3 #pragma omp declare simd directives before each?What about:#pragma omp declare simd int foo (int), var;? Shall this be an error?

And, as has been raised before, I think it is undesirable to restrict just a single simdlen directive, often it is desirable to have one function compiled for more than one simdlen (e.g. one version that would use 128-bit vectors, one that would use 256-bit vectors, etc.). Then some callers could use just the 128-bit vector variant, if used in SIMD loops with lower safelen in one place and in SIMD loops with higher safelen in another place (or in say -msse4 vs. -mavx2 compiled code).

For #pragma omp declare simd, the spec lists reduction as an allowed clause? What is it useful for? From what I understand, reductions on #pragma omp simd are supposed to be treated like any other private variables, except that immediately before the loop they are constructed resp. initialized from the reduction initializer clause or builtin reduction initializer, and after the simd loop combined. But how is it useful to tell that fact to the elemental function? If the elemental function were to update the reduction vars, either it would need to be done by passing them by reference resp. address of the var, or by returning it from the elemental function.

If there is a reason for reduction clauses to be allowed, then guess the spec should make it clear that the reduction clause should only refer to arguments (i.e. have argument-list rather than list), and:"Each argument can appear in at most one uniform or linear clause." should probably also include "or reduction" too.

Also, regarding the syntax where #pragma omp declare simd comes before template, are the parameter names in the uniform/linear/aligned/reduction (for reduction see previous comment) clauses the only things that is parsed actually after processing the function declaration? I mean:

Currently in the parsing code I'm working, this adds simdlen (4) aligned (1st argument of foo <4> : 16) linear (2nd argument of foo <4> : 32), i.e. while a and b in the clauses variable list are looked up after parsing the fn decl,the expressions N * 4, sizeof (*a) * 16 and sizeof (*b) * N * 16 are parsed in the context where the #pragma omp declare simd line is written. Is that right, or do you expect to defer parsing the expressions somehow (guess that would be quite hard)and parse the expressions only later on when the template parameter N and parameters a and b are in scope?