开发者

Loop Dependence

Say I have a nested loop as:

for(m=0;m<10;m++)
   for(n=0;n<10;n++)
      result[n][m]=result[m-3][n-2]
                   +result[n+1];

Would we call any of the two lo开发者_运维知识库ops parallelizeable? My understanding is there is dependence on both the two variables n and m so we can't parallelize any of the loops.

Please clarify. Also, what type of dependences is this?

Thanks!


You are correct that the example loop there is not parallelizeable (or at least not easily), but it's not because the inner contents rely on both m and n (as those could be passed as arguments to a new thread or whatever). It's because later calculations depend on the results of earlier calculations. For example, the value of result[10][12] depends on result[9][8] which depends on result[5][7] etc.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜