4 Replies Latest reply on Jan 30, 2010 9:50 AM by Svinarenko

    [Brook+] Monte-Carlo

    Svinarenko

      Hello! I am beginer of programming for Brook+. I have a problem with output stream. Who knows how to write

      value of variable (res) to stream (result)?

      #define MAX 32000 #include <windows.h> #include <conio.h> #include <time.h> #include <math.h> #include <brook\brook.h> #include <stdio.h> kernel void GPU_area(float x[],float y[], float p, out float result<>) { float res float max = 32000; float hits = 0; float i; for (i = 0; i < max; i++) { if (x[i] * x[i] + y[i] * y[i] <= p * p) hits++; } res = 4*p * p * hits / max; result = res; } int main(int argc, char** argv) { float x[MAX]; float y[MAX]; float c<1>; float c_out[1]; double area(double p); double R, res; int time; int i; printf("This program compares MonteCarlo algoritm running on CPU and GPU\n"); printf("This program using ATI Stream.\n"); printf("Please, input radius: "); scanf("%d",&R); //CPU time = GetTickCount(); res = area(R); printf("Time is: %d",GetTickCount()-time); printf("\nResult is: %f",res); //GPU for (i = 0; i < MAX; i++) { x[i] = rand()%(int)(R); y[i] = rand()%(int)(R); } time = GetTickCount(); GPU_area(x,y,R,c); streamWrite(c,c_out); printf("Time is: %d",GetTickCount()-time); printf("\nResult is: %f",c_out[1]); getch(); return 0; } double area(double p) { int hits = 0; int i; srand(time(NULL)); for (i = 0; i < MAX; i++) { double x = rand()%(int)(p); double y = rand()%(int)(p); if (x * x + y * y <= p * p) hits++; } return 4*p * p * hits / MAX; }