Changes

Jump to: navigation, search

Kernal Blas

189 bytes added, 22:56, 2 April 2018
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, yint 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>
96
edits

Navigation menu