Error accessing global variables inside parfor. (addAttachedFiles ??)

조회 수: 1 (최근 30일)
JP
JP 2013년 11월 22일
Dear,
I have a code that defines some global vectors (X, Y, Z) and 3D arrays (U, V, W).
At some point I'm doing the following parfor loop:
parfor plab = 1: N_particles;
[i, j, k] = R2voxel(X(plab),Y(plab), Z(plab), resolution);
[uip, vip, wip] = V2part(X(plab),Y(plab), Z(plab), i,j,k);
if ( U(i+1,j,k) > 0.0 )
Flag_Average_u = Flag_Average_u + 1;
Total_u = Total_u + uip
end
end
where V2part is a simple linear interpolation between two grid points:
function [uip,vip,wip] = V2part(X,Y,Z,x2i,y2j,z2k)
hx=( U(x2i+1,y2j,z2k) - U(x2i,y2j,z2k))/deltax;
uip= U(x2i,y2j,z2k) + hx*(X -( x2i-1)* deltax)
hy=(V(x2i,y2j + 1,z2k) - V(x2i,y2j,z2k))/deltay;
vip=( V(x2i,y2j,z2k) + hy *(Y -(y2j-1) * deltay));
hz=( W(x2i,y2j,z2k+ 1) - W(x2i,y2j,z2k))/deltaz;
wip=( W(x2i,y2j,z2k)+ hz*(Z-(z2k -1)* deltaz));
and then I get the error:
Error using V2part (line 4) An UndefinedFunction error was thrown on the workers for 'U'. This may be because the file containing 'U' is not accessible on the workers. Specify the required files to this MATLAB pool using the matlabpool addAttachedFiles command. See the documentation for matlabpool for more details.
Any ideas ? Why is parfor complaining about accessing an array previously defined as Global ?
many thanks !
p.s I guess there are better ways of writing this in Matlab, but I'm just starting now to migrate some old fortran code I have.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Parallel for-Loops (parfor)에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by