필터 지우기
필터 지우기

FOR vs PARFOR execution time improvement when using a COM object

조회 수: 2 (최근 30일)
Klemen D
Klemen D 2020년 3월 22일
편집: Klemen D 2020년 3월 25일
I have set up a communication between Matlab and COM Object (FEMM software) via Active server interface. Matlab (client) calls FEMM (server) with certain parameter set, FEMM then performs FE analysis and returns result (9 scalar variables).
My task is to do a parametric sweep over 3 variables by calling FEMM in every iteration. I have separately implemented the sweep using (serial) FOR loop and PARFOR loop. I am interested in the improvement in execution time when using PARFOR.
My benchmark example consisted of 6 iterations (i.e. 6 calls to FEMM) on 6 core machine (Intel(R) Core(TM) i7-8700 CPU @ 3.20GHz), 6 workers are added to the pool for PARFOR loop. The execution times of the loops were
  • FOR loop: 66.7 s,
  • PARFOR loop 26.8 s (the time needed to start parellel pool is not included).
As you can see, there is 2.5x improvement in execution time using PARFOR. As I have been using 6 cores and the most time-consuming part of the loop by far is the FE analysis on each worker, I would have expected a greater improvement. I am aware that there can be certain overhead in parallel workers if there is a lot of data transfer and little actual work – I think, however, in my case the opposite is true. Is there something I should do differently or is 2.5x a reasonable impromevent given the circumstances?
Implementation of the PARFOR loop is based on this answer.
c = parallel.pool.Constant(@buildCOMObject, @deleteCOMObject);
parfor idx = 1:N
i = i_vec(idx); j = j_vec(idx); % choose parameters for iteration
openDocument(filename,c.Value) % open file (22kB) in COM object
saveasDocument(filename_temp,c.Value) % saveas file (22kB) in COM object (is this a problem)?
setCOMObject(i,j,c.Value); % set parameters to COM object
useCOMObject(c.Value); % FE analysis takes long time...
res = getCOMObject(c.Value); % get results (9 of these)
res_vec(idx) = res; % save result to vector
delete(path_name_temp) % delete file (22kB) in COM object (is this a problem)?
end
EDIT: In the follow up, I have analysed system performance for two FE problems (benchmark example above is labeled as HARD problem) for various number of workers. As you can see from the figure below, the PARFOR performs better for easier FE tasks.
  댓글 수: 2
Walter Roberson
Walter Roberson 2020년 3월 22일
My expectations would have been that parallel was slower, as COM interfaces all talk to the same server, not one server per connection.
Klemen D
Klemen D 2020년 3월 22일
If I have repeated benchmark with slightly harder problem and – ceteris paribus – I obtain 115.8 s (FOR) and 52 s (PARFOR). This is only 2.2x improvement, so even less than in the first case and with (as I understand) same communication burden between server and COM interfaces. There must be some other bottleneck... CPU use during PARFOR is constant at 70%.

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

답변 (0개)

카테고리

Help CenterFile Exchange에서 Parallel for-Loops (parfor)에 대해 자세히 알아보기

제품


릴리스

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by