FOR vs PARFOR execution time improvement when using a COM object

2 次查看(过去 30 天)
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