Here is the pseudo-code. What I’m trying to do is to prevent threads that are not launched yet from doing anything if one of previous threads met the ‘timed out’ condition (worked for more than allowed number of iterations).
shared bool bStopWorking;
global void Kernel(int* pTimedOut)
{
const int nThreadIdx = __mul24(blockDim.x, blockIdx.x) + threadIdx.x;
const int nThreadIdxInBlock = threadIdx.x;
const int nNumThreads = __mul24(blockDim.x, gridDim.x);
if (nThreadIdx == 0)
bStopWorking = false;
__syncthreads();
for (int nTestCase = nThreadIdx;
nTestCase < nNumTestCases;
nTestCase += nNumThreads)
{
if (bStopWorking)
break;
bool bTimedOut = false;
EvaluateTestCase(&bTimedOut);
if (bTimedOut)
{
bStopWorking = true;
__syncthreads();
}
}
if (bStopWorking)
*pTimedOut = 1;
}
pTimedOut returns 1 when timed out condition is met, however, the workflow is not stopped and all the threads from the grid of blocks do their full job.
Thanks in advance!