Will random result break SIMD?

Hello all,

I want to do some work based on Monte Carlo method, and I have a question.

A basic example is like that:

  1. sum_accept = 0; sum_random = 0;

  2. sum_random++; random with uniform distribution on [0, 1].

  3. If result larger than 0.5, then sum_accept++;

  4. Do 2 and 3 until sum_accept == 1000;

Just like this. So the code for every code is exactly the same. But when running it, there surely be different for different core. Is this the case SIMD? Or say, will it perform will in GPU?

Thank you.

SIMD is in good shape while the majority of threads within one warp have work to do and while all these warps are executing non-divergent code. For the definition of a warp, refer to the CUDA programming guide.

Your problem seems non-divergent while in the loop, and the vast majority of threads will terminate at roughly the same time, however some outlier threads will keep running a bit longer. So you will have some warps where only one or two threads remain active.

To improve performance in such cases, consider

a) dynamically re-populating any finished threads with new work
or
b) compacting the threads within a thread block periodically e.g. by transferring their state through shared memory to a different thread.