Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
588 views
in Technique[技术] by (71.8m points)

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

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 with the /openmp command line option in Visual Studio 2012, it gives me

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

I don't know why 'for' statement has improper form.

What is a proper for statement to OpenMP? How do I apply it to my for loop?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...