How to reduce the time for data collection from workers in parallel computing?

조회 수: 2 (최근 30일)
Ahmad Gad
Ahmad Gad 2017년 11월 19일
댓글: Ahmad Gad 2017년 11월 19일
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
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.
Ahmad Gad
Ahmad Gad 2017년 11월 19일
No, I am not pre-allocating k. My problem usually happens after finishing the loop. I never thought that pre-allocating it will save me time.
I pre-allocated it and this reduced the time to a reasonable amount. After I got the k, I need to use sparse function for it to get the matrix completed. Any Ideas about a faster alternative?
Thanks and best Ahmad

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by