SPMD Error when trying to use the data outside of the SPMD loop
2 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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 Commenti
Risposte (1)
Raymond Norris
il 22 Mag 2021
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 Commenti
Raymond Norris
il 22 Mag 2021
You'll need to define NumberThrownCount outside spmd (as presumably it's already define).
Vedere anche
Categorie
Scopri di più su Parallel for-Loops (parfor) in Help Center e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!