Dependency problem how to solve the problem that i am facing with these type of dependeny

Recently i am facing a situation well i would like to explain it with an example which goes below

int previous_pixel;
fs=get_global_id(0);

us=fs%frame_width;

if(us==0)
previous_pixel=0;

if(input_buffer[fs]==12)
previous_pixel=fs;

else if(previous_pixel!=0)
{
//operation being done
calculate some value h here than,
previous_pixel=h;
}

well this is my condition i how can i solve this dependency problem for previous_pixel. Its taking the value zero for all threads.

Thanks in advance
Best regards
Megharaj

Can you post a bit more about the dimensions you are using ?
What is frame_width, What is the workgroup size and so on.

Thanks a lot for your replay.

I got the solution for that , I am running one row in one thread because dependency was there only inside a row, each row were independent of other so got the solution as shown below.

Initially I was doing like this

Global_worksize=(width*height)

__kernel(…)

{

Id=get_global_id(0);

//operation

}

Now

Global_worksize=(height)//taking only height number of threads

__kernel(…)

{

Id=get_global_id(0);

For(i=0;i<width;i++)

{

//operation

}//end of for loop

}

Now the problem is solved but

Disadvantage :

Number of parallel threads have been reduced.

Best regards

Megharaj.