i want to run parfor loop.... but there is a problem like slice... help me.....
2 views (last 30 days)
Show older comments
parfor i=1:Num
alpha_i2_1 = alpha(i+2,1);
alpha_i1_1 = alpha(i+1,1);
alpha_i_1 = alpha(i,1);
B(2*i-1:2*i,6*i-5:6*i) = [...
1+0.5*Time*A0_5_1+0.5*Time*A0_6_1*alpha_i2_1, ...
-2+Time^2*A0_1_1+Time^2*A0_2_1*alpha_i1_1,...
1+0.5*Time*A0_6_1*-alpha_i_1-0.5*Time*A0_5_1, ...
0.5*Time*A0_6_1*-alpha_i2_1, ...
Time^2*A0_2_1*-alpha_i1_1, ...
0.5*Time*A0_6_1*alpha_i_1; ...
alpha_i2_1+0.5*Time*A0_7_1+0.5*Time*A0_8_1*alpha_i2_1, ...
-2*alpha_i1_1 + Time^2*A0_7_1+Time^2*A0_8_1*alpha_i1_1, ...
alpha_i_1-0.5*Time*A0_8_1-0.5*Time*A0_7_1, ...
-alpha_i2_1+0.5*Time*A0_8_1*-alpha_i2_1, ...
2*alpha_i1_1+Time^2*A0_4_1*-alpha_i1_1, ...
-alpha_i_1+0.5*Time*A0_8_1*alpha_i_1] ;
end
They indicate that Valid indices for 'B' are restricted in PARFOR loops. and The PARFOR loop cannot run due to the way variable 'B' is used.
please, help me. give me a advice
0 Comments
Answers (1)
Edric Ellis
on 30 Sep 2011
You're trying to write the results of your PARFOR loop into 'B'. The rules for doing this mean that you can only index 'B' with the loop variable 'i', and other constant expressions. For example, the following is valid:
parfor i = 1:10
B(i, 7) = 2 * i;
end
but the following is not:
parfor i = 1:10
B(2 * i:(2 * i + 1)) = i;
end
You need to simplify your expression so that your calculation results in values you can store in this form. Usually it's best in this sort of situation to try and calculate a whole row or column, something like
B = zeros(10, 10);
parfor i = 1:10
B(:, i) = rand(10, 1) * i;
end
and then reshape 'B' after the loop.
0 Comments
See Also
Categories
Find more on Parallel for-Loops (parfor) in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!