error C3017: termination test in OpenMP 'for' statement has improper form

后端 未结 2 847
[愿得一人]
[愿得一人] 2020-12-21 05:58

I have a for loop that has all variables defined

#pragma omp parallel for
for(long long l = 1; l<=sqrtt; l++) ...

When I compile this wi

相关标签:
2条回答
  • 2020-12-21 06:37

    I was having the same problem. I had this:

    #pragma omp parallel for
    for(int i = 0; i < stop; i++){ 
        //My code
    }
    

    Then I discovered that the problem was that my variable stop was a double, so, how in my case I needed that stop was a double, I had to do a casting:

    #pragma omp parallel for
    for(int i = 0; i < (int)stop; i++){ 
        //My code
    }
    

    And then all worked :)

    I hope this can help.

    0 讨论(0)
  • 2020-12-21 06:58

    The OpenMP 3.1 standard prescribes a very strict form for the for-loop construct (see pag.39):

    for (init-expr; test-expr; incr-expr) structured-block
    

    In particular, test-expr must look like one of the following:

    var relational-op b
    b relational-op var
    

    where relational-op is one of <,<=,>,>= and b is a loop invariant expressions of a type compatible with the type of var.

    Other than that you must ensure that:

    The values of the loop control expressions of the loops associated with the loop construct must be the same for all the threads in the team.

    So, coming back to your case, I would check sqrtt to be a loop invariant and to have the same value for all threads.

    A little side note

    long long isn't standard in C++ prior to C++11, see for instance this question on SO.

    0 讨论(0)
提交回复
热议问题