PARFOR Transparency violation error

16 visualizzazioni (ultimi 30 giorni)
Why am I getting the transperancy error for the following code?
Error using syms (line 216)
Transparency violation error.
See Parallel Computing Toolbox documentation about Transparency
clc
clear
alpha =4; % Path loss exponent
del = 2/alpha;
R =1;
N = 4;
p_k = [0.15 0.05 0.45 0.35];
epsi = 1;
N_set = 1:N;
lambda_dash = 0.05:0.05:0.5;
spec_eff1 = zeros(length(lambda_dash),N);
parfor vv = 1:length(lambda_dash)
vv
comm_term = lambda_dash(vv)*pi*(epsi+R^alpha).*gamma(1+del)*gamma(1-del);
syms tt
fun_int1 = zeros(1,N);
for k = 1:N
term = 0;
for ii = 1:N
m =max(ii-N+k,0):1:min(k,ii);
p_intf = (factorial(k)./(factorial(m).*factorial(k-m))).*(factorial(N-k)./(factorial(ii-m).*factorial(N-k-ii+m)))./(factorial(N)./(factorial(ii).*factorial(N-ii)));
term =term + (sum(p_k(ii).*p_intf.*((2^(tt)-1).*m./k).*((epsi+R^alpha).*(2^(tt)-1).*(m./k) + epsi).^(del-1)));
end
f = exp(-comm_term.*term);
fun_int1(k) = vpa(int(f,[0 inf]));
end
spec_eff1(vv,:) = fun_int1;
end
spec_eff = sum(p_k.*spec_eff1,2);
semilogy(lambda_dash,spec_eff,'k-')
hold on
grid on

Risposta accettata

Andrea Picciau
Andrea Picciau il 18 Giu 2019
The problem occurs in this line:
syms tt
Although the syms function is very handy for hacking symbolic math on your client machine, it modifies the global state of the workspace in a way that is not suitable for parallel computations (and parfor in particular). For parallel computations, use the sym object constructor and change that line to:
tt = sym('tt');
In general, with parfor it's better to use functions that construct and return objects (like the function sym), which are transparent in most cases.
  3 Commenti
Andrea Picciau
Andrea Picciau il 20 Set 2019
Hi Saddam,
I can't see any usage of syms in your code.
Take a look at your error. It should be something like this:
Error using XXXXX (line NNN)
Transparency violation error.
it should give you a starting point to debug your code. Read this to see how to do it!
felicioharley
felicioharley il 8 Mar 2022
Thanks. This worked for me.

Accedi per commentare.

Più risposte (1)

gonzalo Mier
gonzalo Mier il 17 Giu 2019
Parfor loop don't work in GPU, it just multithread your CPU code, so you have to be careful with the variables you use because all of them can change the values of the variables that are accessed by other threads, so the behavior is not predefined. For that, matlab create this error if more than one thread can access to the same memory space. I recommend to use cells for each variable so you don't have any problems with the threats. Also, defining a symbolic variable inside the parfor is a bad idea for the same reason.
  3 Commenti
gonzalo Mier
gonzalo Mier il 20 Giu 2019
thank you, that was really helpful :)
Andrea Picciau
Andrea Picciau il 20 Giu 2019
You're welcome!

Accedi per commentare.

Categorie

Scopri di più su Loops and Conditional Statements in Help Center e File Exchange

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by