matlab并行计算:parfor中的变量未分类
matlab parallel computing : the variable in a parfor is not classified
全部,
我在 matlab 上的 parfor 运行 遇到了一个非常有趣的情况,下面是我的问题。
fid = 'test.nc';
temp = ncread(fid,'temp');
[s1,s2,s3] = size(temp);
for m = 1 : 100
parfor xid = 1 : s1
for yid = 1 : s2
output = struct;
output.t = squeeze(temp(xid,yid,:));
if ~isnan(temp(xid,yid,37))
output.t(:) = 1;
else
output.t(:) = nan;
end
temp(xid,yid,:) = output.t;
end
end
end
在这种情况下,我收到了错误消息...
"Error using pwp_parallel (line 238) Error: The variable temp in a parfor cannot be classified.See Parallel for Loops in MATLAB, "概览"。"
但是,如果我的代码看起来像这样...
fid = 'test.nc';
temp = ncread(fid,'temp');
[s1,s2,s3] = size(temp);
for m = 1 : 100
parfor xid = 1 : s1
for yid = 1 : s2
output = struct;
output.t = squeeze(temp(xid,yid,:));
output.t(:) = 1;
temp(xid,yid,:) = output.t;
end
end
end
密码是运行ning.
有人可以帮我处理这个错误吗?
我贴出来后自己想出来了哈哈
现在的问题是 parfor 中的 if 条件无法识别变量 temp 是什么。但是,if 条件确实识别变量 output.t.
所以,在这种情况下,我只需要将if条件中的变量"temp(xid,yid,37)"替换为"output.t(37)",问题就解决了。
全部,
我在 matlab 上的 parfor 运行 遇到了一个非常有趣的情况,下面是我的问题。
fid = 'test.nc';
temp = ncread(fid,'temp');
[s1,s2,s3] = size(temp);
for m = 1 : 100
parfor xid = 1 : s1
for yid = 1 : s2
output = struct;
output.t = squeeze(temp(xid,yid,:));
if ~isnan(temp(xid,yid,37))
output.t(:) = 1;
else
output.t(:) = nan;
end
temp(xid,yid,:) = output.t;
end
end
end
在这种情况下,我收到了错误消息...
"Error using pwp_parallel (line 238) Error: The variable temp in a parfor cannot be classified.See Parallel for Loops in MATLAB, "概览"。"
但是,如果我的代码看起来像这样...
fid = 'test.nc';
temp = ncread(fid,'temp');
[s1,s2,s3] = size(temp);
for m = 1 : 100
parfor xid = 1 : s1
for yid = 1 : s2
output = struct;
output.t = squeeze(temp(xid,yid,:));
output.t(:) = 1;
temp(xid,yid,:) = output.t;
end
end
end
密码是运行ning.
有人可以帮我处理这个错误吗?
我贴出来后自己想出来了哈哈
现在的问题是 parfor 中的 if 条件无法识别变量 temp 是什么。但是,if 条件确实识别变量 output.t.
所以,在这种情况下,我只需要将if条件中的变量"temp(xid,yid,37)"替换为"output.t(37)",问题就解决了。