【问题标题】:matlab parallel computing : the variable in a parfor is not classifiedmatlab并行计算:parfor中的变量未分类
【发布时间】:2016-10-29 03:52:08
【问题描述】:

全部,

我在 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

在这种情况下,我收到了错误消息...

“使用 pwp_parallel 时出错(第 238 行)错误:无法对 parfor 中的变量 temp 进行分类。请参阅 MATLAB 中的并行 for 循环,“概述”。”

但是,如果我的代码看起来像这样......

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

代码正在运行。
有人可以帮我处理这个错误吗?

【问题讨论】:

    标签: matlab parfor


    【解决方案1】:

    我发帖后自己想出来的,哈哈

    现在的问题是 parfor 中的 if 条件无法识别变量 temp 是什么。但是,if 条件确实可以识别变量 output.t。

    所以,在这种情况下,我只需要将if条件中的变量“temp(xid,yid,37)”替换为“output.t(37)”,那么问题就解决了。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-10-24
      • 2015-05-17
      • 1970-01-01
      • 1970-01-01
      • 2017-03-04
      • 1970-01-01
      相关资源
      最近更新 更多