This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.
Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
---|---|---|
Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |
Other format: | [Raw text] |
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
Attachment:
pgprPr6SoJyXs.pgp
Description: PGP signature
Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
---|---|---|
Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |