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!

채택된 답변

Edric Ellis
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개)

카테고리

Help CenterFile Exchange에서 GPU Computing in MATLAB에 대해 자세히 알아보기

제품


릴리스

R2016a

Community Treasure Hunt

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

Start Hunting!

Translated by