cancel
Showing results for 
Search instead for 
Did you mean: 

Archives Discussions

Svinarenko
Journeyman III

[Brook+] Monte-Carlo

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 * x + y * y <= 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 = rand()%(int)(R); y = 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; }

0 Likes
4 Replies
gaurav_garg
Adept I

I would suggest you to take a look at ATI stream computing user guide.

You can also take a look at http://gpgpu.org/w/index.php/Brook to understand Brook programming model.

0 Likes

Thank's for reply. What I shoud to change in that code?

0 Likes

Your assignment to output stream is correct. But, there are many other problem in your code. Like x and y arguments to kernel should also be passed as streams and not C arrays.

Number of threads that execute the kernel is decided by output stream dimension. In your case, it is 1. i.e. you are running only a single thread on GPU. GPUs are efficient only if you run millions of threads.

I would suggest you to first take a look at documentation and Brook+ tutorial shipped with Brook+ SDK.

0 Likes

OK! Thank's for quick reply

0 Likes