
MATLAB RESHAPE SERIAL
This code runs a lot faster, especially on the GPU which was crippled by very low utilization in the serial code (we were asking it to do too little work at a time). AntennaDirection = Elevation * AntennaDirection The rules of matrix multiplication let me do this without a loop. Note, however, that there’s no dependency between one rotation and the next. NewAntennaDirection(:,ii) = Elevation * AntennaDirection(:,ii) NewAntennaDirection = gpuArray.zeros(size(AntennaDirection)) % Allocate a new array of directions and loop through to compute them Let’s say I need to rotate all the antennae downwards by 10 degrees, as the following code shows. The simplest approach to vectorization in MATLAB is to take advantage of matrix algebra in your mathematical operations. Masts = gpuArray() ĪntennaDirection = gpuArray(AntennaDirection) Vectorization basicsĬomputational hot spots in code generally appear as loops or repeated segments of code, where the repeated operations are naturally parallel in other words, they don’t depend on each other. % positions into a single 3-column matrix containing all

% Put the map data on the GPU and concatenate the map MastIndex = lon(1,M) % 1 x M array of mast indices

MapIndex = lon(1,N)' % N x 1 array of map indices Pan = [cosd(turnAngle) -sind(turnAngle) Zero % Set up some random rotation matrices, stacked along the 3rd % horizontal vectors representing the direction the antennae are facing.ĪntennaDirection = % Finally, give each antenna a random orientation. Power() = 0 % A small number are out of order Power(1:4:M) = 400 % A few transmitters are more powerful Power = 100 * ones(1, M) % Most transmitters use 100 W of power H = 20 % All masts are 20 meters in heightįrequency = 800e6 % 800 MHz transmitters % Antenna masts - index into map spacing every 20 gridpoints

This technique, known as vectorization, benefits all your code whether or not it uses the GPU.
MATLAB RESHAPE HOW TO
First I explain how to write MATLAB code which is inherently parallelizable. Reshape a 3-by- 4 matrix into a 2-by- 6 matrix.In this post, I will discuss techniques you can use to maximize the performance of your GPU-accelerated MATLAB® code. The quantity prod(siz) must be the same as prod(size(A)). Returns an n-dimensional array with the same elements as A, but reshaped to siz, a vector representing the dimensions of the reshaped array. The value of prod(size(A)) must be evenly divisible by the product of the specified dimensions. The product of the specified dimensions, m*n*p*., must be the same as prod(size(A)).ī = reshape(A.) calculates the length of the dimension represented by the placeholder, such that the product of the dimensions equals prod(size(A)). Returns an n-dimensional array with the same elements as A but reshaped to have the size m-by- n-by- p-by. An error results if A does not have m*n elements.ī = reshape(A,m,n,p.) or B = reshape(A,) Returns the m-by- n matrix B whose elements are taken column-wise from A. Reshape (MATLAB Functions) MATLAB Function Reference
