for-loop GPU Parallelization

8 views (last 30 days)
John
John on 27 Dec 2011
I was wondering whether there is a way to parallelize a for-loop such that each GPU core runs one in parallel. I have access to the Parallel Computing Toolbox v2011a, and of course any freely available files, if all I have to do is download them into a folder (e.g. GPUmat).
More specifically, I want to drive multiple systems to equilibrium independently, with each system consisting mainly of an array.
As far as I know, there is no way to do such a thing explicitly with the Toolbox? I tried circumventing this by defining a gpu-array "index" [1 2 3 ... N ] and using arrayfun on the array. The problem I ran into was arrayfun won't let me run loops on the GPU. Furthermore, I'm not sure what this exactly does to each GPU core.
I also tried GPUmat's compiler, which won't let me call indices of arrays. It's also not completely clear whether the GPUfor loop is a parallel for-loop.

Answers (1)

Jill Reese
Jill Reese on 27 Dec 2011
R2011a does support loops with arrayfun executing on the GPU. Without knowing more details about the code you'd like to execute on the GPU it's hard to provide suggestions on how to proceed. Could you add a code snippet to your post?
  2 Comments
John
John on 28 Dec 2011
I haven't implemented it to my program yet, but I've been playing around with it.
What I tried was
function y = testfunction(x)
for i=1:x
y=x+i;
end
This works fine for normal arrays but doesn't for gpu arrays.
Jill Reese
Jill Reese on 2 Jul 2012
Are you passing in x as a scalar?

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!