ParFor - how to rewrite For loop
Ältere Kommentare anzeigen
Is it possible to rewrite the following code to that the main loop (a 1:NumData) use Parfor and allows the main loop to be processed in parallel. The core prpoblem is the need to access the 'a' variable which is state dependent and therefore excludes the use of Parfor.
Suggestions would be appreciated.
row = -1; high = 1;
NumData = 100000;
% start timer
tic
% pre allocate memory
RandData= ones(1:80,1:NumData);
% make random numbers
for a=1:NumData % <-- use ParFor ??
for b=1:80
RandData(a,b) = round(low + (high-low) * rand);
end
end
% end timer
toc
Antworten (1)
Daniel Shub
am 4 Okt. 2011
Have you tried it? It works fine for me
parfor a=1:NumData
for b=1:80
RandData(a,b) = round(low + (high-low) * rand);
end
end
2 Kommentare
adam cox
am 4 Okt. 2011
Walter Roberson
am 4 Okt. 2011
I don't see the state dependency? What you have posted looks like straight-forward use of parfor to me.
Kategorien
Mehr zu Parallel for-Loops (parfor) finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!