开发者

OPenMP loop increment

Is it OK to use loop increment greater than 1?

开发者_高级运维
#pragma omp parallel for schedule(dynamic, 1000)
for (int i=0; i<100000; i+=10)
{
    // do something that uses i
}

Thank you.


Yes.

The allowed form for the for loop is:

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

Where incr_expr is any of:

++var
var++
--var
var--
var += incr
var -= incr
var = var + incr
var = incr + var
var = var - incr

See http://www.openmp.org/mp-documents/OpenMP3.1.pdf page 40.


Another way of thinking of it is:

#pragma omp parallel for schedule(dynamic, 1000)
for (int i=0; i<100000; i+=10)
{
    // do something that uses i
}

Could be rewritten as

#pragma omp parallel for schedule(dynamic, 1000)
for (int j=0; j<10000; j++)
{
    i = 10*j;
    // do something that uses i
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜