Hi Gün Süer,
As I understand, you would like to improve the performance of the code by using parfor. As suggested by the error, parfor is unable to work with variables that change size inside the parallel region. Hence, pre-allocating xsol, ysol and zsol should sort the issue. In general, pre-allocating is a great idea to achieve performance and especially useful in parallelization. I was unable to test the original code as the definitions for isPosDef and Matrix were missing. However, the following example should work.
K=7; % (K+1)x(K+1) matrix
g = 1; % g(x^2 + y^2)^2 coupling
N = 50; % Lattice site number
xrange = [0,2]; % E range
yrange = [0,1]; % <r^2> range
zrange = [0,1]; % l range
xsol = zeros(N, N, N);
ysol = zeros(N, N, N);
zsol = zeros(N, N, N);
indexPD = zeros(N, N, N, 'logical');
parfor i=1:N
for j=1:N
for k=1:N
a = xrange(1)+(xrange(2)-xrange(1))*i/N;
b = yrange(1)+(yrange(2)-yrange(1))*j/N;
c = zrange(1)+(zrange(2)-zrange(1))*k/N;
if isPosDef(Matrix(K,a,b,c,g))==1
xsol(k, j, i) = a;
ysol(k, j, i) = b;
zsol(k, j, i) = c;
indexPD(k, j, i) = 1;
end
end
end
end
xsol = xsol(indexPD).';
ysol = ysol(indexPD).';
zsol = zsol(indexPD).';
