How to resolve "Transparency violation error" for parallel programming?

I am trying to use parallel programming for the following code, but I am unable to resolve the error which I am facing. Any hint/solution is highely appreciated.
%Data Import and elimination of bad taps from contour plot---------1
tic
index_file_name = linspace(1800,3600,37);
angle = linspace(180,360,37);
data2(:,667:end)=[];
parfor ii = 1:37
wind_angle = angle(ii);
Name = ['ADW100o100D040a',num2str(index_file_name(ii)),'.hdf']
data = hdfread(Name, 'Tap_Coordinates_3D');
data2 = double(transpose(hdfread(Name, 'Time_Series')));
index = find(data(2,:)==5);
tap5 = [data(:,index);data2(:,index)];
sort5 = sortrows(tap5',[5,4,3])';
clear index
index = find(data(2,:)==6);
tap6 = [data(:,index);data2(:,index)];
sort6 = sortrows(tap6',[5,4,3])';
% Single Matrix of coordinates and Timeseries
if wind_angle<=195
Timeseries = [sort5 sort6(:, 1:105) sort6(:, 107:end)];
elseif wind_angle>=205 && wind_angle<=280
Timeseries = [sort5(:, 3:end) sort6(:, 1:105) sort6(:, 107:end)];
elseif wind_angle>=240 && wind_angle<=325
Timeseries = [sort5(:, 3:end) sort6];
else
Timeseries = [sort5 sort6];
end
% Timeseries = [sort5 sort6];
x = Timeseries(4,:);
y = Timeseries(3,:);
%Voronoi and Pressure Contour--------------------2
pressure = mean(Timeseries(6:end, :))*0.001/0.657^2;
figure;
[xx, yy] = meshgrid(linspace(min(x), max(x)), linspace(min(y), max(y)));
pressure = griddata(x, y, pressure, xx, yy, 'linear');
contourf(xx, yy, pressure,10,'edgecolor', 'none')
shading interp
hold on
scatter(x, y, 'R','.')
plot ([0 125], [40 40], 'black', 'LineWidth', 0.25)
axis([0 125 0 80])
set(gca, 'Ydir', 'reverse', 'FontName', 'Times New Roman')
ylabel('Building width (ft)', 'FontName', 'Times New Roman', 'FontWeight', 'bold')
xlabel('Building length (ft)', 'FontName', 'Times New Roman', 'FontWeight', 'bold')
title(sprintf('Mean pressure contour at Roof - %d^{o} (kN/ft^2)', angle(ii)), 'fontsize', 12)
colorbar
pbaspect([1.5625 1 1])
hold off
end
toc
The output I am receiving is...
Transparency violation error.
See Workspace Transparency in MATLAB Statements.

댓글 수: 3

Just a note not concerning the problem:
index = find(data(2,:)==5);
tap5 = [data(:,index);data2(:,index)];
clear index
% Faster with logical indexing:
index = (data(2,:)==5); % No FIND
tap5 = [data(:,index); data2(:,index)];
% clear index % This is a waste of time here!
This looks strange:
elseif wind_angle>=205 && wind_angle<=280
...
elseif wind_angle>=240 && wind_angle<=325
For wind_anle == 240 to 280 there are two options?!
Hi Jan,
Thank you for your response towards the optimization, and 240 to 325 is changed to 285 to 325.
Note that graphics done inside parfor will not be displayed. You can do things such as capture the figure to image file, and I think you might be able to copy graphics objects back to the client.

댓글을 달려면 로그인하십시오.

 채택된 답변

Swaraj
Swaraj 2023년 3월 9일

0 개 추천

The error message you're getting implies that your code is violating the transparency rule. The “parfor” loop in MATLAB can do this, which can result in multiple workers accessing and changing the same variable at once.
Use the “spmd” block in place of “parfor” to correct this. “SPMD” enables parallel loop execution while guaranteeing that transparency is maintained.
See the below documentation for details.
The below documentation might also be helpful.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Matrix Indexing에 대해 자세히 알아보기

제품

릴리스

R2022b

질문:

2023년 3월 2일

댓글:

2023년 3월 9일

Community Treasure Hunt

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

Start Hunting!

Translated by