SPMD Error when trying to use the data outside of the SPMD loop
조회 수: 7 (최근 30일)
이전 댓글 표시
if true
% code
tic;
arraySize = 24;
tArray = [1:arraySize];
spmd
startIdx = (labindex-1)*(arraySize/numlabs) + 1;
endIdx = startIdx + (arraySize/numlabs) - 1;
for index = startIdx:endIdx
for throw_1 = 1:1:6
for throw_2 = 1:1:6
RollTotal = throw_1 + throw_2;
NumbersThrownCount(RollTotal) = NumbersThrownCount(RollTotal) + 1;
Probability = NumbersThrownCount(Throw) / sum(NumbersThrownCount) * 100;
end
end
end
end
toc
Throw = input('For which throw would you like the probability?');
if Throw > 24 fprintf("Sorry but the throw you want the probability for is invalid please try again\n"); Throw = input('For which throw would you like the probability?'); end
fprintf("The probability of throwing a %d is %f %%\n", Throw, Probability);
Error using SPMD (line 6) Error detected on workers 2 3.
Caused by: Error using SPMD (line 6) An UndefinedFunction error was thrown on the workers for 'NumbersThrownCount'. This may be because the file containing 'NumbersThrownCount' is not accessible on the workers. Specify the required files for this parallel pool using the command: addAttachedFiles(pool, ...). See the documentation for parpool for more details. Unrecognized function or variable 'NumbersThrownCount'.
What I am trying to do is get the data from the SPMD loop so that I can then ask the user what the probability is rolling 'x' value on the dice. The error I get is shown below any help with this would be great as I am really stuck with this. Thanks in advance
댓글 수: 0
답변 (1개)
Raymond Norris
2021년 5월 22일
I would suggest reformatting your post so that all your code is formatted well. Code is not correctly indented and some of the code is text [e.g., Throw = input('For which throw would you like the probability?'); ]. This will make it easier to read.
On line 13, you reference NumbersThrownCount on the right hand side of the equation. Is this a function or a variable? Since you also index into it on the left hand side, I'll assume a variable. Given that, where in your code are you initializing NumbersThrownCount? In the end, that's what the error is stating.
댓글 수: 2
Raymond Norris
2021년 5월 22일
You'll need to define NumberThrownCount outside spmd (as presumably it's already define).
참고 항목
카테고리
Help Center 및 File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!