OpenMP nécessite variable de boucle pour être de type entier:
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.
Vous ne pouvez pas utiliser des variables de type flottant dans la construction en boucle OpenMP. Votre première boucle a i
entier qui est correct et la seconde a float
variable typée qui est incorrecte. sous forme de boucle Canonical défini dans « 2.6 Canonique forme de boucle » - http://www.openmp.org/wp-content/uploads/openmp-4.5.pdf#page=62 comme
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
et votre deuxième boucle n'a pas la forme canonique et ne peut être mis en parallèle.
#pragma omp parallel for
for(x[0]=0.000000; x[0]<10.000000; x[0]+=1.000000)
Il sera difficile de compilateur pour obtenir boucle nombre d'itérations à l'avance avec des valeurs en virgule flottante de var et INCR: certaines constantes décimales ne peuvent pas être représentées exactement au format virgule flottante (par exemple, 0,2 à virgule flottante est 0f3FC999999999999A et 0,1 + 0,2 est 0,30000000000000004 dans de nombreuses langues, vérifiez https://0.30000000000000004.com/).
Vous pouvez essayer tableau d'entiers ou long
s ou 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)
/* code here */
}
Ou vous pouvez essayer d'estimer le nombre de boucles correct pour une plage de virgule flottante avant boucle et utiliser ensuite les itérateurs entiers dans la boucle parallèle var et incr (assurez-vous de bien arrondir).
Copie possible de [OpenMP parallel pour avec plage à virgule flottante] (https: // stackoverflow.com/questions/14418908/openmp-parallel-for-with-floating-point-range) – osgx