Reputation: 25
I 'm trying to create a parallel block in openMP with multiple for loops inside. What I've done so far (or at least the important parts i guess, i can post the whole program if neccessary):
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <omp.h>
int main(int argc, char**argv) {
[...]
int i, j, N=200, num_t=2;
[...]
M = (int) round(M);
[...]
double **u = malloc(N * sizeof(double));
for (i = 0; i < N; i++){
u[i] = (double*) malloc(M * sizeof(double));
}
/* Initialize time and space arrays */
double *x, *t;
x = (double*) malloc(N * sizeof(double));
t = (double*) malloc(M * sizeof(double));
#pragma omp parallel num_threads(num_t) private(i,j) shared(x,t,u,dt,dx,N,M,c) default(none)
{
#pragma omp for
for (i = 0; i < N; i++)
x[i] = 0 + i * dx;
#pragma omp for
for (i = 0; i < M; i++)
t[i] = 0 + i * dt;
/* Initial Conditions */
#pragma omp for
for (i = 0; i < N; i++) {
[do stuff with `u` array]
}
/* boundary conditions. */
#pragma omp for
for (j = 0; j < M; j++) {
[more stuff with `u` array]
}
#pragma omp for collapse(2)
for (j = 0; j< M - 1; j++) {
for(i = 1; i < N - 1; i ++) {
[even more stuff with `u` array].
}
}
}
And why I try to compile this with gcc -Wall -fopenmp -fsanitize=address exe1.c -o t1_1 -lm
I get the following error
exe1.c:56:15: error: invalid controlling predicate
for (i = 0; i < M; i++)
^
exe1.c:67:15: error: invalid controlling predicate
for (j = 0; j < M; j++) {
^
exe1.c:73:15: error: invalid controlling predicate
for (j = 0; j< M - 1; j++) {
The only way I 've managed to actually compile this, is by ending the parallel block (not sure if this is the correct terminology) after the first #pragma omp for
:
#pragma omp parallel num_threads(num_t) private(i,j) shared(x,t,u,dt,dx,N,M,c) default(none)
{
#pragma omp for
for (i = 0; i < N; i++)
x[i] = 0 + i * dx;
}
My gcc version is gcc (Ubuntu 7.5.0-3ubuntu1~18.04) 7.5.0
and openMP #define _OPENMP 201511
.
Now, I 've read lots of posts here about this error comming up (invalid controlling predicate
) but most of them seems to come from not conforming to a "Canonical Loop Form". Think my code does conform. What could be the issue?
Thank you:)
Upvotes: 0
Views: 134
Reputation: 74455
You are getting errors in loops involving M
probably because M
is not of an integer type. A clue in favor of that assumption is that you are rounding its value at some point:
M = (int) round(M);
You cannot use floating-point variables in canonical loop forms. So this doesn't work:
#pragma omp for
for (i = 0; i < M; i++)
t[i] = 0 + i * dt;
but this should work:
#pragma omp for
for (i = 0; i < (int)M; i++)
t[i] = 0 + i * dt;
Upvotes: 2