Question about conditionals inside device function

Hi, I have encountered some weird issues in conditionals (if and else) inside a device function.

I am trying to execute a program where it’s structured as the following:

for(int i=0; counter < LIMIT && i < MAXITERATIONS_ALLOWED; ++i){
Variable solution;
if (condition 1)
update solution

if (condition 2)
update solution

If I execute with this manner, it’s taking quite slow to complete (8-30 seconds overall)

So I was wondering what’s going on inside the parallel world, and I commented out from if (condition 2) to the end. Now it’s taking more than 250 seconds to execute!! Does this mean that I need to use syncthreads() in somewhere between this code snippet? Or is this some compiler optimization issue?

Thank you.

How does your kernel look? You didn’t just paste this code into the kernel, did you? ;)