Hi:) I’m new to cuda programming. I’ve written 2 algorithms (one for the gpu and one for the cpu) that calculate the number p. I want to measure the time needed by both algorithms to be executed. I’m using events to measure the time needed by the gpu implementation, but I have problems calculating the exact time needed by the cpu to execute the algorithm. I also need to calculate the Gb/s (bandwidth) of both algorithms. I know of the mathematical type ((Bw+Br)/time) that gives the bandwidth, but I have some problems to define which time and what data to measure.

Below are both algorithms:

//GPU

**global** void montecarlo_p(float* res_D,float* random_xD,float* random_yD,int n)

{

float booli = 0.0f;

int idx = blockIdx.x*blockDim.x + threadIdx.x;

if (random_xD[idx]*random_xD[idx] + random_yD[idx]*random_yD[idx] <= 1)

booli = 1.0f;

res_D[idx] = booli;

}

//CPU

float cpuFunction_p_calc(int n,float* random_xH,float* random_yH){

float pH = 0.0f;

float count = 0.0f;

for (int j=0 ;j<n;++j){

if (random_xH[j]*random_xH[j] + random_yH[j]*random_yH[j] <= 1)
count ++;
}
pH = 4*(float)count /(float)n;

return pH;

}

I use res_D to store the times there’s a success and then counting them in cpu code as well as calculating the number p.

I’d appreciate any suggestions on how to measure the time needed by the cpu to execute the second function and the Gb/s rate of both algorithms:)

Thanks in advance…