How to reduce the time for data collection from workers in parallel computing?
1 次查看(过去 30 天)
显示 更早的评论
Hello everyone. I am having a parallel for loop 'parfor' that iterates for N times. In each iteration, a new vector with size (M x 1) is created and accumulated to a matrix, resulting in a M x N matrix (very big matrix) after finishing the loop. The parfor works efficiently and performs the job without problems, but it takes very long time to collect the data back from the workers. For example, if the total consumed time is 10 minutes, I can say that parfor takes about 1 minute, and remaining 9 are consumed in the data collection. How to reduce this time efficiently?
parfor i=1:N
stuff ...
k(i,:) = b % b is a temporary vector (M x 1) inside the parfor loop
end
2 个评论
Walter Roberson
2017-11-19
Are you pre-allocating k?
parfor deliberately runs loops in reverse order to attempt to cut down the pre-allocation costs, but it wouldn't hurt to pre-allocate to be sure.
回答(0 个)
另请参阅
类别
在 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!