96
edits
Changes
→Assignment 2
<syntaxhighlight lang="cpp">
__global__ void calculate(float *sumd_pi, int nbincurandState *states, float step, int nthreads, int nblocksn) { unsigned int itid = threadIdx.x + blockDim.x * blockIdx.x; float points = 0; float x, y; int idx = blockIdx.x * blockDim.x + threadIdx.xcurand_init(1000, tid, 0, &states[tid]); // Sequential thread index across the blocks Initialize CURAND for (int i = idx0; i< nbinn; i += nthreads*nblocks+) { x = curand_uniform(i + &states[tid]); //calls random float from 0.0to 1.50 y = curand_uniform(&states[tid])*step; sum[idx] points += 4.0 / (1.0 + x*x+ y*y <= 1.0f);// count if x & y is in the circle.
}
d_pi[tid] = 4.0f * points / n; // return estimate of pi}
</syntaxhighlight>
<br>