n.treutner

Variables in a for-loop

Discussion created by n.treutner on May 10, 2010
Latest reply on Jun 7, 2010 by n.treutner

Hi Everyone,

i can't quite get my head around a problem i have, when trying to implement the backward pass of a dynamic programming algorithm.

 

I attached the code, that won't work. i added the backlinks-initialization in order to make sure, i have valid entries to add to ww (this would be computed beforehand in the 1st DP-pass).

The output-line is just for testing purposes. it only works, if i remove the "ww = BackLinks[Y * w + ww];" line. so i guess, i can't really change the ww-variable inside a loop. is that correct? why?

do you have any workaround - or probably a good idea, how to tackle the whole dynamic-programming issue in opencl? (since the "classic" way, is not a perfect parallelization-candidate...)

Thanks for your help

for (int Y = 1; Y < height; Y++) { for (int ww = 0; ww < w; ww++) { BackLinks[Y * w + ww] = 0; } } // Dynamic Programming (scanline): backward pass --- int ww = 0; for (int Y = height-1; Y > 1; Y--) { output[(X + Y * width)].x = 0.0f; ww = BackLinks[Y * w + ww]; }

Outcomes