Reputation: 1158
I have some code I made in C++ that takes advantage of multiple threads.
I did away with an array, and can sum up the program as such (running on multiple threads over multiple runs) i.e. a summation of -1/+1 random numbers
runningTotal += ((rng_1.rand_cmwc()%range + 1) <= halfRange ? 1: -1);
rng_1.rand_cmwc() refers to a function of cmwc class, rng_1 is the object.
I've done some reading on OpenCl (http://opencl.codeplex.com/wikipage?title=OpenCL%20Tutorials%20-%201) , I have the library setup, and compiled my own host.
Which leads me to question #1
This class doesn't exist in OpenCL, so I'm thinking I need to create a kernel just to hold this class.
Variables:
runningTotal is a long
range is a const long
halfRange is a const long (i.e. range/2)
My second question is.
Since it's not an array (and most OpenCL tutorials discuss how to have OpenCL assign multiple elements in an array simultaneously).
How do I setup
runningTotal += ((rng_1.rand_cmwc()%range + 1) <= halfRange ? 1: -1);
to run on multiple cores? Do I do a workgroup?
Could someone give an example of how I would do the cl_program clCreateProgramWithSource command referencing multiple kernels?
I'm sure I'm going to have more questions, but I think I'm going to need two kernel's, each running it's own workgroup?, one for my cmwc class, and one for the runningTotal summation.
Then somehow sync all the work-items every so often to a larger total.
Upvotes: 0
Views: 670
Reputation: 1019
First question: I believe that only AMD supports the use of classes in kernels through an extension called Static C++ Kernel language (see http://developer.amd.com/Assets/CPP_kernel_language.pdf)
Second question: To do the summation in parallel you have to use a parallel summation algorithm such as prefix sum (http://en.wikipedia.org/wiki/Prefix_sum) or reduction (http://developer.amd.com/Resources/documentation/articles/Pages/OpenCL-Optimization-Case-Study-Simple-Reductions.aspx). Note that there exists libraries for this.
Hope that helps. Good luck :)
Upvotes: 1