hello all,
I’m brazilian and want implement in CUDA the calc of PI for simulation de Monte Carlo, but no obtain. The following is the program in C. And how generator number in GPU?
[codebox]#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <string.h>
#define SEED 35791246
int main()
{
int niter=1000000;
double x,y;
int i,count=0;
double z;
double pi;
/* initialize random numbers */
srand( SEED );
count=0;
for ( i=0; i<niter; i++) {
x = (double)rand()/RAND_MAX;
y = (double)rand()/RAND_MAX;
z = x*x+y*y;
if (z<=1) count++;
}
pi=(double)count/niter*4;
printf(“pontos lancados %d , valor de pi %g \n”,niter,pi);
return 0;
}
[/codebox]
very THank you!!
Sorry errors in English.