PARFOR loop: The entire array or structure 'H' is a broadcast variable.This might result in unnecessary communication overhead.
Show older comments
clear all
clc
% file_name11 = ('enter DEM filename');
% filename1 = input(file_name11,'s');
DEMdata = importdata ('28_32_94_98_arc.txt',' ',6);
H=DEMdata.data; %BOLD% %%size of H=14400X14400
% [NHrow NHcol] = size(H);
% Resultt = zeros(NHrow,NHcol);
% Resultt=Resultt-9999;
% lat0 = input('minimum latitude');
% lat1 = input ('maximum latitude');
% lon0 = input ('minimum longitude');
% lon1 = input ('maximum longitude');
% H_res_deg = (lat1-lat0)/NHrow;
% res_m = 1000* (111.1949*(H_res_deg)); % resolution in meters = deltax = deltay
% s_cap_m = input('Enter the radius of integration (in meters)'); %in meters (inner radius
% s_cap_m = 8000;
% np = ceil(s_cap_m/res_m);
% if mod(np,2)==0
% aaa=1;
% else
% aaa=0;
% end
% some constant matrices x1, x2, y1, y2
href=0;
parfor i = 1780:12620
i
for j = 1780:12620
%%%%%%%%%H is the broadcast variable
hh = H(i-np:i+np,j-np:j+np); %BOLD%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
h = H(i,j)-hh;
Resultt(i,j) = somefunction(x1,x2,y1,y2,href,h);
end
end
Answers (1)
Walter Roberson
on 14 Sep 2018
This happens when the parfor body needs to access multiple rows and multiple columns of a variable relative to the parfor index.
There are workarounds for simpler cases.
Suppose that the code needed K = H(i-1:i, :) then you could write
H1 = H(1:end-1, :);
H2 = H(2:end,:);
before the loop, and then inside the loop you would
K = [H1(i, :), H2(i, :) ];
Here, H1 and H2 would each only need one row of and so could each be sliced.
As you have a variable number of rows and columns accessed you cannot write your code in terms of individual variables, but you could perhaps work something out with cell array.
(As usual though it is better to slice by multiple rows than multiple columns.)
3 Comments
ropesh goyal
on 14 Sep 2018
Walter Roberson
on 15 Sep 2018
I would tend to think that would have the same problems.
ropesh goyal
on 15 Sep 2018
Categories
Find more on Operating on Diagonal Matrices 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!