Hi! OpenMP defines a canonical loop form (in OpenMP 4: »2.6 Canonical Loop Form«, in OpenMP 3.1 as part of »2.5.1 Loop Construct«) that says that the loop index variable »must not be modified during the execution of the for-loop other than in incr-expr«. The following code, which violates this when modifying i in the loop body, thus isn't a conforming program, and GCC may then exhibit unspecified behavior. Instead of accepting it silently, I wonder if it makes sense to have GCC detect this violation and warn about the unspecified behavior, or even turn it into a hard error?
#include <omp.h>
#include <stdio.h>
int
main(void)
{
#pragma omp parallel
#pragma omp for
for (int i = 0; i < 20; i += 2)
{
printf("%d: #%d\n", omp_get_thread_num(), i);
/* Violation of canonical loop form. */
--i;
}
return 0;
}
2: #8
2: #9
0: #0
0: #1
0: #2
0: #3
3: #10
3: #11
1: #4
1: #5
1: #6
1: #7
6: #16
6: #17
4: #12
4: #13
5: #14
5: #15
7: #18
7: #19
Grüße,
Thomas
pgpJYlK_I5DFR.pgp
Description: PGP signature
