Info
La pregunta está cerrada. Vuélvala a abrir para editarla o responderla.
Parfor function for numerical simulations
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Hello ppl ,
I am learning parallel computing with matlab . I have several sequence of functions which is being called from the main function for each iteration . So each iteration is dependent upon the previous iteration for results . Now the sub functions defined within the main function has for loops which are independent and i want to apply parfor for this to speed up the calculation.
example
for i=1:iter
%sequence of codes
[U,V,T]=Mac(u,v,T,rho,....)
end
mac.m
% all variables below comes from the previous loop .
for i=2:imax-1
for j=2:jmax-1
Up1(i,j)=U1(i,j)-(delt/delx)*(E1(i+1,j)-E1(i,j))-(delt/dely)*(F1(i,j+1)-F1(i,j));
Up2(i,j)=U2(i,j)-(delt/delx)*(E2(i+1,j)-E2(i,j))-(delt/dely)*(F2(i,j+1)-F2(i,j));
Up3(i,j)=U3(i,j)-(delt/delx)*(E3(i+1,j)-E3(i,j))-(delt/dely)*(F3(i,j+1)-F3(i,j));
Up4(i,j)=U4(i,j)-(delt/delx)*(E4(i+1,j)-E4(i,j))-(delt/dely)*(F4(i,j+1)-F4(i,j));
end
end
I dont know or cant understand in invoking parfor to this kind of code.
I was reading to some of the example files in which they have used to separate the primary and secondary variable (just for calculation) while using matrix like below
matlabpool ('open',2); % Call to open the distributed processing
x = zeros(100,10); % Initialize the main variable
parfor i = 1:100 % Parallel loop
y = zeros(1,10); % Initialize the secondary variable
for j = 1:10 % Inner loop
y(j) = i;
end
y % Display the inner variable (note the random execution about "i" in the command window)
x(i,:) = y; % Get values from loop into the main variable
end
How could i just start writing my code lines in this format. Bcz of terms like E1(i+1,j)-E1(i,j) , how would i just do the columnwise operations for the parfor ? .
0 comentarios
Respuestas (1)
Edric Ellis
el 29 de Jul. de 2013
You might need to extract the columns of E1 etc. before working on them. For example
parfor colIdx = 1:numColumns
E1Column = E1(:, colIdx);
resultColumn = zeros(numRows, 1);
for rowIdx = 2:numRows-1
resultColumn(rowIdx) = E1Column(rowIdx+1) + E1Column(rowIdx);
end
result(:, colIdx) = resultColumn;
end
0 comentarios
La pregunta está cerrada.
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!