2 Replies Latest reply on Aug 13, 2010 5:39 PM by mihzaha

    improbable if statement cost


      I have something like this:


      while(some long loop)


      if(something very improbable (0.001%) )






      what exactly happens there? Will the if ever converge, or will I have a single thread running alone after entering that if, making everything 2x slower in the workgroup until the end of the kernel?


      and another off topic question:

      is this correct for replacing an if? : b=(a+b!=0)*b/(a+b);

      I want to result to be 0 when both are 0, otherwise b/a+b

      (if the sum of a and b is 0,  a+b!=0 returns 0, 0*anything is 0, otherwise, the comparison returns 1?)



      and what about a simple if:

      if(something improbable ) do something small

      else do something else

      is that costly?


      Thank you again for the great help

        • improbable if statement cost
          If threads within a wavefront diverge on flow control, all branches of the flow control are executed by every thread in the wavefront that a single thread traverses. The threads that are not supposed to execute the branch have their output suppressed, but the computation still occurs.