Using arrayfun is giving me an error

5 views (last 30 days)
Ana
Ana on 6 Nov 2015
Commented: Ana on 6 Nov 2015
Hello! I have a question about the use of arrayfun and a gpuArray. My function:
function [ pks, locs ] = peakDetector( gpu_signal, freq)
x = (1:numel(gpu_signal));
x = x.';
%%Get All The Peaks
% fetch indices all infinite peaks
iInf = find(isinf(gpu_signal) & gpu_signal>0);
yTemp = gpu_signal;
yTemp(iInf) = NaN;
% Do more stuff
end
And, in my main script, I try to use this function with a gpuArray and arrayfun:
signal_2 = gpuArray(signalCell{2});
[ pks, locs ] = arrayfun(@peakDetector,signal_2, freq);
However, the following error occurs: Function passed as first input argument contains unsupported or unknown function 'colon'. Error in 'peakDetector'
which corresponds to the first line of the function. If I take it off, then there's another error in the 3rd line of the code. If I run the script without a function and declare a lot of variables as gpuArrays, the code works. But it's still not so fast and I wanted do make it faster. According to MATLAB documentation, the built-in functions are overloaded for gpuArrays, so I don't understand what is wrong here. If arrayfun is impossible to use in this situation, would it be doable to parallelize the code with spmd and try to make it faster?

Answers (1)

Edric Ellis
Edric Ellis on 6 Nov 2015
arrayfun is designed for purely element-wise operations. Your code appears to be attempting to operate on the whole value of gpu_signal. Does it work simply to call
peakDetector(signal_2, freq);
?
  1 Comment
Ana
Ana on 6 Nov 2015
It does. But the thing is, without GPU it takes me almost 15min to run the entire code. With setting a lot of variables as gpuArrauys, takes me 6min. So, I though as a function should be easier, or at least the same time. If I do it like
peakDetector(signal_2, freq);
it takes me 10min to run. Just wanted to see if it was possible to break the code in a faster way. Thank you.

Sign in to comment.

Categories

Find more on Parallel Computing Fundamentals in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!