- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
#define NX (256)
...
#pragma prefetch Array:0:NX
is invalid. The compiler should be able to accept any expression that is deamed constant.
Jim Dempsey
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Sergey, please re-read the first post.
At issue is the preprocessor, with respect to #pragma, is not in line with respect to #if
#define X 40
#define Xtoo (20 * 2)
#if (X == 40)
expands
#endif
#if (Xtoo == 40)
expands
#endif
#pragma prefetch Array:0:X ! ok
#pragma prefetch Array:0:Xtoo ! fails
The only requirement of the 3rd argument to the prefetch is that it be known at compile time (prior to the statement).
The #pragma processing complains about the "(", and the rest of the constant expression.
Jim Dempsey
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Sergey,
This is valid preprocessor syntax:
#define A 2
#define B 3
...
#if (((A+B)&1)==1)
// odd code expansion
#else
// even code expansion
#endif
At issue here is at times it is a requirement to include the ('s in the macro name.
At other times, due to programmers preference/style, you may wish to include ('s, example
#define myMacro (someoneElsesMacro)
Where the #define includes the ('s due to the situation where someoneElsesMacro, which is outside of your control, may not be suitable for your use (without you adding parenthesis). With or without the added paranthesis, the expression is calcuable by the preprocessor, and should be reduced to the value, whenenever the preprocessor required the evaluation of the literal expression. Such as in the even/odd test above, as well as in the #pragma prefetch pointer:level:offset.
The case where this came up for me, is I have a 3D array, defined at compile time with dimensions NX, NY, NZ. I need to specify the prefetching in terms of these parameters, as well as in terms of a #define REAL ..., where ... is float or double (or in the future longdouble).
It is not unreasonable to want to use a derived parameter in terms of constituent parameters, and then use this where a compile time value is required.
Jim Dempsey
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Yes, that is what I am saying is the problem. I am laying out the case where it is impractical or impossible to specify the 3rd token without parenthesis. And therefore requesting that the compiler be fixed.
Jim Dempsey
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Sergey, you are still not getting the problem:
Realistic mockup:
[cpp]
#define CACHE_LINE_SIZE 64
#define REAL float
...
#if (REAL==float)
#define SIZEOF_REAL 4
#elif (REAL==double)
#define SIZEOF_REAL 8
#else
#error ??
#endif
#define N_REALS_PER_CACHE_LINE (CACHE_LINE_SIZE / SIZEOF_REAL)
// 4 cache lines ahead
#define PREFETCH_DISTANCE (N_REALS_PER_CACHE_LINE * 4)
-----------------
icc -openmp -O3 -std=c99 -vec-report=3 -mmic diffusion_tiled_HT2.c -o diffusion_tiled_HT2_xphi
# Diagnostic PREFETCH_DISTANCE =((64 / 4) * 4)
# Diagnostic N_REALS_PER_CACHE_LINE =(64 / 4)
# Diagnostic CACHE_LINE_SIZE =64
# Diagnostic SIZEOF_REAL =4
# Diagnostic REAL =float
diffusion_tiled_HT2.c(369): error: expected positive integer
#pragma prefetch f1_t_c:0:PREFETCH_DISTANCE
^
diffusion_tiled_HT2.c(369): warning #1672: invalid expression in pragma will be ignored
#pragma prefetch f1_t_c:0:PREFETCH_DISTANCE
^
[/cpp]
Now then, is it reasonable for me to use "()"'s in my #defines?
If so, then why is it unreasonable to have them on the #pragma prefetch
...when the preprocessor and compiler can fully reduce the expression to a constant (as required by prefetch).
Jim Dempsey
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Apparently
const int pfd = PREFETCH_DISTANCE;
#pragma prefetch f1_t_c:0:pfd
works. To quote Martin Johnson (1970's Laugh-In): "but stupid!"
The tokens contain in the macro express a constant. Why clutter-up the code with unnecessary statements.
Jim Dempsey
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page