OpenMP requires loop variable to be of integer type:
http://www.openmp.org/wp-content/uploads/openmp-4.5.pdf#page=68
The syntax of the loop construct is as follows:
#pragma omp for ...
for-loops
...
Specifically, all associated for-loops must have canonical loop form (see Section 2.6 on page 53).
3 The iteration count for each associated loop is computed before entry to the outermost loop. If execution of any associated loop changes any of the values used to compute any of the iteration counts, then the behavior is unspecified.
6 The integer type (or kind, for Fortran) used to compute the iteration count for the collapsed loop is implementation defined.
You can't use variables of floating type in openmp loop construction. Your first loop has i
integer which is correct and second has float
typed variable which is incorrect. Canonical loop form is defined in "2.6 Canonical Loop Form" - http://www.openmp.org/wp-content/uploads/openmp-4.5.pdf#page=62 as
for (init-expr; test-expr; incr-expr) structured-block
...
var - One of the following:
* A variable of a signed or unsigned integer type.
* For C++, a variable of a random access iterator type.
* For C, a variable of a pointer type
incr-expr One of the following:
...
* var += incr
incr A loop invariant integer expression
and your second loop has not canonical form and can't be paralleled.
for(x[0]=0.000000; x[0]<10.000000; x[0]+=1.000000)
It will be hard to compiler to get loop iteration count in advance with floating point values of var and incr: some decimal constants can't be represented exactly in floating point format (for example, 0.2 in floating point is 0f3FC999999999999A; and 0.1 + 0.2 is 0.30000000000000004 in many languages, check https://0.30000000000000004.com/).
You can try array of integers or long
s or long long
s:
#define MAX_DIMENSIONS 10
long long x[MAX_DIMENSIONS];
unsigned int i,y=0;
#pragma offload target(mic) in(x[MAX_DIMENSIONS],i,y)
{
#pragma omp parallel for
for(x[0]=0; x[0] < 10; x[0] += 1)
}
Or you can try to estimate correct loop count for floating point range before loop and then use integer iterators in parallel loop as var and incr (be sure to do correct rounding).