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

14 views (last 30 days)
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 Comments
Jigar
Jigar on 2 Mar 2023
Hi Jan,
Thank you for your response towards the optimization, and 240 to 325 is changed to 285 to 325.
Walter Roberson
Walter Roberson on 2 Mar 2023
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.

Sign in to comment.

Accepted Answer

Swaraj
Swaraj on 9 Mar 2023
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.

More Answers (0)

Categories

Find more on Graphics Performance in Help Center and File Exchange

Products


Release

R2022b

Community Treasure Hunt

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

Start Hunting!