Indexing Arrays for Loops in a gpuArray/arrayfun-called Function
1 次查看(过去 30 天)
显示 更早的评论
I am using MATLAB R2016a, and I'm trying to use GPUArray to make some data processing take less than the two weeks it's taken me using "parpool"... but I've been having issues with that.
Specifically, I was under the impression that indexing is supported with my version of Matlab and the Parallel Computing Toolbox (ver. 6.8). However, I keep getting the following error:
Error using gpuArray/arrayfun
Indexing is not supported.
For more information see Tips and Restrictions.
Error in 'iterateFunc' (line: 6)
Below is my code:
cond=a 60,000-element boolean column vector;
A=gpuArray(an 60,000-by-endID matrix full of NaN's);
B=gpuArray(another 60,000-by-endID matrix full of NaN's);
for time=2:endID
valid=size(A,1);
[tint_new,dint_new]=arrayfun(@iterateFunc,timerange,A,B,valid);
tint_soFar(cond,time-1)=tint_new;
dint_soFar(cond,time-1)=dint_new;
end
...where...
function [tint_new,dint_new]=iterateFunc(timerange,A,B,valid)
tint_result=nan(valid,1);
dint_result=tint_result;
for pos=1:valid
[tint,dint,~,~]=someFunction(timerange,A(pos,:),timerange,B(pos,:),1);
tint_new(pos,1)=tint(1);
dint_new(pos,1)=dint(1);
end
end
Note that "someFunction" is the pseudonym I gave for a custom-written function which only works using 1-D vectors. I would ideally find a way to make it work with higher-dimension arrays, but that's another issue.
Given this, what could I do to return tint_new and dint_new as 60,000-by-endID matrices, some of which have non-NaN values?
Thank you!
0 个评论
采纳的回答
Edric Ellis
2018-6-1
gpuArray does support indexing, but only limited forms are allowed within the context of arrayfun. The limitations for the GPU version of arrayfun are described in the doc.
In your case, you cannot index into A or B within iterateFunc because those are inputs to the function, rather than variables in the parent workspace.
However, in this case, arrayfun is probably not being applied at the right level. The way arrayfun is designed to work is that scalar elements of the inputs are passed to the function. So, inside iterateFunc, A and B will be scalars.
So, I suspect you need to structure your code so that either you can operate in a completely element-wise manner on A and B - and then use arrayfun, or else you fully vectorise your code so that the whole of A and B can be passed in.
0 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 GPU Computing in MATLAB 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!