MATLAB PARALLEL COMPUTING TOOLBOX - S User's Guide Page 350

  • Download
  • Add to my manuals
  • Print
  • Page
    / 656
  • Table of contents
  • TROUBLESHOOTING
  • BOOKMARKS
  • Rated. / 5. Based on customer reviews
Page view 349
11 Functions — Alphabetical List
11-6
R2 = rand(2,1,4,3,'gpuArray');
R3 = rand(1,5,4,3,'gpuArray');
R = arrayfun(@(x,y,z)(x+y.*z),R1,R2,R3);
size(R)
2 5 4 3
R1 = rand(2,2,0,4,'gpuArray');
R2 = rand(2,1,1,4,'gpuArray');
R = arrayfun(@plus,R1,R2);
size(R)
2 2 0 4
• Because the operations supported by arrayfun are strictly element-wise, and each
element’s computation is performed independently of the others, certain restrictions
are imposed:
• Input and output arrays cannot change shape or size.
• Functions like rand do not support size specifications. Arrays of random numbers
have independent streams for each element.
For more limitations and details, see “Tips and Restrictions” on page 9-17.
Examples
If you define a MATLAB function as follows:
function [o1,o2] = aGpuFunction(a,b,c)
o1 = a + b;
o2 = o1 .* c + 2;
You can evaluate this on the GPU.
s1 = gpuArray(rand(400));
s2 = gpuArray(rand(400));
s3 = gpuArray(rand(400));
[o1,o2] = arrayfun(@aGpuFunction,s1,s2,s3);
whos
Name Size Bytes Class
o1 400x400 108 gpuArray
Page view 349
1 2 ... 345 346 347 348 349 350 351 352 353 354 355 ... 655 656

Comments to this Manuals

No comments