Help with making parfor loop work
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Quy
el 19 de Mzo. de 2024
Comentada: Edric Ellis
el 20 de Mzo. de 2024
Need help making the code below run in parfor loop. The errors are:
"The parfor loop cannot run due to the way symTable is used"
"The parfor loop cannot run due to the way asymTable is used"
freqVec = freqMin:freqStep:freqMax;
fullModes = 1:4;
symTab = ["Frequency" ; "S"+string(fullModes'-1) + " Cp"];
asymTab = ["Frequency" ; "A"+string(fullModes'-1) + " Cp"];
tableTypes = repmat("double",1,fullModes(end)+1);
symTable = table('Size',[length(freqMin:freqStep:freqMax) fullModes(end)+1],'VariableNames', ...
symTab,'VariableTypes',tableTypes);
asymTable = table('Size',[length(freqMin:freqStep:freqMax) fullModes(end)+1],'VariableNames', ...
asymTab,'VariableTypes',tableTypes);
parfor ii = 1:length(freqVec)
currentFreq = freqVec(ii);
symCTR = 1;
asymCTR = 1;
%LOTS OF CODE HERE TO DETERMINE Cp, which is a 2x10 matrix
for modeType = 1:2
if any(CpFin(1,:) ~= 0,2) % store root results into table based on mode.
symTable(ii,1) = {currentFreq};
asymTable(ii,1) = {currentFreq};
for j = 1:size(CpFin,2)
if modeType == 1
if symCTR > width(symTable)-1
continue
elseif CpFin(1,j) == 0
continue
elseif round(CpFin(1,j)) == Cs || round(CpFin(1,j)) == Cl
continue
end
symTable(ii,symCTR+1) = {CpFin(1,j)};
symCTR = symCTR + 1;
else
if asymCTR > width(asymTable)-1
continue
elseif CpFin(1,j) == 0
continue
elseif round(CpFin(1,j)) == Cs || round(CpFin(1,j)) == Cl
continue
end
asymTable(ii,asymCTR+1) = {CpFin(1,j)};
asymCTR = asymCTR + 1;
end
end
end
end
end
0 comentarios
Respuesta aceptada
Walter Roberson
el 19 de Mzo. de 2024
First of all, you are permitted only one assignment into a variable indexed by your parfor loop. Having
symTable(ii,1) = {currentFreq};
and
symTable(ii,symCTR+1) = {CpFin(1,j)};
is not allowed.
What you effectively have to do is assign into a temporary variable, and then assign the temporary variable to symTable(ii,:)
1 comentario
Edric Ellis
el 20 de Mzo. de 2024
This is correct. You will also need to move the computation width(symTable) to before the parfor loop. The same applies to asymTable.
Más respuestas (0)
Ver también
Categorías
Más información sobre Parallel for-Loops (parfor) en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!