Changes

Jump to: navigation, search

GPU610/DPS915 CUDA PI

867 bytes added, 01:36, 4 November 2013
Code Snippet
==== '''Code Snippet''' ====
Serial Working Kernel Parallel CUDA Pi Calculation Algorithm __global__ void findPi(float *estimatedPi, curandState *states, unsigned int taskElements, float seed) { unsigned int task_id = blockDim.x * blockIdx.x + threadIdx.x; // loops through user amount linear sequence of rounds of sets threads x-axis int score = 0; float xCoord; float yCoord; // 'random' generated value using curand, initialize curand using task_id, and seed parameter curand_init(seed, task_id, 0, &states[task_id]); // tally number of pointstask elements for(int i = 0; i < pointstaskElements; i++) {x // assigned each point coordinate values xCoord = randNumcurand_uniform (&states[task_id]);y yCoord = randNumcurand_uniform (&states[task_id]); // check determine if point resides coordinate is within the circle if (((xxCoord*x) xCoord + (yyCoord*y)yCoord) <= 1.00f) { score++; } } // calculate estimated value of pifor this particular taskpi estimatedPi[task_id] = (4.0 0f * (floatscore)score/(float)pointstaskElements; } }
==== '''Compilation and Running''' ====

Navigation menu