implemente the calc de PI for Monte Carlo Simulation

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 );


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++;



printf(“pontos lancados %d , valor de pi %g \n”,niter,pi);

return 0;



very THank you!!

Sorry errors in English.