フィルターのクリア

Are my variables sliced?

14 ビュー (過去 30 日間)
Sam
Sam 2013 年 3 月 20 日
Hello all. I'm trying to parallelize my code, and I'm having a devil of a time trying to understand what a sliced variable looks like. Below, I've included a cleaned-up version of the relevant parts of my code. If I'm not slicing the variables, please let me know what I can do to fix that. I think this might be important because each column of xdata is rather hefty. Thanks in advance.
x = nan(14,6) ;
parfor r = 1:14
x0 = [param_struct.region(r).param1 ...
param_struct.region(r).param2 ...
param_struct.region(r).param3 ...
param_struct.region(r).param4 ...
param_struct.region(r).param5 ...
param_struct.region(r).param6 ...
] ; % x0 is a vector
xdata = [data_struct(r).xdata1 ...
data_struct(r).xdata2 ...
data_struct(r).xdata3 ...
data_struct(r).xdata4 ...
data_struct(r).xdata5 ...
] ; % xdata is a matrix
ydata = data_struct(r).ydata ;
x = lsqcurvefit(fun,x0,xdata,ydata) ;
end

採用された回答

Shashank Prasanna
Shashank Prasanna 2013 年 3 月 21 日
Sam, you've probably already went through this page, but I will paste it here anyway:
The slicing happens is there is first-Level indexing. In this case param_struct is not sliced because the whole param_struct is required to be passed to each worker.
data_struct(r).xdata1 is sliced. Which means under parfor, data_struct is sliced into 14 variables and sent off to workers. In the former case param_struct can't be sliced because it appears to parfor that all of it may be required.
  1 件のコメント
Sam
Sam 2013 年 3 月 21 日
Okay, excellent. Thanks so much!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeParallel for-Loops (parfor) についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by