Usage of parfor (parallel computing)
情報
この質問は閉じられています。 編集または回答するには再度開いてください。
古いコメントを表示
I have a question regarding parallel computing with MATLAB. Suppose I have the following code:
----
trials = 30;
data = zeros(trials,11,3);
for k=1:trials
count = 1;
for i=0:1:10
b = simulate_network_inhibitory_testing(i/10);
data(k,count,: ) = b;
count = count + 1;
end
end
save('data2301performance.mat', 'data');
---
The called function 'simulate_network_inhibitory_testing' returns a 3x1 Matrix.
I now want to parallelize this script using parfor. However, if I just substitute the first for loop by a parfor loop this does not work, because MATLAB says I am not allowed to use the data matrix in that way.
What is the problem with this and how would a work-around look like?
3 件のコメント
Walter Roberson
2011 年 1 月 23 日
Does simulate_network_inhibitory_testing return a value involving random seeds? If not then there is no need to do repeated trials.
Remove your count loop and replace its value in the loop with i+1
data(k,i+1,:) = b;
You would have better efficiency if you moved the trial number to the last dimension and the 3 outputs of b to the first:
data(:, i+1, trial) = b;
This would allow the array to be split along complete panes.
Stefan Depeweg
2011 年 1 月 23 日
Walter Roberson
2011 年 1 月 23 日
Use a local array to hold all the 11 x 3 results calculated in the loop, and then after the end of the inner loop, write the block in, so that the only index named in data() in the outer loop is k and the other two are : .
回答 (1 件)
Edric Ellis
2011 年 1 月 31 日
Walter is quite right to suggest the local array approach. Just to expand what he described:
trials = 30;
data = zeros(trials,11,3);
parfor k=1:trials
datak = zeros(11,3);
for i=0:1:10
b = simulate_network_inhibitory_testing(i/10);
datak(i+1, :) = b;
end
data(k,:,:) = datak;
end
1 件のコメント
Walter Roberson
2011 年 1 月 31 日
Amazing what one can pick up by reading random cssm answers for products one doesn't even use ;-)
この質問は閉じられています。
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!